Model Railroad System  2.2.1
Classes | Public Member Functions | Private Member Functions | Friends | List of all members
azatrax::SR4 Class Reference

SR4 I/O Class. More...

#include <sr4.h>

Inheritance diagram for azatrax::SR4:
azatrax::Azatrax

Classes

union  status1_union
 Status byte 1 union type (Outputs) More...
 
union  status2_union
 Status byte 2 union type (Input sense) More...
 
union  status3_union
 Status byte 3 union type (Input Control Status) More...
 

Public Member Functions

 ~SR4 ()
 
ErrorCode BlinkRelays (bool Q1, bool Q2, bool Q3, bool Q4, uint8_t speed)
 Blink relay contacts. More...
 
ErrorCode RelaysOff (bool Q1, bool Q2, bool Q3, bool Q4)
 Set output relay contacts off. More...
 
ErrorCode RelaysOn (bool Q1, bool Q2, bool Q3, bool Q4)
 Set output relay contacts on. More...
 
ErrorCode PulseRelays (bool Q1, bool Q2, bool Q3, bool Q4, uint8_t duration)
 Pulse output relay contacts. More...
 
ErrorCode OutputRelayInputControl (bool I1, bool I2, bool I3, bool I4)
 Enable/Disable descrete input lines from affecting outputs. More...
 
bool Sense_1_Latch () const
 Sense 1, return true if input line 1 was activated since last get status. More...
 
bool Sense_2_Latch () const
 Sense 2, return true if input line 2 was activated since last get status. More...
 
bool Sense_3_Latch () const
 Sense 3, return true if input line 3 was activated since last get status. More...
 
bool Sense_4_Latch () const
 Sense 4, return true if input line 4 was activated since last get status. More...
 
bool Q1_State () const
 Q1 state, return true if Q1 is closed. More...
 
bool Q2_State () const
 Q2 state, return true if Q2 is closed. More...
 
bool Q3_State () const
 Q3 state, return true if Q3 is closed. More...
 
bool Q4_State () const
 Q4 state, return true if Q4 is closed. More...
 
bool Input_1_Enabled () const
 Input 1 enabled? Return true if I1 can affect outputs. More...
 
bool Input_2_Enabled () const
 Input 2 enabled? Return true if I2 can affect outputs. More...
 
bool Input_3_Enabled () const
 Input 3 enabled? Return true if I3 can affect outputs. More...
 
bool Input_4_Enabled () const
 Input 4 enabled? Return true if I4 can affect outputs. More...
 
bool Sense_1_Live () const
 Sense 1, return true if input line 1 is now activated. More...
 
bool Sense_2_Live () const
 Sense 2, return true if input line 2 is now activated. More...
 
bool Sense_3_Live () const
 Sense 3, return true if input line 3 is now activated. More...
 
bool Sense_4_Live () const
 Sense 4, return true if input line 4 is now activated. More...
 
- Public Member Functions inherited from azatrax::Azatrax
 ~Azatrax ()
 Base destructor. More...
 
ErrorCode RestoreLEDFunction () const
 Restore LED function. More...
 
ErrorCode Identify_1 () const
 Identify 1. More...
 
ErrorCode GetStateData ()
 Get State Data. More...
 
uint8_t PacketCount () const
 Packet count. More...
 
const char * SerialNumber () const
 Serial Number. More...
 
const char * MyProduct () const
 My product name. More...
 
unsigned short int MyProductId () const
 My product code. More...
 

Private Member Functions

 SR4 (const char *serialnumber, char **outmessage=NULL)
 Base constructor. More...
 

Friends

class Azatrax
 

Additional Inherited Members

