Public Member Functions

cedrus::xid_con_t Class Reference

Implementation of communication with an XID device. More...

#include <xid_device_driver/xid_con_t.h>

List of all members.

Public Member Functions

 xid_con_t (const std::wstring &port_name, int port_speed=115200, int delay_ms=1, port_settings_t::bytesize byte_size=port_settings_t::BYTESIZE_8, port_settings_t::bitparity bit_parity=port_settings_t::BITPARITY_NONE, port_settings_t::stopbits stop_bits=port_settings_t::STOP_BIT_1)
 xid_con_t constructor
virtual ~xid_con_t ()
int close ()
 Closes the device.
int flush_input ()
 Flush the device's input buffer.
int flush_output ()
 Flush the device's output buffer.
int open ()
 Opens the COM port for use.
int read (unsigned char *in_buffer, int bytes_to_read, int &bytes_read)
 Read data from the device.
int write (unsigned char *const in_buffer, int bytes_to_write, int &bytes_written)
 Write data to the device.
key_state check_for_keypress ()
 Checks the device to see if an event response has been sent.
void remove_current_response ()
 Removes the current response from the internal buffer.
void get_current_response (int &port, int &key, bool &was_pressed, int &reaction_time)
 Gets the last response from the device.
int get_number_of_keys_down ()
 Number of keys currently being held down.
int send_xid_command (const char in_command[], int num_bytes, char out_response[], int max_out_response_size, int expected_bytes_rec, int timeout=100, int command_delay=0)
 Send an XID command to the device.
void set_needs_interbyte_delay (bool need_delay=true)
 Sets whether or not the device needs an inter-byte delay.
void set_digital_out_prefix (char prefix)
 Sets the digital output prefix.
void set_digital_output_lines (unsigned int lines, bool leave_remaining_lines=false)
 Raise digital output lines on the StimTracker device.
void clear_digital_output_lines (unsigned int lines, bool leave_remaining_lines=false)
 Clear digital output lines on the StimTracker device.

Detailed Description

Implementation of communication with an XID device.

This class implements the nuts and bolts of communicating with an XID device. Inter-byte delays are optionally added if it's communicating with a 4 MHz XID device. It also handles the parsing of the XID protocol 6-byte packats.

Definition at line 51 of file xid_con_t.h.


Constructor & Destructor Documentation

cedrus::xid_con_t::xid_con_t ( const std::wstring &  port_name,
int  port_speed = 115200,
int  delay_ms = 1,
port_settings_t::bytesize  byte_size = port_settings_t::BYTESIZE_8,
port_settings_t::bitparity  bit_parity = port_settings_t::BITPARITY_NONE,
port_settings_t::stopbits  stop_bits = port_settings_t::STOP_BIT_1 
)

xid_con_t constructor

Parameters:
[in]port_nameCOM port name the device is connected to.
[in]port_speedspeed of the port. This defaults to 115200bps
[in]delay_msInter-byte delay time in miliseconds. Defaults to 1ms.
[in]byte_sizeByte size used by the device
[in]bit_paritybit parity of the device. Defaults to none.
[in]stop_bitsstop bits of the device. Defaults to 0

Definition at line 35 of file xid_con_t.cpp.

cedrus::xid_con_t::~xid_con_t ( void   ) [virtual]

Definition at line 80 of file xid_con_t.cpp.


Member Function Documentation

cedrus::key_state cedrus::xid_con_t::check_for_keypress (  )

Checks the device to see if an event response has been sent.

Returns:
key_state if no event was found, NO_KEY_DETECTED is returned. Otherwise, it responds with FOUND_KEY_UP, or FOUND_KEY_DOWN.

Definition at line 334 of file xid_con_t.cpp.

void cedrus::xid_con_t::clear_digital_output_lines ( unsigned int  lines,
bool  leave_remaining_lines = false 
)

Clear digital output lines on the StimTracker device.

Parameters:
[in]linesThis is a bitmask used to specify the lines to be raised on the device. Each of the 8 bits in the integer specifies a line. If bits 0 and 7 are 1, lines 1 and 8 are raised.
[in]leave_remaining_linesboolean value of whether or not to keep the current line state when applying the new bitmask.

Definition at line 499 of file xid_con_t.cpp.

int cedrus::xid_con_t::close (  )

Closes the device.

Returns:
NO_ERR if closing the device was successful, or ERROR_CLOSING_PORT if it was unsuccessful. Enum values are defined in constants.h

Definition at line 86 of file xid_con_t.cpp.

int cedrus::xid_con_t::flush_input (  )

