RSxxx Interface
ADwin
36
ADwin-Gold II
, Manual February 2013
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