Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef XID_CON_T_H
00033 #define XID_CON_T_H
00034
00035 #include "port_settings_t.h"
00036 #include "constants.h"
00037 #include <Windows.h>
00038
00039 namespace cedrus
00040 {
00051 class xid_con_t
00052 {
00053 public:
00054
00065 xid_con_t(
00066 const std::wstring &port_name,
00067 int port_speed = 115200,
00068 int delay_ms = 1,
00069 port_settings_t::bytesize byte_size = port_settings_t::BYTESIZE_8,
00070 port_settings_t::bitparity bit_parity = port_settings_t::BITPARITY_NONE,
00071 port_settings_t::stopbits stop_bits = port_settings_t::STOP_BIT_1
00072 );
00073
00074 virtual ~xid_con_t();
00075
00083 int close();
00084
00092 int flush_input();
00093
00101 int flush_output();
00102
00111 int open();
00112
00125 int read(
00126 unsigned char *in_buffer,
00127 int bytes_to_read,
00128 int &bytes_read);
00129
00140 int write(
00141 unsigned char * const in_buffer,
00142 int bytes_to_write,
00143 int &bytes_written);
00144
00151 key_state check_for_keypress();
00152
00156 void remove_current_response();
00157
00167 void get_current_response(
00168 int &port, int &key, bool &was_pressed, int &reaction_time);
00169
00173 int get_number_of_keys_down();
00174
00190 int send_xid_command(
00191 const char in_command[],
00192 int num_bytes,
00193 char out_response[],
00194 int max_out_response_size,
00195 int expected_bytes_rec,
00196 int timeout = 100,
00197 int command_delay = 0);
00198
00202 void set_needs_interbyte_delay(bool need_delay = true);
00203
00210 void set_digital_out_prefix(char prefix);
00211
00221 void set_digital_output_lines(
00222 unsigned int lines,
00223 bool leave_remaining_lines = false);
00224
00234 void clear_digital_output_lines(
00235 unsigned int lines,
00236 bool leave_remaining_lines = false);
00237
00238 private:
00239 int setup_com_port();
00240 void setup_dcb(DCB &dcb) const;
00241 void setup_timeouts(COMMTIMEOUTS &ct) const;
00242
00243 key_state xid_input_found();
00244
00245 port_settings_t port_settings_;
00246 int in_buffer_size_;
00247 int out_buffer_size_;
00248 int model_id_;
00249 wchar_t port_name_[40];
00250 HANDLE device_id_;
00251
00252 int delay_;
00253
00254 enum {INPUT_BUFFER_SIZE = 1000};
00255 enum {XID_PACKET_SIZE = 6};
00256 enum {INVALID_PACKET_INDEX = -1};
00257 enum {KEY_RELEASE_BITMASK = 0x10};
00258
00259 int bytes_in_buffer_;
00260 unsigned char input_buffer_[INPUT_BUFFER_SIZE];
00261 unsigned char invalid_port_bits_;
00262
00263 const double timer_rate_;
00264
00265 int first_valid_xid_packet_;
00266 int num_keys_down_;
00267 int last_resp_port_;
00268 int last_resp_key_;
00269 bool last_resp_pressed_;
00270 int last_resp_rt_;
00271
00272 char lines_state_;
00273 char set_lines_cmd_[4];
00274
00275 bool needs_interbyte_delay_;
00276 };
00277 }
00278
00279 #endif // XID_CON_T_H