From d1976e22c20aa0520b97766f3135c8e5797238ab Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Jan 2015 01:56:23 +0200 Subject: [PATCH] read usb port from file, enabled debug --- plugins/MQTT-SN/MsDevice.serial.cs | 52 +++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/plugins/MQTT-SN/MsDevice.serial.cs b/plugins/MQTT-SN/MsDevice.serial.cs index 9b29185..502c48b 100644 --- a/plugins/MQTT-SN/MsDevice.serial.cs +++ b/plugins/MQTT-SN/MsDevice.serial.cs @@ -66,6 +66,8 @@ internal class MsGSerial : IMsGate { } public static void Open() { + _verbose.value = true; + Log.Info("Search for MQTT-SN.serial devices"); Topic dev=Topic.root.Get("/dev"); dev.Get("_declarer").value="DevFolder"; @@ -73,6 +75,8 @@ internal class MsGSerial : IMsGate { ScanPorts(null, false); } public static void Rescan() { + _verbose.value = true; + if(_scanBusy==0) { _startScan.Set(); } @@ -91,6 +95,8 @@ internal class MsGSerial : IMsGate { SerialPort port=null; int length; bool found; + _verbose.value = true; + List pns=new List(); Topic dev=Topic.root.Get("/dev"); @@ -118,25 +124,46 @@ internal class MsGSerial : IMsGate { } else { pns=pns.Intersect(SerialPort.GetPortNames()).ToList(); } + + pns = new List(); + string curFile = @"port.txt"; + if (File.Exists(curFile)) + { + var logFile = File.ReadAllLines(curFile); + pns = new List(logFile); + // readonlyList LogList = new List(logFile); + } + + for(int i=0; i z.name==pns[i])) { continue; } - + + + Log.Debug("Itteration NR {0}",i); try { + _verbose.value = true; + //Log.Debug("Itteration tryCnt"); port=new SerialPort(pns[i], 38400, Parity.None, 8, StopBits.One); port.ReadBufferSize=300; port.WriteBufferSize=300; port.Open(); port.DiscardInBuffer(); + SendRaw(port, disconnectAll, tmpBuf); // Send Disconnect + Log.Info("done with raw SendRaw(port, disconnectAll"); Thread.Sleep(500); cnt=-1; - tryCnt=6; + tryCnt=30; escChar=false; length=-1; found=false; + while(--tryCnt>0) { + Log.Debug("in tryCnt {0}", tryCnt); + _verbose.value = true; if(GetPacket(port, ref length, buf, ref cnt, ref escChar)) { var msgTyp=(MsMessageType)(buf[0]>1?buf[1]:buf[3]); if(msgTyp==MsMessageType.SEARCHGW || msgTyp==MsMessageType.DHCP_REQ) { // Received Ack @@ -155,14 +182,17 @@ internal class MsGSerial : IMsGate { } Thread.Sleep(90); } - if(!found) { - port.Close(); - continue; + if (!found) + { + Log.Debug("!found"); + port.Close(); + continue; } + else { return; } } catch(Exception ex) { if(_verbose.value) { - Log.Debug("MQTTS.Serial search on {0} - {1}", pns[i], ex.Message); + Log.Debug("MQTTS.Serial search on {0} - ex.Mes {1}", pns[i], ex.Message); } try { if(port!=null) { @@ -240,18 +270,22 @@ internal class MsGSerial : IMsGate { return false; } private static void SendRaw(SerialPort port, byte[] buf, byte[] tmp) { + Log.Debug("in UART_RAW_MQTTSN in raw, (1)", port.IsOpen); if(port==null || !port.IsOpen) { return; } int i, j=0; byte b; b=(byte)buf.Length; + #if UART_RAW_MQTTSN + Log.Debug("if"); tmp[j++]=b; for(i=0; i