//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public void Read() { SharpPy msg = new SharpPy() { operation = RWCMD.DRRead, payload = "", }; var res = base.ReadSingleValue(msg); }
//------------------------------------------------------------------------------------------------------------------------ public void SendMessage(string data) { SharpPy msg = new SharpPy() { payload = data }; this.sharppyiface.Send2python(msg); }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public override void ReadContinuously() { SharpPy msg = new SharpPy() { operation = RWCMD.ARead, payload = "", }; base.ReadContinuously(msg); }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public void Read() { SharpPy msg = new SharpPy() { operation = RWCMD.DRRead, payload = "", }; var res = base.ReadSingleValue(msg); }
//------------------------------------------------------------------------------------------------------------------------ public override void ReadContinuously() { SharpPy msg = new SharpPy() { operation = RWCMD.DRRead, payload = "", }; base.ReadContinuously(msg); }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public void Display(string value) { SharpPy msg = new SharpPy() { pin = this.Pin.ToString(), operation = RWCMD.LCD, payload = value, isRequest = true }; DebugEx.TraceLog("LCD: Send to python: " + msg); this.transport.Send2python(msg); }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Functions //------------------------------------------------------------------------------------------------------------------------ public void Display(string value) { SharpPy msg = new SharpPy() { pin = this.Pin.ToString(), operation = RWCMD.LCD, payload = value, isRequest = true }; DebugEx.TraceLog("LCD: Send to python: " + msg); this.transport.Send2python(msg); }
//send mesg for processing to python public void Send2python(SharpPy data) { lock (this) { if (data.payload == null) { data.payload = String.Empty; } var csharp2pythonmessage = JsonConvert.SerializeObject(data); string timestamp = DateTime.Now.ToString(); //DebugEx.TraceLog("Send to python: " + csharp2pythonmessage); sw.WriteLine(csharp2pythonmessage); sw.WriteLine("\n"); } }
//------------------------------------------------------------------------------------------------------------------------ private void OnRxPythonMsg(SharpPy msg) { #if DEBUG DebugEx.TraceLog("OnRxPython " + msg.payload + ", syncid: " + msg.syncid + ", watcherid " + msg.watcherid); if (PendingRequests.Count != 0) { DebugEx.TraceLogInlineBegin("PENDING syncids: "); foreach (var item in PendingRequests.Keys) { DebugEx.TraceLogInline(item.ToString()); } DebugEx.TraceLogInlineEnd(""); } DebugEx.TraceLog("This watcherid:" + this.WatcherId); #endif if (msg.watcherid == this.WatcherId) { int syncId = msg.syncid; if (syncId == 0) { return; } Waiter w = null; w = PendingRequests.TryGetOrDefault(syncId); //set result and wake if (w != null) { lock (w) { w.response = msg.payload; Monitor.Pulse(w); } } else { DebugEx.TraceLog("w is null"); } } }
//------------------------------------------------------------------------------------------------------------------------ public object GetSingleValue <Req>(Req data) { var syncid = GetNewSyncId(); var w = new Waiter(); lock (PendingRequests) PendingRequests.Add(syncid, w); //construct sharppy msg SharpPy msg = new SharpPy() { isRequest = true, watcherid = WatcherId, syncid = syncid, pin = this.sensor.Pin.ToString(), operation = (data as SharpPy).operation, payload = (data as SharpPy).payload, }; lock (w) { this.sharppyiface.Send2python(msg); Monitor.Wait(w); } lock (PendingRequests) PendingRequests.Remove(syncid); if (w.response != null) { if (w.response != prevData && w.response != "255" && w.response != "65535") { prevData = w.response; DebugEx.TraceLog("CONT: wId:" + WatcherId + " sId:" + syncid + " response:" + w.response); return(this.sensor.DeserializePayload(w.response)); } //else // DebugEx.TraceLog("DROP: wId:" + WatcherId + " sId:" + syncid + " response:" + w.response); } return(null); }
//send mesg for processing to python public void Send2python(SharpPy data) { lock (this) { if (data.payload == null) data.payload = String.Empty; var csharp2pythonmessage = JsonConvert.SerializeObject(data); string timestamp = DateTime.Now.ToString(); //DebugEx.TraceLog("Send to python: " + csharp2pythonmessage); sw.WriteLine(csharp2pythonmessage); sw.WriteLine("\n"); } }