• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xid_con_t.h

Go to the documentation of this file.
00001 /* Copyright (c) 2010, Cedrus Corporation
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are
00006  * met:
00007  *
00008  * Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.  
00010  *
00011  * Redistributions in binary form must reproduce the above copyright
00012  * notice, this list of conditions and the following disclaimer in the
00013  * documentation and/or other materials provided with the distribution.
00014  *
00015  * Neither the name of Cedrus Corporation nor the names of its
00016  * contributors may be used to endorse or promote products derived from
00017  * this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 } // namespace cedrus
00278 
00279 #endif // XID_CON_T_H

Generated on Wed Dec 15 2010 13:17:12 for XID device library by  doxygen 1.7.2