COMRAD

A C++ library for controlling Conrad relay boards through a serial port on Linux (and possibly other POSIX compliant systems, haven't tested).

Get the latest version here: https://codeberg.org/zynskeyfolf/comrad

Please use the repo's issue tracker for reporting bugs. My web design team is on Hawaii.

comradPort class member functions reference


comradPort comradPort()

Constructor, nothing much to say here. A comradPort object represents a chain of relay boards connected to a serial port. Initialization of the port and the cards is done by separate functions.


int Setup(char *devpath)

Open and initialize a serial port at the specified device name with the appropriate settings for communicating with a relay board.

return value:
0: Success.
1: Unable to open port. (permission issue?)
2: File opened but is not a valid tty.


CmrdResult sendCommand(unsigned char writebuf[4])

Send a command frame to the bus and verify the response frame. If the execution is succesful, the data byte from the response is stored and can be retrieved later by responseData().

return value:
CMRD_EXEC_OK: Success.
CMRD_ERR_RESPONSE_INVALID: Communication error due to missing bytes or bad checksum.
CMRD_ERR_MSG: Card returned an error message. The responding card's address can be retrieved by responseData().


CmrdResult init(unsigned char firstaddr)

Initialize all cards on the port. The specified address is assigned to the first card, and for every subsequent card the address increases by 1. Use lastCard() to get the address of the last card. The first card's firmware version can be retrieved by responseData().

return value:
CMRD_ERR_INIT_FAIL: Invalid loopback response from the last card.
For any other value see sendCommand.


unsigned char responseData()

Returns the data byte from the response to the last command if it was successful, or the card's address in case it returned an error message.


unsigned char lastCard()

Returns the address of the last card on the port after successful initialization.


CmrdResult nop(unsigned char addr)

Send a NOP command to the specified card. This is solely for testing if the card is communicating correctly. Please note that this command will always result in an error message.

return value: see sendCommand.


CmrdResult getCardStatus(unsigned char addr)

Read the output state of a card and store it to be retrieved by responseData(). Each bit of the data byte corresponds to an output pin.

return value: see sendCommand.


CmrdResult setCard(unsigned char addr, unsigned char data)

Set the output state of a card to data. Each bit of the data byte corresponds to an output pin.

return value: see sendCommand.


CmrdResult getOption(unsigned char addr)

Read the current value of various options for the specified card and store it to be retrieved by responseData(). See the card's manual for details.

return value: see sendCommand.


CmrdResult setOption(unsigned char addr, unsigned char data)

Set the value for various options for the specified card to data. See the card's manual for details.

return value: see sendCommand.


CmrdResult setPins(unsigned char addr, unsigned char data)

Turn the specified output pins on without changing the rest. Each bit of the data byte corresponds to an output pin.

return value: see sendCommand.


CmrdResult delPins(unsigned char addr, unsigned char data)

Turn the specified output pins off without changing the rest. Each bit of the data byte corresponds to an output pin.

return value: see sendCommand.


CmrdResult togglePins(unsigned char addr, unsigned char data)

Toggle the state of the specified output pins without changing the rest. Each bit of the data byte corresponds to an output pin.

return value: see sendCommand.


This is basically all, thanks for reading 0w0