/// <summary> /// this function starts the serial port detection, waits for the results to return, and /// reports back the detect serial port name /// </summary> /// <returns></returns> public string DeterminePort(int baud) { Initialize(); string comport = "invalid"; bool done = false; SerialAutodetectConfig config = new SerialAutodetectConfig(); config.m_baud = baud; //open and test all serial ports at once foreach (String s in DeviceDriver.GetPortNames()) { if (s.Equals("COM113")) { // create a new tester ConnectionTester tester = new ConnectionTester(s); // specify the name of the port we're trying to detect //set the baud tester.m_baud = config.m_baud; //set up to listen to events tester.ConnectionTesterStatusEvent += new ConnectionTester.ConnectionTesterStatus(ConnectionTesterStatusDel); //start it off tester.Start(); } } m_starttime = Environment.TickCount; while (!done) { try { //check for timeout if (Environment.TickCount >= (m_starttime + TIMEOUTTIME)) { done = true; } Thread.Sleep(0); // yield lock (m_lock) { // check the m_lstresults foreach (ConnectionTester con in m_lstresults) { if (con.m_result == ConnectionTester.eConnTestStatus.eDeviceResponded) { comport = con.m_portname; done = true; Initialize(); break; } } } } catch (Exception ex) { DebugLogger.Instance().LogError(ex); } } return(comport); }
/// <summary> /// this function starts the serial port detection, waits for the results to return, and /// reports back the detect serial port name /// </summary> /// <returns></returns> public string DeterminePort(int baud) { Initialize(); string comport = "invalid"; bool done = false; SerialAutodetectConfig config = new SerialAutodetectConfig(); config.m_baud = baud; //open and test all serial ports at once foreach (String s in DeviceDriver.GetPortNames()) { if (s.Equals("COM113")) { // create a new tester ConnectionTester tester = new ConnectionTester(s); // specify the name of the port we're trying to detect //set the baud tester.m_baud = config.m_baud; //set up to listen to events tester.ConnectionTesterStatusEvent += new ConnectionTester.ConnectionTesterStatus(ConnectionTesterStatusDel); //start it off tester.Start(); } } m_starttime = Environment.TickCount; while (!done) { try { //check for timeout if (Environment.TickCount >= (m_starttime + TIMEOUTTIME)) done = true; Thread.Sleep(0); // yield lock (m_lock) { // check the m_lstresults foreach (ConnectionTester con in m_lstresults) { if (con.m_result == ConnectionTester.eConnTestStatus.eDeviceResponded) { comport = con.m_portname; done = true; Initialize(); break; } } } } catch (Exception ex) { DebugLogger.Instance().LogError(ex); } } return comport; }
private void run() { //get the list of serial ports foreach (String s in SerialPort.GetPortNames()) { // create a new tester ConnectionTester tester = new ConnectionTester(s); //set the baud tester.m_baud = m_config.m_baud; //set up to listen to events tester.ConnectionTesterStatusEvent += new ConnectionTester.ConnectionTesterStatus(ConnectionTesterStatusDel); //start it off tester.Start(); } //for each serial port, create a new serial port tester while (m_running) { //check for timeout Thread.Sleep(0); } }
private void run() { //get the list of serial ports foreach (String s in SerialPort.GetPortNames()) { // create a new tester ConnectionTester tester = new ConnectionTester(s); //set the baud tester.m_baud = m_config.m_baud; //set up to listen to events tester.ConnectionTesterStatusEvent += new ConnectionTester.ConnectionTesterStatus(ConnectionTesterStatusDel); //start it off tester.Start(); } //for each serial port, create a new serial port tester while (m_running) { //check for timeout Thread.Sleep(0); } }