ADwin-Gold
USB / ENET, manual version 3.8, October 2005
41
CAN add-on
ADwin
Example programs
RS232
The following program illustrates the initialization of the serial RS232 interface
in the
INIT
:
section and the cyclic reading and writing of data in the
EVENT
:
.
section. The process is timer-controlled:
REM The program initializes the serial interface
REM in the Init: section.
REM In the Event: section data is exchanged between
REM the interfaces 1 & 2 of the RS module.
REM The interfaces are tested with this program.
REM For this connect the interfaces with each other
REM befor starting the program.
#INCLUDE
adwpext.inc
DIM
DATA_1
[1000]
AS
LONG
'Transmitted data
DIM
DATA_2
[1000]
AS
LONG
'Received data
DIM
lauf
AS
LONG
'Control variable
INIT
:
FOR
run
= 1
TO
1000
'Initialization of the transmit-
'ted data
DATA_1
[
run
] =
run
AND
0FFh
NEXT
run
REM Initialization of the interfaces:
REM 9600 Baud, not parity bit, 8 data bits,
REM 2 stop bits, RS232 witout handshake
RS_INIT
(1 9600.0.8,1,0)
RS_INIT
(2,9600,0,8,1,0)
PAR_1
= 1
PAR_4
= 1
EVENT
:
REM Read and write a data set
IF
(
PAR_1
<= 1000)
THEN
'Send data
PAR_2
=
WRITE_FIFO
(1,
DATA_1
[
PAR_1
])
IF
(
PAR_2
= 0)
THEN
INC
PAR_1
ENDIF
PAR_3
=
READ_FIFO
(2)
'Read data
IF
(
PAR_3
<> -1)
THEN
DATA_2
[
PAR_4
] =
PAR_3
INC
PAR_4
ENDIF
IF
(
PAR_4
> 1000)
THEN
END
'All data are transmitted