Model Railroad System
2.2.1
|
#include <Azatrax.h>
Classes | |
struct | StateDataPacket |
Raw USB Data Packet. More... | |
Public Types | |
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... | |
Public Member Functions | |
~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... | |
Static Public Member Functions | |
static int | NumberOfOpenDevices () |
Open device count. More... | |
static char ** | AllConnectedDevices () |
List serial numbers of all connected devices. More... | |
static Azatrax * | OpenDevice (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 | |
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 | |
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 | |
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 | |
static int | deviceOpenCount |
Device open count. More... | |
Friends | |
class | MRD |
class | SL2 |
class | SR4 |
Azatrax I/O Class.
Base Azatrax interface class. From this base class, a class is derived that implements the device-specific functions. The base class only implements the shared core functions. It also includes a static method that implements a factor that creates device instances from device serial numbers.
There are two static methods, one that return the number of open devices (active instances) and another that returns a list of discovered serial numbers.
anonymous enum |
Command codes.
Enumerator | |
---|---|
cmd_SetChan1 | Set channel 1 (MRD2 only) |
cmd_SetChan2 | Set channel 2 (MRD2 only) |
cmd_ClearExternallyChanged | Clear Externally Changed (MRD2 only) |
cmd_DisableExternal | Disable External Changes (MRD2 only) |
cmd_EnableExternal | Enable External Changes (MRD2 only) |
cmd_Q1posQ2neg | (SL2 only) Sets output terminal Q1 to positive, Q2 to negative. |
cmd_Q1negQ2pos | (SL2 only) Sets output terminal Q1 to negative, Q2 to positive. |
cmd_Q1Q2open | (SL2 only) Outputs Q1 & Q2 both set to open circuit (disconnects switch machine #1) |
cmd_Q3posQ4neg | (SL2 only) Sets output terminal Q3 to positive, Q4 to negative. |
cmd_Q3negQ4pos | (SL2 only) Sets output terminal Q3 to negative, Q4 to positive. |
cmd_Q3Q4open | (SL2 only) Outputs Q3 & Q4 both set to open circuit (disconnects switch machine #1) |
cmd_RestoreLEDFunction | Restore LED Function (All devices) |
cmd_Identify_1 | Identify LED 1 (All devices) |
cmd_Identify_2 | Identify LED 2 (MRD2 only) |
cmd_Identify_1_2 | Identify both LEDs (MRD2 only) |
cmd_ResetStopwatch | Reset Stopwatch (MRD2 only) |
cmd_GetStateData | Get State Data (All devices) |
cmd_OutputRelayBlink | 3 bytes - Sets output relay contacts to blinking state. 2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected 3rd Byte is the output on/off rate (50% duty cycle): bits<7:2>: ignored bits<1:0>: 1,1 - one cycle / 2 seconds 1,0 - one cycle / second 0,1 - two cycles / second 0,0 - four cycles / second |
cmd_OutputRelayOff | 2 bytes - Sets output relay contacts to 'off' state. 2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected |
cmd_OutputRelayOn | (SR4 only) 2 bytes - Sets output relay contacts to 'on' state. 2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected |
cmd_OutputRelayPulse | (SR4 only) 3 bytes - Pulses output relay contacts to momentary 'on' state. 2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected 3rd Byte is pulse duration in 0.5 second increments: 0x00: no pulse generated 0x01: 0.5 sec 0x02: 1.0 sec ... ... 0xFE 63.0 sec 0xFF 63.5 sec |
cmd_OutputRelayInputControl | (SR4 and SL2 only) 2 bytes - Enables/disables discrete input lines from controlling outputs For SL2: When enabled, I1 & I2 affect Q1 & Q2 (switch 1), I3 & I4 affect Q3 & Q4 (switch 2). 2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 enables I4, 0 disables bit 2: 1 enables I3, 0 disables bit 1: 1 enables I2, 0 disables bit 0: 1 enables I1, 0 disables For SR4: 2nd Byte is a bit map of the inputs: bits 7-4: ignored bit 3: 1 if I4 active causes Q4 on, else 0 (I4 does not affect Q4) bit 2: 1 if I3 active causes Q3 on, else 0 (I3 does not affect Q3) bit 1: 1 if I2 active causes Q2 on, else 0 (I2 does not affect Q2) bit 0: 1 if I1 active causes Q1 on, else 0 (I1 does not affect Q1) |
|
protected |
Base constructor.
serialnumber | The serial number of the device to open. |
idProduct | The product Id to look for. |
outmessage | To hold an error message, if any. |
azatrax::Azatrax::~Azatrax | ( | ) |
Base destructor.
|
static |
List serial numbers of all connected devices.
Return a vector of serial number strings.
Referenced by NumberOfOpenDevices().
|
staticprotected |
Return the matching product id for this device and serial number.
Checks if the dev is a Azatrax device, with the specified serial number, matching for product id.
dev | libusb_device struct pointer (from libusb_get_device_list). |
serialnumber | the serial number we are looking for. |
idProductMatch | either an exact product id or 0 (means any product id) |
Referenced by ProductIdCode().
ErrorCode azatrax::Azatrax::GetStateData | ( | ) |
Get State Data.
Get State Data - retrieve 16 byte data packet from sensor to in memory copy.
Referenced by Identify_1().
|
inline |
Identify 1.
Identify 1 - Flashes sensor 1's LED.
References cmd_Identify_1, ErrorCode, GetStateData(), and sendByte().
|
staticprotected |
Is this the device we want?
Check to see if this device is a Azatrax device and if it has the serial number we want.
dev | libusb_device struct pointer (from libusb_get_device_list). |
serialnumber | the serial number we are looking for. |
idProduct | the product id code. |
Referenced by ProductIdCode().
|
inline |
My product name.
Return our Product name.
References idMRDProduct, idSL2Product, idSR4Product, and myProductId.
|
inline |
|
inlinestatic |
Open device count.
Return the number of open devices.
References AllConnectedDevices(), deviceOpenCount, and OpenDevice().
|
static |
Open an Azatrax device by serial number.
serialnumber | the serial number to open. |
idProduct | The product id code identifing the type of device to open. Passing 0 means open any Azatrax device. |
outmessage | To hold an error message, if any. |
Referenced by NumberOfOpenDevices().
|
inline |
Packet count.
References azatrax::Azatrax::StateDataPacket::packetCount, and stateDataPacket.
|
inlinestatic |
Product id code.
Return a product ID code.
productName | The name of the product. |
References ErrorCode, GetProductId(), idMRDProduct, idSL2Product, idSR4Product, IsThisTheAzatraxWeAreLookingFor(), send2Bytes(), send3Bytes(), and sendByte().
|
inline |
Restore LED function.
Restore LED function - On-board LEDs return to their normal function of indicating status of sensors 1 and 2.
References cmd_RestoreLEDFunction, and sendByte().
|
protected |
Send a command byte with 1 data byte.
Sends one command byte on endpoint 01, with one data byte.
commandByte | The command byte to send. |
byte2 | The data byte to send. |
Referenced by azatrax::SL2::OutputRelayInputControl(), azatrax::SR4::OutputRelayInputControl(), ProductIdCode(), azatrax::SR4::RelaysOff(), and azatrax::SR4::RelaysOn().
|
protected |
Send a command bytewith 2 data bytes.
Sends one command byte on endpoint 01, with two data bytes.
commandByte | The command byte to send. |
byte2 | The first data byte to send. |
byte3 | The second data byte to send. |
Referenced by azatrax::SR4::BlinkRelays(), ProductIdCode(), and azatrax::SR4::PulseRelays().
|
protected |
Send a command byte.
Sends one command byte on endpoint 01.
commandByte | the command byte to send. |
Referenced by azatrax::MRD::ClearExternallyChanged(), azatrax::MRD::DisableExternal(), azatrax::MRD::EnableExternal(), Identify_1(), azatrax::MRD::Identify_1_2(), azatrax::MRD::Identify_2(), ProductIdCode(), azatrax::MRD::ResetStopwatch(), RestoreLEDFunction(), azatrax::MRD::SetChan1(), azatrax::MRD::SetChan2(), azatrax::SL2::SetQ1negQ2pos(), azatrax::SL2::SetQ1posQ2neg(), azatrax::SL2::SetQ1Q2open(), azatrax::SL2::SetQ3negQ4pos(), azatrax::SL2::SetQ3posQ4neg(), and azatrax::SL2::SetQ3Q4open().
|
inline |
|
friend |
|
friend |
|
friend |
|
staticprotected |
Device open count.
This is used to decide if and when to call libusb_init and libusb_exit.
Referenced by NumberOfOpenDevices().
|
protected |
USB Device Handle.
This is the USB device handle for the device.
|
protected |
Product id.
Referenced by MyProduct(), and MyProductId().
|
protected |
|
protected |
Referenced by azatrax::MRD::AllowingExternalChanges(), azatrax::MRD::ExternallyChanged(), azatrax::MRD::HasRelays(), azatrax::SL2::Input_1_Enabled(), azatrax::SR4::Input_1_Enabled(), azatrax::SL2::Input_2_Enabled(), azatrax::SR4::Input_2_Enabled(), azatrax::SL2::Input_3_Enabled(), azatrax::SR4::Input_3_Enabled(), azatrax::SL2::Input_4_Enabled(), azatrax::SR4::Input_4_Enabled(), azatrax::MRD::Latch_1(), azatrax::MRD::Latch_2(), azatrax::SL2::Motor_1_Direction(), azatrax::SL2::Motor_1_State(), azatrax::SL2::Motor_2_Direction(), azatrax::SL2::Motor_2_State(), azatrax::MRD::OperatingMode(), PacketCount(), azatrax::SR4::Q1_State(), azatrax::SR4::Q2_State(), azatrax::SR4::Q3_State(), azatrax::SR4::Q4_State(), azatrax::MRD::ResetStatus(), azatrax::SL2::Sense_1(), azatrax::MRD::Sense_1(), azatrax::SR4::Sense_1_Latch(), azatrax::SR4::Sense_1_Live(), azatrax::SL2::Sense_2(), azatrax::MRD::Sense_2(), azatrax::SR4::Sense_2_Latch(), azatrax::SR4::Sense_2_Live(), azatrax::SL2::Sense_3(), azatrax::SR4::Sense_3_Latch(), azatrax::SR4::Sense_3_Live(), azatrax::SL2::Sense_4(), azatrax::SR4::Sense_4_Latch(), azatrax::SR4::Sense_4_Live(), azatrax::MRD::Stopwatch(), and azatrax::MRD::StopwatchTicking().