Implementation of communication with an XID device. More...
#include <xid_device_driver/xid_con_t.h>
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. |
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.
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
[in] | port_name | COM port name the device is connected to. |
[in] | port_speed | speed of the port. This defaults to 115200bps |
[in] | delay_ms | Inter-byte delay time in miliseconds. Defaults to 1ms. |
[in] | byte_size | Byte size used by the device |
[in] | bit_parity | bit parity of the device. Defaults to none. |
[in] | stop_bits | stop 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.
cedrus::key_state cedrus::xid_con_t::check_for_keypress | ( | ) |
Checks the device to see if an event response has been sent.
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.
[in] | lines | This 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_lines | boolean 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.
Definition at line 86 of file xid_con_t.cpp.
int cedrus::xid_con_t::flush_input | ( | ) |
Flush the device's input buffer.
Definition at line 95 of file xid_con_t.cpp.
int cedrus::xid_con_t::flush_output | ( | ) |
Flush the device's output buffer.
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.
[out] | port | device port the response is from. usually 0 |
[out] | key | Which key was pressed. |
[out] | was_pressed | true if a key was pressed, false otherwise |
[out] | reaction_time | reaction 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.
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.
[out] | in_buffer | character 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_read | specifies the number of bytes to expect to be returned from the device |
[out] | bytes_read | number of bytes actually read |
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/
[in] | in_command | command to send to the device |
[in] | num_bytes | number of bytes in the command |
[out] | out_response | response from the device |
[in] | max_out_response_size | maximum allowed response size |
[in] | expected_bytes_rec | number of bytes expected |
[in] | timeout | command timeout. Defaults to 100ms |
[in] | command_delay | Some 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.
[in] | prefix | A 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.
[in] | lines | This 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_lines | boolean 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.
[in] | in_buffer | command to be sent to the device |
[in] | bytes_to_write | number of bytes in the command to be sent |
[out] | bytes_written | number of bytes written to the device |
Definition at line 233 of file xid_con_t.cpp.