Flush the device's input buffer.

Returns:
NO_ERR if flushing the device was successful, or ERROR_FLUSHING_PORT if it was unsuccessful. Enum values are defined in constants.h

Definition at line 95 of file xid_con_t.cpp.

int cedrus::xid_con_t::flush_output (  )

Flush the device's output buffer.

Returns:
NO_ERR if flushing the device was successful, or ERROR_FLUSHING_PORT if it was unsuccessful. Enum values are defined in constants.h

Definition at line 107 of file xid_con_t.cpp.

void cedrus::xid_con_t::get_current_response ( int &  port,
int &  key,
bool &  was_pressed,
int &  reaction_time 
)

Gets the last response from the device.

Parameters:
[out]portdevice port the response is from. usually 0
[out]keyWhich key was pressed.
[out]was_pressedtrue if a key was pressed, false otherwise
[out]reaction_timereaction time read from the internal device timer.

Definition at line 369 of file xid_con_t.cpp.

int cedrus::xid_con_t::get_number_of_keys_down (  )

Number of keys currently being held down.

Definition at line 390 of file xid_con_t.cpp.

int cedrus::xid_con_t::open (  )

Opens the COM port for use.

Returns:
NO_ERR if opening the device for communication was successful. If the operation was unsuccessful, it can return one of the following: PORT_NOT_AVAILABLE, ERROR_SETTING_UP_PORT, ERROR_FLUSHING_PORT. Enum values are defined in constants.h.

Definition at line 119 of file xid_con_t.cpp.

int cedrus::xid_con_t::read ( unsigned char *  in_buffer,
int  bytes_to_read,
int &  bytes_read 
)

Read data from the device.

Parameters:
[out]in_buffercharacter array to be used for reading data from the device into. It is the user's responsibility to ensure bytes_to_read is less than the size of in_buffer
[in]bytes_to_readspecifies the number of bytes to expect to be returned from the device
[out]bytes_readnumber of bytes actually read
Returns:
NO_ERR if the read was successful, ERROR_READING_PORT otherwise.

Definition at line 212 of file xid_con_t.cpp.

void cedrus::xid_con_t::remove_current_response (  )

Removes the current response from the internal buffer.

Definition at line 351 of file xid_con_t.cpp.

int cedrus::xid_con_t::send_xid_command ( const char  in_command[],
int  num_bytes,
char  out_response[],
int  max_out_response_size,
int  expected_bytes_rec,
int  timeout = 100,
int  command_delay = 0 
)

Send an XID command to the device.

XID commands are documented at http://www.cedrus.com/xid/

Parameters:
[in]in_commandcommand to send to the device
[in]num_bytesnumber of bytes in the command
[out]out_responseresponse from the device
[in]max_out_response_sizemaximum allowed response size
[in]expected_bytes_recnumber of bytes expected
[in]timeoutcommand timeout. Defaults to 100ms
[in]command_delaySome devices need an additional delay between receiving a request and sending a response. Set the delay here. It defaults to 0.

Definition at line 395 of file xid_con_t.cpp.

void cedrus::xid_con_t::set_digital_out_prefix ( char  prefix )

Sets the digital output prefix.

Parameters:
[in]prefixA single character. This should be 'a' for XID response devices, or 'm' for StimTracker devices.

Definition at line 469 of file xid_con_t.cpp.

void cedrus::xid_con_t::set_digital_output_lines ( unsigned int  lines,
bool  leave_remaining_lines = false 
)

Raise digital output lines on the StimTracker device.

Parameters:
[in]linesThis is a bitmask used to specify the lines to be raised on the device. Each of the 8 bits in the integer specifies a line. If bits 0 and 7 are 1, lines 1 and 8 are raised.
[in]leave_remaining_linesboolean value of whether or not to keep the current line state when applying the new bitmask.

Definition at line 474 of file xid_con_t.cpp.

void cedrus::xid_con_t::set_needs_interbyte_delay ( bool  need_delay = true )

Sets whether or not the device needs an inter-byte delay.

Definition at line 464 of file xid_con_t.cpp.

int cedrus::xid_con_t::write ( unsigned char *const   in_buffer,
int  bytes_to_write,
int &  bytes_written 
)

Write data to the device.

If the device is a 4MHz XID unit, an inter-byte delay is used between each byte sent to the device.

Parameters:
[in]in_buffercommand to be sent to the device
[in]bytes_to_writenumber of bytes in the command to be sent
[out]bytes_writtennumber of bytes written to the device

Definition at line 233 of file xid_con_t.cpp.


The documentation for this class was generated from the following files: