| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 
 | // **********************************************************
// * search_pedal_port 										*
// *														*
// * enumerate the serial ports	on the tablet				*
// * search for the one connected to the pedal				*
// **********************************************************
bool pedal::search_pedal_port(void)
{
 
std::string				sport_number;
std::string				sport_name;
int						port_number_max;
char*					cport_name;
 
	if (enumerate_serial_ports())
	{
		#ifdef CENUMERATESERIAL_USE_STL
			port_number_max = ports.size();
		#else
			port_number_max = ports.GetSize();
		#endif
		port_number = 0;
		while ((pedalport == PEDALPORT_UNKNOWN)&&(port_number != port_number_max))
		{
			sport_number = to_string(ports[port_number]);
			sport_name = "COM" + sport_number;
			cport_name = const_cast<char*>(sport_name.c_str());
 
			com = new tserial_event();
			if (com!=0)
			{
				com->setManager(this->SerialEventManager);
				error = com->connect(cport_name, PEDAL_PORT_SPEED, SERIAL_PARITY_NONE, PEDAL_PORT_BITS, PEDAL_PORT_MODEM_EVENT);
				if (!error)
				{
					this->request_iss_version();
					this->wait_for_reply();
					while ((!iss_version_received)&&(!this->pedalreply_timeelapsed));
					com->disconnect();
					if (iss_version_received)
					{
						portname = cport_name;
						com->~tserial_event();
						return PEDAL_DETECTED;
					}
					else
						port_number++;
				}
				else
					return PEDAL_UNDETECTED;
			}
		}
		com->~tserial_event();
		return PEDAL_UNDETECTED;
	}
}
 
// **********************************************************
// * setup           										*
// **********************************************************
bool pedal::setup(void)
{
	com = new tserial_event();
	if (com!=0)
	{
		com->setManager(this->SerialEventManager);
		error = com->connect(this->portname, PEDAL_PORT_SPEED, SERIAL_PARITY_NONE, PEDAL_PORT_BITS, PEDAL_PORT_MODEM_EVENT);
		if (!error)
		{
			configure_io_mode();
			wait_for_reply();
			while ((!io_mode_received)&&(!this->pedalreply_timeelapsed));
			com->disconnect();
			com->~tserial_event();
			return (io_mode_received);
		}
	}
} | 
Partager