public async void ExecuteTDSThread(Object Obj) { SanwaTISThread ThreadObj = (SanwaTISThread)Obj; SanwaTIS sanwaTIS = ThreadObj._sanwaTIS; SanwaTDS sanwaTDS = new SanwaTDS { _trid = sanwaTIS._trid, _smpln = 0 }; while (!ThreadObj.isStopThread && sanwaTDS._smpln < sanwaTIS._totsmp) { //Data sample period Thread.Sleep(sanwaTIS._dsper); sanwaTDS._smpln++; ////運算次數累加 foreach (string svid in sanwaTIS._svIDList) { //_svList.TryGetValue(svid, out SanwaSV sanwaSV); SanwaSV sanwaSV = _svList.FirstOrDefault(x => x.Value._id == svid).Value; if (sanwaSV != null && sanwaSV._value != null) { SanwaSV svObj = new SanwaSV { _id = sanwaSV._id, _value = sanwaSV._value, _format = sanwaSV._format, _name = sanwaSV._name, _sVName = sanwaSV._sVName, _unit = sanwaSV._unit, }; sanwaTDS._svList.Add(svObj._id + "_" + sanwaTDS._smpln.ToString(), svObj); } } if (sanwaTDS._smpln % sanwaTIS._repgsz == 0) //不送出S6F1 { //時間 sanwaTDS._stime = GetDateTime(); //送出S6F1 if (!IsOfflineState()) { await SendS6F1Async(sanwaTDS); } //送出S6F1 sanwaTDS._svList.Clear(); } } sanwaTDS._svList.Clear(); //將從Thread List移除 if (!ThreadObj.isStopThread) { _tisThreadList.Remove(sanwaTIS._trid); } }
public async Task SendS6F1Async(SanwaTDS sanwaTDS) { _smlManager._messageList.TryGetValue("S6F1", out SanwaSML sanwaSML); if (sanwaSML != null) { SecsMessage secsMessage = new SecsMessage(6, 1, sanwaSML.MessageName); string newSendMsg = GetMessageName(secsMessage.ToSml()); newSendMsg += "< L[4]\r\n"; newSendMsg += "<U4[0]" + sanwaTDS._trid + ">\r\n"; newSendMsg += "<U4[0]" + sanwaTDS._smpln.ToString() + ">\r\n"; newSendMsg += "<A[0]" + sanwaTDS._stime + ">\r\n"; newSendMsg += "< L[" + sanwaTDS._svList.Count.ToString() + "]\r\n"; foreach (var PairKey in sanwaTDS._svList) { newSendMsg = RecursivelySV(PairKey.Value, newSendMsg); } newSendMsg += ">\r\n"; newSendMsg += ">"; _secsGem.SendAsync(newSendMsg.ToSecsMessage()); } }