public bool Next_Find_Device() { if (sm != null) { sm.ClosePort(); sm = null; } if (_f_ports == null) { respuesta = false; _f_resp_scom = "-"; _f_com = "-"; return(true); } if (_f_cnt < _f_ports.Length) { respuesta = false; _f_resp_scom = "-"; _f_com = _f_ports[_f_cnt]; port = _f_com; _f_cnt++; return(Open()); } respuesta = false; _f_resp_scom = "-"; _f_com = "-"; return(true); }
public void Stop_Find_Device() { if (sm != null) { sm.ClosePort(); sm = null; } }
public void Close() { if (sm != null) { Disable_All(); Thread.Sleep(100); Poll(); sm.ClosePort(); sm = null; } OnLine = false; }
public string Find_Device() { string[] portNames = SerialPort.GetPortNames(); ECHO = false; CHKTYPE = CHECKSUMTYPE.CRC16BIT; bool flag = false; CCT_PrepareMsg(1, "28 0 1 9F", bAddChecksum: true); _f_resp_scom = "-"; respuesta = false; if (portNames == null) { return("-"); } string[] array = portNames; foreach (string text in array) { try { bFoundAcceptor = false; if (sm == null) { sm = new SerialManager(); } sm.OnReceivedData += sm_OnReceivedData; OnCCTRxData += cct_OnCCTRxData; OnCCTTxData += cct_OnCCTTxData; sm.BAUDRATE = 9600; port = text; sm.PORTNAME = port; sm.OpenPort(); bFoundAcceptor = false; flag = false; CCT_PrepareMsg(1, "28 0 1 9F", bAddChecksum: true); Poll(); Thread.Sleep(100); Enable(); Poll(); Thread.Sleep(100); for (int j = 0; j < 20; j++) { Poll(); Thread.Sleep(100); if (bFoundAcceptor) { Disable(); if (sm != null) { sm.ClosePort(); sm = null; } respuesta = true; _f_resp_scom = text; return(text); } } if (sm != null) { sm.ClosePort(); sm = null; } } catch { if (sm != null) { sm.ClosePort(); sm = null; } } } return("-"); }
public bool Open() { if (sm != null) { sm.ClosePort(); sm = null; } _f_ports = SerialPort.GetPortNames(); int num = 0; if (_f_ports != null) { for (int i = 0; i < _f_ports.Length; i++) { if (_f_ports[i].ToLower() == port.ToLower()) { num = 1; } } } if (port == "-" || port == "?" || num == 0) { return(false); } if (sm == null) { sm = new SerialManager(); } sm.BAUDRATE = 9600; sm.PORTNAME = port; sm.OnReceivedData += sm_OnReceivedData; OnCCTRxData += cct_OnCCTRxData; OnCCTTxData += cct_OnCCTTxData; ECHO = false; CHKTYPE = CHECKSUMTYPE.CRC16BIT; OnLine = false; try { sm.OpenPort(); } catch (Exception) { return(false); } OnLine = true; NoMoney = 1; bool flag = false; CCT_PrepareMsg(1, "28 0 1 9F", bAddChecksum: true); for (int i = 0; i < 5; i++) { Poll(); Thread.Sleep(100); } Enable(); for (int i = 0; i < 10; i++) { Poll(); Thread.Sleep(100); } TimeOutComs = 0; return(true); }