#include <di_serial_io.h>
Collaboration diagram for di_serial_io:
Public Member Functions | |
di_serial_io () | |
Simple initialization. | |
~di_serial_io () | |
Close connection. | |
const u_int16_t | connect (const char *const dev_file, const u_int8_t device) |
Connect to device and set up serial port settings. | |
const u_int16_t | disconnect () |
Restore original serial port settings and disconnect from device. | |
const bool | is_comm_open () |
Determines whether the serial connection is active. | |
const bool | di_read (u_int8_t *data, u_int16_t &amount, const u_int8_t packet_len=2) |
Read data from serial connection, validate if requested. | |
const bool | di_send (const u_int8_t *const data, u_int16_t &amount, const u_int8_t echo=2, const u_int8_t retry=4) |
Send data to device. | |
const int16_t | bytes_in_receive () |
Returns the number of bytes in the input buffer. | |
void | flush_receive () |
Clears input buffers. | |
Private Member Functions | |
const bool | di_valid (const u_int8_t *const data, const u_int8_t packet_len) |
True when packet matches DI signature. | |
const bool | di_synchronize (u_int8_t *data, const u_int8_t data_len, const u_int8_t packet_len) |
Attempts to synchronize the input buffer to the beginning of a packet. | |
const bool | di_echo (const u_int8_t *const expected, const u_int8_t amount) |
Returns true if the 'expected' data is echoed (except NULL). | |
Private Attributes | |
unsigned int | m_baudrate |
Connection baudrate. | |
int | m_comm_fd |
Serial port file descriptor. | |
termios | m_old_termios |
Original serial port settings. | |
int | m_old_tiocm |
Other original settings. | |
u_int8_t | m_timeout |
Timeout in seconds. |
This class handles setting up the port settings, connecting to the device, providing validated reads, send out data, open status, available data points, and some device controlled errors.
Definition at line 46 of file di_serial_io.h.
|
Connect to device and set up serial port settings. Returns error codes of internal functions it calls.
Definition at line 64 of file di_serial_io.cpp. References flush_receive(), m_baudrate, m_comm_fd, m_old_termios, and m_old_tiocm. Referenced by di194_dsdk::DeviceConnect(). |
Here is the call graph for this function:
|
Restore original serial port settings and disconnect from device. Disconnects at all costs. Returns error codes of internal functions.
Definition at line 232 of file di_serial_io.cpp. References flush_receive(), m_comm_fd, m_old_termios, and m_old_tiocm. Referenced by di194_dsdk::DeviceDisconnect(), and ~di_serial_io(). |
Here is the call graph for this function:
|
Determines whether the serial connection is active.
Definition at line 258 of file di_serial_io.cpp. References m_comm_fd. Referenced by di194_dsdk::ADChannelCount(), di194_dsdk::ADChannelList(), di194_dsdk::DeviceConnect(), di194_dsdk::DeviceDisconnect(), di194_dsdk::InfoSerial(), di194_dsdk::OverRun(), di194_dsdk::Start(), and di194_dsdk::Stop(). |
|
Read data from serial connection, validate if requested. Return error codes of internal functions. Function will block until either enough data was read or it timed out, according to m_timeout.
ENODATA = Not enough data available. Errors returned by read(). ETIMEDOUT = Timed out before getting requested amount. Errors set by di_serial_io::di_synchronize(). 0 = No error. Definition at line 285 of file di_serial_io.cpp. References di_synchronize(), di_valid(), m_comm_fd, and m_timeout. Referenced by di_echo(), di_synchronize(), di194_dsdk::GetDataEx(), and Ncmd(). |
Here is the call graph for this function:
|
Send data to device. Flushes output buffer before every command. Blocks slightly if device signals its receive buffer is full.
Errors set by write(). EBADRSVP = Device not responding properly. Bad echo. 0 = No error. Definition at line 367 of file di_serial_io.cpp. References di_echo(), EBADRSVP, flush_receive(), and m_comm_fd. |
Here is the call graph for this function:
|
Returns the number of bytes in the input buffer.
Definition at line 430 of file di_serial_io.cpp. References m_comm_fd. Referenced by di194_dsdk::AvailableData(), flush_receive(), and di194_dsdk::OverRun(). |
|
Clears input buffers.
Definition at line 442 of file di_serial_io.cpp. References bytes_in_receive(), and m_comm_fd. Referenced by connect(), di_send(), and disconnect(). |
Here is the call graph for this function:
|
True when packet matches DI signature.
Current signature format is as follows:
Definition at line 466 of file di_serial_io.cpp. Referenced by di_read(). |
|
Attempts to synchronize the input buffer to the beginning of a packet. Attempts to synchronize the input buffer to the beginning of a packet, it stores what it thinks is a packet in 'data' while at it. Uses the read function without any validation checking.
Definition at line 495 of file di_serial_io.cpp. References di_read(). Referenced by di_read(). |
Here is the call graph for this function:
|
Returns true if the 'expected' data is echoed (except NULL). Checks if 'amount' bytes of 'expected' are echoed by the device. The function automatically excludes the beginning NULL.
Definition at line 527 of file di_serial_io.cpp. References di_read(). Referenced by di_send(). |
Here is the call graph for this function: