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 #include "xid_device_scanner_t.h"
00033 #include "xid_con_t.h"
00034
00035 #include <boost/shared_ptr.hpp>
00036
00037 cedrus::xid_device_scanner_t::xid_device_scanner_t(void)
00038 {
00039 load_available_com_ports();
00040 }
00041
00042
00043 cedrus::xid_device_scanner_t::~xid_device_scanner_t(void)
00044 {
00045 }
00046
00047 void cedrus::xid_device_scanner_t::load_available_com_ports()
00048 {
00049 available_com_ports_.clear();
00050 for(int i=1; i < MAX_PORTS; ++i)
00051 {
00052 wchar_t port_name[10];
00053 wsprintf(port_name, L"COM%d", i);
00054
00055 cedrus::xid_con_t conn(port_name);
00056
00057 int status = conn.open();
00058
00059 if(status == NO_ERR)
00060 {
00061 conn.close();
00062 available_com_ports_.push_back(port_name);
00063 }
00064 }
00065 }
00066
00067 int cedrus::xid_device_scanner_t::detect_valid_xid_devices()
00068 {
00069 load_available_com_ports();
00070
00071 rb_connections_.clear();
00072 st_connections_.clear();
00073 int devices = 0;
00074
00075 for(std::vector<std::wstring>::iterator iter = available_com_ports_.begin(),
00076 end = available_com_ports_.end();
00077 iter != end; ++iter)
00078 {
00079 bool device_found = false;
00080 const int baud_rate[] = { 115200, 19200, 9600, 57600, 38400 };
00081 const int num_bauds = sizeof(baud_rate)/sizeof(int);
00082
00083 for(int i = 0; i < num_bauds && !device_found; ++i)
00084 {
00085 boost::shared_ptr<cedrus::xid_con_t> xid_con(
00086 new xid_con_t(*iter, baud_rate[i]));
00087
00088 if(xid_con->open() == NO_ERR)
00089 {
00090 char return_info[200];
00091 xid_con->flush_input();
00092 xid_con->flush_output();
00093 xid_con->send_xid_command(
00094 "_c1",
00095 0,
00096 return_info,
00097 sizeof(return_info),
00098 5,
00099 1000,
00100 100);
00101
00102 std::string info;
00103 if(return_info[0] == NULL)
00104 {
00105
00106
00107
00108 for(int j = 0; j < sizeof(return_info); ++j)
00109 {
00110 if(return_info[j] != NULL)
00111 {
00112 info.append(&return_info[j], 1);
00113 }
00114 }
00115 }
00116 else
00117 {
00118 info = std::string(return_info);
00119 }
00120
00121 if(strstr(info.c_str(), "_xid"))
00122 {
00123
00124 ++devices;
00125
00126 device_found = true;
00127
00128 if(strcmp(info.c_str(), "_xid0") != 0)
00129 {
00130
00131
00132
00133 char empty_return[10];
00134 xid_con->send_xid_command(
00135 "c10",
00136 0,
00137 empty_return,
00138 sizeof(empty_return),
00139 0);
00140
00141 xid_con->flush_input();
00142 xid_con->flush_output();
00143 }
00144
00145 char dev_type[10];
00146 xid_con->send_xid_command(
00147 "_d2",
00148 0,
00149 dev_type,
00150 sizeof(dev_type),
00151 1,
00152 1000);
00153
00154 if(dev_type[0] == 'S')
00155 {
00156 st_connections_.push_back(xid_con);
00157 }
00158 else
00159 {
00160 rb_connections_.push_back(xid_con);
00161 }
00162 }
00163 }
00164
00165 xid_con->close();
00166 }
00167 }
00168
00169 return devices;
00170 }
00171
00172 boost::shared_ptr<cedrus::xid_con_t>
00173 cedrus::xid_device_scanner_t::response_device_connection_at_index(unsigned int i)
00174 {
00175 if(i >= rb_connections_.size())
00176 return boost::shared_ptr<xid_con_t>();
00177
00178 return rb_connections_[i];
00179 }
00180
00181 boost::shared_ptr<cedrus::xid_con_t>
00182 cedrus::xid_device_scanner_t::stimtracker_connection_at_index(unsigned int i)
00183 {
00184 if( i > st_connections_.size())
00185 return boost::shared_ptr<xid_con_t>();
00186
00187 return st_connections_[i];
00188 }
00189
00190 int cedrus::xid_device_scanner_t::rb_device_count() const
00191 {
00192 return rb_connections_.size();
00193 }
00194
00195 int cedrus::xid_device_scanner_t::st_device_count() const
00196 {
00197 return st_connections_.size();
00198 }