// 主動回報事件 void VDTC_OnTCReport(object tc, TextPackage txt) { //throw new Exception("The method or operation is not implemented."); System.Data.DataSet ds=null; if (txt.Text[0] == 0x10) //cycle data { try { ds=m_protocol.GetReturnDsByTextPackage(txt); VD_MinAvgData data= getOneMinAvgData(ds); OneMinDataStore.inData(data); VD_MinAvgData fiveMinData = this.OneMinDataStore.getFiveMinMovingAvgData(); if (this.OnFiveMinAvgData != null) this.OnFiveMinAvgData(this, fiveMinData); ConsoleServer.WriteLine("Five min AVG:" + fiveMinData.ToString()); } catch (Exception ex) { ConsoleServer.WriteLine(ex.Message); } } else if(txt.Cmd==0x17) // 20 sec 事件資料 { ConsoleServer.WriteLine(txt.ToString()); try { ds = m_protocol.GetReturnDsByTextPackage(txt); //if (this.OnRealTimeData != null) // this.OnRealTimeData(this, ds); } catch (Exception ex) { ConsoleServer.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } } else if (txt.Cmd == 0x18) //現點速率 { ConsoleServer.WriteLine(txt.ToString()); try { ds = m_protocol.GetReturnDsByTextPackage(txt); if (this.OnRealTimeData != null) this.OnRealTimeData(this, ds); } catch (Exception ex) { ConsoleServer.WriteLine("現點速率:"+ex.Message + "\r\n" + ex.StackTrace); } } }
//public void RemoveCommMoniterRegist(TCBase tc) //{ // try // { // tc.m_device.OnAck -= new OnAckEventHandler(m_device_OnAck); // tc.m_device.OnBeforeAck -= new OnSendingAckNakHandler(m_device_OnBeforeAck); // tc.m_device.OnSendingPackage -= new OnSendPackgaeHandler(m_device_OnSendingPackage); // tc.m_device.OnReceiveText -= new OnTextPackageEventHandler(m_device_OnReceiveText); // tc.m_device.OnNak -= new OnNakEventHandler(m_device_OnNak); // } // catch { ;} //} void m_device_OnReceiveText(object sender, TextPackage txtObj) { try { this.notifier.NotifyAll(new NotifyEventObject(EventEnumType.MFCC_Comm_Moniter_Event, ((Comm.I_DLE)sender).getDeviceName(), "\t" + DateTime.Now.ToLongTimeString() + "," + txtObj.ToString() + "<==")); } catch (Exception ex){ ConsoleServer.WriteLine(ex.Message+","+ex.StackTrace); ;} //throw new Exception("The method or operation is not implemented."); }
private TextPackage ReadText() { int Seq=0,Address=0,Len=0,LRC=0,HeadLRC=0; byte[] text=null; TextPackage textPackage = new TextPackage(); Seq = ReadByte(stream); Address = ReadByte(stream) * 256; Address+= ReadByte(stream); Len = ReadByte(stream) * 256; Len += ReadByte(stream); HeadLRC = ReadByte(stream); textPackage.Seq = Seq; textPackage.Address = Address; // textPackage.LRC = HeadLRC; if (HeadLRC != (((Address >> 8) & 0x00ff) ^ (Address & 0x00ff) ^ ((Len >> 8) & 0x00ff) ^ (Len & 0x00ff))) { // textPackage.HasErrors = true; textPackage.SetErrBit(V2DLE.DLE_ERR_FRAME, true); textPackage.eErrorDescription += "Hearder LRC Error!\r\n"; //Console.WriteLine("Hearder LRC Error!"); return textPackage; } else { text = new byte[Len]; int rlen = 0; do { rlen+=stream.Read(text,rlen, Len-rlen); } while (rlen != Len); //for (int i = 0; i < Len; i++) // text[i] = (byte)stream.ReadByte(); //if (rlen != Len) // Console.WriteLine("rLen={0}!=len={1}",rlen,Len); LRC=DLE ^ SOH ^ Seq ; for (int i = 0; i < text.Length; i++) LRC ^= text[i]; int tmp = ReadByte(stream); if (LRC !=tmp)// stream.ReadByte()) { textPackage.SetErrBit(V2DLE.DLE_ERR_LCR, true); textPackage.eErrorDescription += "LRC Error!\r\n"; textPackage.Text = text; Console.WriteLine("LRC Error!"+"==>"+ textPackage.ToString()); return textPackage; } else { textPackage.Text=text; textPackage.LRC = LRC; return textPackage; } } }
void RDTC_OnTCReport(object tc, TextPackage txt) { // throw new Exception("The method or operation is not implemented."); try{ if (txt.Text[0] == 0x48 ) // cycle data 主動回報 { if (txt.Text.Length != 13) { ConsoleServer.WriteLine(this.DeviceName + "," + txt.ToString() + ",長度不符"); return; } System.DateTime dt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, txt.Text[6], txt.Text[7], txt.Text[8], 0); curr_amount = (txt.Text[9] == 255) ? -1 : txt.Text[9]; curr_acc_amount = (txt.Text[10] * 256 + txt.Text[11] == 65535) ? -1 : txt.Text[10] * 256 + txt.Text[11]; curr_degree = (txt.Text[12] == 255) ? -1 : txt.Text[12]; last_receive_time = dt; if (On_RD_FivceMinData != null) this.On_RD_FivceMinData(this, dt, curr_amount, curr_acc_amount, curr_degree,(txt.Text[1]==0)?1:0); } else if(txt.Text[0]==0x4a) { System.DateTime dt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, txt.Text[6], txt.Text[7], txt.Text[8], 0); if(this.On_DegreeChange!=null) On_DegreeChange(this, txt.Text[1],dt, txt.Text[9], txt.Text[10]); } } catch(Exception ex) { ConsoleServer.WriteLine(this.DeviceName+","+ex.Message); } // this.dbServer.SendSqlCmd(string.Format(sql, txt.Text[9], txt.Text[10] * 256 + txt.Text[11], txt.Text[12], tc.DeviceName, Comm.DB2.Db2.getTimeStampString(dt))); }
// 主動回報事件 void VDTC_OnTCReport(object tc, TextPackage txt) { System.Data.DataSet ds=null; if (txt.Text[0] == 0x10 ) //cycle data 1 min cycle { try { ds=m_protocol.GetSendDsByTextPackage(txt,CmdType.CmdReport); ds.AcceptChanges(); if (true/*System.Convert.ToInt32(ds.Tables[0].Rows[0]["response_type"]) == 0 || System.Convert.ToInt32(ds.Tables[0].Rows[0]["response_type"]) == 4*/) { VD_MinAvgData data = getOneMinAvgData(ds,System.DateTime.Now.Year,System.DateTime.Now.Month); curr_1_min_data = data; if (dtlast0x10 != data.dateTime) OneMinDataStore.inData(data); // if(dtlast0x10!=data.dateTime) VD_MinAvgData fiveMinData = this.OneMinDataStore.getFiveMinMovingAvgData(); if (this.OnFiveMinAvgData != null) try { this.OnFiveMinAvgData(this, fiveMinData); } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+ex.Message+ex.StackTrace); } if (this.On1MinTrafficData != null) try { if (dtlast0x10 != data.dateTime) this.On1MinTrafficData(this, data); else ConsoleServer.WriteLine(this.DeviceName+"1min data repeat!"); } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+ex.Message+ex.StackTrace); }; dtlast0x10 = data.dateTime; // 顯示取得最近1分鐘資料 // ConsoleServer.WriteLine(this.DeviceName + " " + "Five min AVG:" + fiveMinData.ToString()); } } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+" "+"Five min AVG"+ex.Message); } } else if(txt.Cmd==0x17) // 20 sec 事件資料 { // ConsoleServer.WriteLine(txt.ToString()); try { ds = m_protocol.GetSendDsByTextPackage(txt, CmdType.CmdReport); ds.AcceptChanges(); if (this.On20SecEvent != null) this.On20SecEvent(this, getOneMinAvgData(ds, System.DateTime.Now.Year, System.DateTime.Now.Month)); //if (this.OnRealTimeData != null) // this.OnRealTimeData(this, ds); } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+" "+" 20 sec 事件資料"+ex.Message + "\r\n" + ex.StackTrace); } } else if (txt.Cmd == 0x18) //現點速率 { try { ConsoleServer.WriteLine(txt.ToString()); if (System.DateTime.Now >= m_realEventEndTime) { ConsoleServer.WriteLine(this.DeviceName + "關閉現點速率"); //this.Tc_SetRealData(0); AsyncSend(new SendPackage(CmdType.CmdSet,CmdClass.B,0xffff,new byte[]{0x11,00})); return; } ds = m_protocol.GetSendDsByTextPackage(txt, CmdType.CmdReport); ds.AcceptChanges(); if (this.OnRealTimeData != null) this.OnRealTimeData(this, ds); } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+" "+"現點速率:"+ex.Message + "\r\n" + ex.StackTrace); } } else if (txt.Cmd == 0x1a) //觸動事件 { try { ds = m_protocol.GetSendDsByTextPackage(txt, CmdType.CmdReport); ds.AcceptChanges(); if (this.OnTriggerEvent != null) this.OnTriggerEvent(this, ds); } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+" "+"觸動事件:" + ex.Message + "\r\n" + ex.StackTrace); } } }