- Public Types inherited from azatrax::Azatrax
enum  commands {
  cmd_SetChan1 =0x31, cmd_SetChan2 =0x32, cmd_ClearExternallyChanged =0x34, cmd_DisableExternal =0x37,
  cmd_EnableExternal =0x38, cmd_Q1posQ2neg =0x39, cmd_Q1negQ2pos =0x3A, cmd_Q1Q2open =0x3F,
  cmd_Q3posQ4neg =0x49, cmd_Q3negQ4pos =0x4A, cmd_Q3Q4open =0x4F, cmd_RestoreLEDFunction =0x50,
  cmd_Identify_1 =0x51, cmd_Identify_2 =0x52, cmd_Identify_1_2 =0x53, cmd_ResetStopwatch =0x54,
  cmd_GetStateData =0x57, cmd_OutputRelayBlink =0x61, cmd_OutputRelayOff =0x67, cmd_OutputRelayOn =0x6B,
  cmd_OutputRelayPulse =0x6D, cmd_OutputRelayInputControl =0x6E
}
 Command codes. More...
 
enum  DeviceConnectionList { _InitSize = 10, _GrowSize = 10 }
 Device connection list constants. More...
 
enum  { idAzatraxVendor = 0x265F, idMRDProduct = 0xfcb2, idSL2Product = 0xfca1, idSR4Product = 0xfca2 }
 Azatrax vendor and product codes. More...
 
- Static Public Member Functions inherited from azatrax::Azatrax
static int NumberOfOpenDevices ()
 Open device count. More...
 
static char ** AllConnectedDevices ()
 List serial numbers of all connected devices. More...
 
static AzatraxOpenDevice (const char *serialnumber, unsigned short int idProduct=0, char **outmessage=NULL)
 Open an Azatrax device by serial number. More...
 
static unsigned short int ProductIdCode (const char *productName)
 Product id code. More...
 
- Protected Member Functions inherited from azatrax::Azatrax
 Azatrax (const char *serialnumber, unsigned short int idProduct, char **outmessage=NULL)
 Base constructor. More...
 
ErrorCode sendByte (uint8_t commandByte) const
 Send a command byte. More...
 
ErrorCode send2Bytes (uint8_t commandByte, uint8_t byte2) const
 Send a command byte with 1 data byte. More...
 
ErrorCode send3Bytes (uint8_t commandByte, uint8_t byte2, uint8_t byte3) const
 Send a command bytewith 2 data bytes. More...
 
- Static Protected Member Functions inherited from azatrax::Azatrax
static bool IsThisTheAzatraxWeAreLookingFor (libusb_device *dev, const char *serialnumber, unsigned short int idProduct)
 Is this the device we want? More...
 
static unsigned short int GetProductId (libusb_device *dev, const char *serialnumber, unsigned short int idProductMatch=0)
 Return the matching product id for this device and serial number. More...
 
- Protected Attributes inherited from azatrax::Azatrax
struct libusb_device_handle * handle
 USB Device Handle. More...
 
char mySerialNumber [10]
 Serial number buffer. More...
 
unsigned short int myProductId
 Product id. More...
 
struct azatrax::Azatrax::StateDataPacket stateDataPacket
 
- Static Protected Attributes inherited from azatrax::Azatrax
static int deviceOpenCount
 Device open count. More...
 

Detailed Description

SR4 I/O Class.

SR4 interface class.

This class implements the interface logic for a SR4-U device.

The constructor opens a connection to a SR4-U device, given its serial number. Each SR4-U device has a unique, factory defined serial number, which is printed on a sticker attached to the module. This serial number is much like the MAC address of an Ethernet interface. The destructor closes the connection to the device and frees any resources allocated.

The class provides methods to send commands to the device, read back its state and interrogate the state read back. This way each class instance encapsulates each device instance.

Author
Robert Heller <heller@deepsoft.com>

Constructor & Destructor Documentation

◆ SR4()

azatrax::SR4::SR4 ( const char *  serialnumber,
char **  outmessage = NULL 
)
inlineprivate

Base constructor.

Parameters
serialnumberThe serial number of the device to open.
outmessageTo hold an error message, if any.

◆ ~SR4()

azatrax::SR4::~SR4 ( )
inline

Member Function Documentation

◆ BlinkRelays()

ErrorCode azatrax::SR4::BlinkRelays ( bool  Q1,
bool  Q2,
bool  Q3,
bool  Q4,
uint8_t  speed 
)
inline

Blink relay contacts.

Sets output relay contacts to blinking state.

