Main Page | Modules | Class Hierarchy | Class List | File List | Class Members

di_serial_io Class Reference

Class to handle serial type connections. More...

#include <di_serial_io.h>

Collaboration diagram for di_serial_io:

Collaboration graph
[legend]
List of all members.

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.


Detailed Description

Class to handle serial type connections.

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.


Member Function Documentation

const u_int16_t di_serial_io::connect const char *const  dev_file,
const u_int8_t  device
 

Connect to device and set up serial port settings.

Returns error codes of internal functions it calls.

Parameters:
dev_file Device file path and name.
device Device code for specific settings. See file comment.
Precondition:
Inactive connection. Does not check!
Postcondition:
Connection to device file, port set up.
Remarks:
This only applies settings, nothing else. It doesn't lock the device file or check if it is locked. It quits on any errors.
Returns:
Errors returned by open()
Errors returned by tcgetattr()
Errors returned by cfsetispeed()
Errors returned by cfsetospeed()
Errors returned by tcsetattr()
0 = No error.

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:

const u_int16_t di_serial_io::disconnect  ) 
 

Restore original serial port settings and disconnect from device.

Disconnects at all costs. Returns error codes of internal functions.

Precondition:
Connected. Does not check!
Postcondition:
Not connected.
Remarks:
This function attempts to reset the serial port settings. Calling it before connect() will result in undefined settings.
Returns:
Errors returned by close().
0 = No error.

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:

const bool di_serial_io::is_comm_open  ) 
 

Determines whether the serial connection is active.

Returns:
True = Connected.
False = Not connected.

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().

const bool di_serial_io::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.

Return error codes of internal functions. Function will block until either enough data was read or it timed out, according to m_timeout.

Parameters:
data The data read.
amount The number of bytes to try and read.
packet_len Length of normal packet/scan (bytes). If this value is zero, validation is not performed.
Precondition:
Connected. Does not check!
Returns:
True = Error occurred.
False = No error.
Error codes set:
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:

const bool di_serial_io::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.

Flushes output buffer before every command. Blocks slightly if device signals its receive buffer is full.

Precondition:
Connected. Does not check!
Parameters:
data Pointer to array of data to send.
amount Number of bytes to send.
echo Number of bytes to check for echo (except NULL).
retry Number of times to try checking echo. Value of zero will prevent the entire send from occurring.
Returns:
True = Error occurred.
False = No error.
Error codes set:
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.

Referenced by Ccmd(), Dcmd(), Ncmd(), and Scmd().

Here is the call graph for this function:

const int16_t di_serial_io::bytes_in_receive  ) 
 

Returns the number of bytes in the input buffer.

Precondition:
Connected. Does not check!
Returns:
Number of bytes in the receive 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().

void di_serial_io::flush_receive  ) 
 

Clears input buffers.

Precondition:
Connected. Does not check!
Remarks:
No error checking.

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:

const bool di_serial_io::di_valid const u_int8_t *const  data,
const u_int8_t  packet_len
[private]
 

True when packet matches DI signature.

Current signature format is as follows:
0 = Last bit of first byte in 'packet'
1 = Last bit of remaining bytes in 'packet'

Parameters:
data The 'packet' to test.
packet_len Normal packet size.
Returns:
True = 'Packet' is valid.
False = Failed validation test.

Definition at line 466 of file di_serial_io.cpp.

Referenced by di_read().

const bool di_serial_io::di_synchronize u_int8_t *  data,
const u_int8_t  data_len,
const u_int8_t  packet_len
[private]
 

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.

Precondition:
Connected. Does not check!
Parameters:
data Pointer to array where to store next 'packet'.
data_len Length of data.
packet_len Length of a normal packet/scan (bytes).
Returns:
False = Synchronized successfully.
True = Error occurred.

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:

const bool di_serial_io::di_echo const u_int8_t *const  expected,
const u_int8_t  amount
[private]
 

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.

Precondition:
Connected. Does not check!
Remarks:
The beginning NULL must be in expected.
Parameters:
expected Pointer to array of expected data.
amount Number of bytes to check.
Returns:
True = Echo matched.
False = Echo did not match.

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:


Generated on Mon Aug 2 09:45:00 2004 for DataqSDK by doxygen 1.3.6