CRBasic Example 5: Switched relay mode example
Public
Sensor_1_Out As String * 50 =
"Get Awpag Data "
Public
Sensor_2_Out As String * 50 =
"Get Temp Data "
Public
counter
BeginProg
SerialOpen
(32,9600,0,0,50)
SerialOpen
(33,9600,0,0,50)
Scan
(1000,mSec,0,0)
SerialOut
(32,Sensor counter,
""
,0,0)
' Send query for data
SerialOut
(33,Sensor counter,
""
,0,0)
SerialIn
(Sensor_1_In,32,10,0,50)
' receive data back
SerialIn
(Sensor_2_In,33,10,0,50)
' Below If Statement just cycles the different relays to test and do a fun LED
display
' Send 2 digit hex value through SDMGeneric
' Left Digit controls V+, Right Digit controls 12V
' Sending a 1 turns LED/Relay On, Sending a 2 Turns LED/Relay off, Sending a 0
means not to change LED/Relay value
If
counter
=
1
Then
hexVar0
= &
H22
'Sensor1: 12V OFF, Sensor1: V+ OFF
hexVar1
= &
H22
'Sensor2: 12V OFF, Sensor2: V+ OFF
SDMGeneric
(dest, SDM_addr0, cmd_byte, num_vals_out, hexVar0, num_vals_in,
bytes_per_value, big_endian, delay_byte)
SDMGeneric
(dest, SDM_addr1, cmd_byte, num_vals_out, hexVar1, num_vals_in,
bytes_per_value, big_endian, delay_byte)
ElseIf
counter
=
2 Then
hexVar0
= &
H01
'Sensor1: 12V ON
SDMGeneric
(dest, SDM_addr0, cmd_byte, num_vals_out, hexVar0, num_vals_in,
bytes_per_value, big_endian, delay_byte)
ElseIf
counter
=
3
Then
hexVar0
= &
H10
'Sensor1: V+ ON
SDMGeneric
(dest, SDM_addr0, cmd_byte, num_vals_out, hexVar0, num_vals_in,
bytes_per_value, big_endian, delay_byte)
ElseIf
counter
=
4
Then
hexVar1
= &
H01
'Sensor2: 12V ON
SDMGeneric
(dest, SDM_addr1, cmd_byte, num_vals_out, hexVar1, num_vals_in,
bytes_per_value, big_endian, delay_byte)
ElseIf
counter
=
5
Then
hexVar1
= &
H10
'Sensor2: V+ ON
SDMGeneric
(dest, SDM_addr1, cmd_byte, num_vals_out, hexVar1, num_vals_in,
bytes_per_value, big_endian, delay_byte)
ElseIf
counter
=
6
Then
hexVar1
= &
H20
'Sensor2: V+ OFF
SDM-SIO2R Serial Input/Output Module with Switched Sensor Power
49