Example using switched relay power

Switched relay mode example

'CR1000X Program showing how to use SDM-SIO2R. This program will transmit/receive serial data and

'This program will also control the switched relay power using SDM-Generic

 

SequentialMode'Sequential Mode allows for the program to have SDM-Generic command within Conditional Statements

 

Public dest As Long' variable holding incoming bytes from SDM device

Const SDM_addr0 = 0 ' sdm address of device communicating with. valid addresses 0-14

Const SDM_addr1 = 1 ' sdm address of device communicating with. valid addresses 0-14

Const cmd_byte = 7 ' setup byte sent to SDM device

Public hexVar0 As Long' variable holding values to be sent to SDM device

Public hexVar1 As Long' variable holding values to be sent to SDM device

Const num_vals_out = 1 ' number of values to be sent to SDM device. number of bytes out - none sent

Const source As String =""' variable holding values to be sent to SDM device

Const num_vals_in = 0 ' number of values expected to be received back from SDM device.

Const bytes_per_value = 1 ' number of bytes for each value sent to or received from SDM device. one bytes returned

Const big_endian = 1 ' order of bytes sent or received, 0 = little endian, 1 = big endian

Const delay_byte = -0 ' delay in microseconds between sending bytes (negative means delay for incoming bytes from SDM device)

 

Public Sensor_1_In As String * 50

Public Sensor_2_In As String * 50

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_1_Out + counter,"",0,0) ' Send query for data

SerialOut (33,Sensor_2_Out + 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

SDMGeneric(dest, SDM_addr1, cmd_byte, num_vals_out, hexVar1, num_vals_in, bytes_per_value, big_endian, delay_byte)

ElseIf counter = 7 Then

hexVar1 =&H02 'Sensor2: 12V OFF

SDMGeneric(dest, SDM_addr1, cmd_byte, num_vals_out, hexVar1, num_vals_in, bytes_per_value, big_endian, delay_byte)

ElseIf counter = 8 Then

hexVar0 =&H20 'Sensor1: V+ OFF

SDMGeneric(dest, SDM_addr0, cmd_byte, num_vals_out, hexVar0, num_vals_in, bytes_per_value, big_endian, delay_byte)

ElseIf counter = 9 Then

hexVar0 =&H02 'Sensor1: 12V OFF

SDMGeneric(dest, SDM_addr0, cmd_byte, num_vals_out, hexVar0, num_vals_in, bytes_per_value, big_endian, delay_byte)

ElseIf counter = 10 Then

hexVar0 =&H11 'Sensor1: 12V ON, Sensor1: V+ ON

hexVar1 =&H11 'Sensor2: 12V ON, Sensor2: V+ ON

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)

counter = 0

EndIf

counter += 1

NextScan

EndProg