Parameters
Q1Blink relay Q1.
Q2Blink relay Q2.
Q3Blink relay Q3.
Q4Blink relay Q4.
speedBlink speed: 0 is 4hz, 1 is 2hz, 2 is 1hz, and 3 is .5hz.

References azatrax::Azatrax::cmd_OutputRelayBlink, and azatrax::Azatrax::send3Bytes().

◆ Input_1_Enabled()

bool azatrax::SR4::Input_1_Enabled ( ) const
inline

◆ Input_2_Enabled()

bool azatrax::SR4::Input_2_Enabled ( ) const
inline

◆ Input_3_Enabled()

bool azatrax::SR4::Input_3_Enabled ( ) const
inline

◆ Input_4_Enabled()

bool azatrax::SR4::Input_4_Enabled ( ) const
inline

◆ OutputRelayInputControl()

ErrorCode azatrax::SR4::OutputRelayInputControl ( bool  I1,
bool  I2,
bool  I3,
bool  I4 
)
inline

Enable/Disable descrete input lines from affecting outputs.

When enabled, I1 & I2 affect Q1 & Q2 (switch 1), I3 & I4 affect Q3 & Q4 (switch 2).

Parameters
I1Enable/Disable I1.
I2Enable/Disable I2.
I3Enable/Disable I3.
I4Enable/Disable I4.

References azatrax::Azatrax::cmd_OutputRelayInputControl, and azatrax::Azatrax::send2Bytes().

◆ PulseRelays()

ErrorCode azatrax::SR4::PulseRelays ( bool  Q1,
bool  Q2,
bool  Q3,
bool  Q4,
uint8_t  duration 
)
inline

Pulse output relay contacts.

Parameters
Q1Pulse Q1.
Q2Pulse Q2.
Q3Pulse Q3.
Q4Pulse Q4.
durationPulse duration in 0.5 second units.

References azatrax::Azatrax::cmd_OutputRelayPulse, and azatrax::Azatrax::send3Bytes().

◆ Q1_State()

bool azatrax::SR4::Q1_State ( ) const
inline

◆ Q2_State()

bool azatrax::SR4::Q2_State ( ) const
inline

◆ Q3_State()

bool azatrax::SR4::Q3_State ( ) const
inline

◆ Q4_State()

bool azatrax::SR4::Q4_State ( ) const
inline

◆ RelaysOff()

ErrorCode azatrax::SR4::RelaysOff ( bool  Q1,
bool  Q2,
bool  Q3,
bool  Q4 
)
inline

Set output relay contacts off.

Parameters
Q1Turn off Q1.
Q2Turn off Q2.
Q3Turn off Q3.
Q4Turn off Q4.

References azatrax::Azatrax::cmd_OutputRelayOff, and azatrax::Azatrax::send2Bytes().

◆ RelaysOn()

ErrorCode azatrax::SR4::RelaysOn ( bool  Q1,
bool  Q2,
bool  Q3,
bool  Q4 
)
inline

Set output relay contacts on.

Parameters
Q1Turn on Q1.
Q2Turn on Q2.
Q3Turn on Q3.
Q4Turn on Q4.

References azatrax::Azatrax::cmd_OutputRelayOn, and azatrax::Azatrax::send2Bytes().

◆ Sense_1_Latch()

bool azatrax::SR4::Sense_1_Latch ( ) const
inline

◆ Sense_1_Live()

bool azatrax::SR4::Sense_1_Live ( ) const
inline

◆ Sense_2_Latch()

bool azatrax::SR4::Sense_2_Latch ( ) const
inline

◆ Sense_2_Live()

bool azatrax::SR4::Sense_2_Live ( ) const
inline

◆ Sense_3_Latch()

bool azatrax::SR4::Sense_3_Latch ( ) const
inline

◆ Sense_3_Live()

bool azatrax::SR4::Sense_3_Live ( ) const
inline

◆ Sense_4_Latch()

bool azatrax::SR4::Sense_4_Latch ( ) const
inline

◆ Sense_4_Live()

bool azatrax::SR4::Sense_4_Live ( ) const
inline

Friends And Related Function Documentation

◆ Azatrax

friend class Azatrax
friend