Programming examples, 5 programming examples – ADLINK CM1-86DX2 User Manual

Page 63

Advertising
background image

Using the Module

57

CM1-86DX2

4.5 Programming Examples

The following programming examples are provided based on a Linux operating system. If other
operating systems are used, some header files could be unnecessary or they may have different
names.

The "iopl()" function is a Linux specific function and defined inside the iopl.h header file. In Win-
dows XP, a tool called "porttalk" can be used instead.

Pay attention to the "outb" order in the following examples:

Linux:

'outb(value, address)'

DOS, Windows:

'outb(address, value)'

The code is meant to be compiled using gcc under Linux.

GPIOs on GPIO Port 1 (X17)

#include

<

sys

/

io

.

h

>

#include

<

stdio

.

h

>

#include

<

stlib

.

h

>

#include

<

unistd

.

h

>

//GPIO registers:
#define GPIO1X_DAT0x99

//default address for gpio port1 data

#define GPIO1X_DIR0x79

//default address for gpio port1 direction

int

main

()

{

if(

iopl

(

3

) !=

0

)

{
printf

(

"IOPL error

\

n"

);

return

1

;

}

outb

(

0xff

,

GPIO1X_DIR

);

//set all pins of gpio port1 to output (set 0x00 for all input)

outb

(

0x55

,

GPIO1X_DAT

);

//write out 0x55 to gpio port1

RS-232 / RS-485 switching

#!/bin/bash

#set speed pins to 0
./dx2_gp

0

d

0x00

./dx2_gp

0

o

0x00

#######################################################
# GP36 (COM1) and GP37 (COM2)
#######################################################

Please note that some of the following lines of code appear in smaller font sizes to make
them fit in single lines.

Please note that this source code example is provided for a system running with Linux.
For other operating systems, it may be necessary to adapt the source code regarding
include files or headers and the syntax of I/O out commands because Linux is using
outb(value, address) instead of outb(address, value).

Advertising