Sensoray 421 User Manual
Page 25

Sensoray Model 421 Instruction Manual
Page 23
Relay Interface Procedures
FUNCTION ReadRelay% (bankAdrs%, chan%)
‘****************************************************************************
‘ Read relay channel input state.
‘
‘ Imports:
‘
chan% = relay channel in range 0:23.
‘
bankAdrs% = address of relay group (RELAY0 or RELAY2).
‘
‘ Exports:
‘
ReadRelay% = relay channel input state (TRUE or FALSE).
‘****************************************************************************
adrs% = bankAdrs% + chan% \ 8
‘ Compute relay channel port address
bitMask% = 2 ^ (chan% AND 7)
‘ Compute relay channel bit mask
readRelay% = ((INP(adrs%) AND bitMask%) <> 0)
‘ Read relay input state
END FUNCTION
SUB writeRelay (bankAdrs%, chan%, state%)
‘****************************************************************************
‘ Program relay output.
‘
‘ Imports:
‘
chan% = relay channel in range 0:23.
‘
bankAdrs% = address of relay group (RELAY0 or RELAY2).
‘
state% (boolean): TRUE = relay on, FALSE = relay off.
‘****************************************************************************
Index% = chan% \ 8
‘ Compute relay%() index and port address
bitMask% = 2 ^ (chan% AND 7)
‘ Compute relay channel bit set mask
invMask% = bitMask% XOR 255
‘ Compute relay channel bit reset mask
‘ Update relay port output image
relay%(Index%) = (relay%(Index%) AND invMask%) OR (state% AND bitMask%)
OUT bankAdrs% + Index%, relay%(Index%)‘ Write new state to relay channel output register
END SUB