public void Start(SerialAutodetectConfig config) { m_running = true; m_thread = new Thread(new ThreadStart(run)); m_list = new List <ConnectionTester>(); m_lstresults = new List <ConnectionTester>(); m_thread.Start(); }
public void Start(SerialAutodetectConfig config) { m_running = true; m_thread = new Thread(new ThreadStart(run)); m_list = new List<ConnectionTester>(); m_lstresults = new List<ConnectionTester>(); m_thread.Start(); }
/// <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; }