static void device_OnReceiveText(object sender, TextPackage txtObj) { double x = System.BitConverter.ToDouble(txtObj.Text, 0); double y = System.BitConverter.ToDouble(txtObj.Text, 8); double z= System.BitConverter.ToDouble(txtObj.Text, 16); Console.WriteLine("{0} {1} {2}", x, y, z); //throw new NotImplementedException(); }
public override sealed void OnReceiveText(TextPackage text) { if (text.Cmd == 0x28) DoGetPeriodData(text); else // pass to children OnSSHDDataController_ReceiveText(text); //throw new NotImplementedException(); }
private TextPackage ReadText() { int Seq=0,Address=0,Len=0,LRC=0;//,HeadLRC=0; byte[] text=null; TextPackage textPackage = new TextPackage(); Seq = stream.ReadByte(); Address = stream.ReadByte() * 256; Address+= stream.ReadByte(); Len = stream.ReadByte() * 256; Len += stream.ReadByte(); // HeadLRC = stream.ReadByte(); Len -= 10; textPackage.Seq = Seq; textPackage.Address = Address; //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(); stream.ReadByte(); //READ DLE stream.ReadByte(); // READ ETX LRC= STX ^ Seq ^ETX ^ (Len+10) /256 ^ (Len+10)%256 ; System.IO.MemoryStream ms = new System.IO.MemoryStream(); bool isDLE=false; for (int i = 0; i < text.Length; i++) { LRC ^= text[i]; if (text[i] != DLE) { ms.WriteByte(text[i]); isDLE = false; } else //double dle 處理 { if (isDLE) //2nd dle isDLE = false; else // 1st dle { isDLE = true; ms.WriteByte(text[i]); } } } int tmp = stream.ReadByte(); if (LRC !=tmp)// stream.ReadByte()) { textPackage.SetErrBit(TCDLE30.DLE_ERR_LCR, true); textPackage.eErrorDescription += "LRC Error!\r\n"; Console.WriteLine("LRC Error!"); return textPackage; } else { textPackage.Text=text; textPackage.LRC = LRC; return textPackage; } // } }
private bool IsModuleErr(TextPackage txt) { int msglength = 0, msginx = 0, msglenginx = 0; if (txt.Text[0] == 0x04 && txt.Text[7] == 0x57 && txt.Text[8] == 0) msglenginx = 9; else if (txt.Text[0] == 0x04 && txt.Text[7] == 0x5f && txt.Text[8] == 0x57 && (txt.Text[9] == 1 || txt.Text[9] == 4)) msglenginx = 12; else if (txt.Text[0] == 0x5b && txt.Text[8] == 0) msglenginx = 11; else if (txt.Text[0] == 0x5a && txt.Text[8] == 0) msglenginx = 9; if (msglenginx != 0) { msglength = txt.Text[msglenginx]; msginx = msglenginx + 1 + txt.Text[msglenginx + 1] + 2 + 1; for (int i = msginx; i < msginx + msglength; i++) if (txt.Text[i] == 0) return true; //throw new Exception("DisplayModuleError"); } return false; }
void CMSTC_OnTCReceiveText(object tc, TextPackage txt) { if (txt.Cmd == 0x56) { CMS_LedTest_Report(txt.Text, this.DeviceName); } //throw new Exception("The method or operation is not implemented."); }
CmdResult GetCmdResult(TextPackage pkg) { if (pkg.GetErrBit(V2DLE.DLE_ERR_LCR)) return CmdResult.LRC_ERR; else if (pkg.GetErrBit(V2DLE.DLE_ERR_FRAME)) return CmdResult.Frame_ERR; else if (pkg.GetErrBit(V2DLE.DLE_ERR_CMD_ERR)) return CmdResult.Cmd_Invalid; else if (pkg.GetErrBit(V2DLE.DLE_ERR_CMD_PARAM_OVERRANGE)) return CmdResult.Param_OverRange; else if (pkg.GetErrBit(V2DLE.DLE_ERR_CMD_FAIL)) return CmdResult.Cmd_Fail; else return CmdResult.Unknown; }
void m_device_OnReceiveText(object sender, TextPackage txtObj) { try { this.LastReceiveTime = System.DateTime.Now; this.IsTcpConnected = true; if (this.IsConnected == false) new System.Threading.Thread(new ParameterizedThreadStart(AsyncSetIsConnect)).Start(true); if (this.OnTCReceiveText != null) this.OnTCReceiveText(this, txtObj); } catch (Exception ex) { ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace); } }
public void m_device_OnReport(object sender, TextPackage txtObj) { try { if (txtObj == null) return; ReportQueue.Enqueue(txtObj); lock (ReportQueue) { System.Threading.Monitor.PulseAll(ReportQueue); } } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName + ex.Message + ex.StackTrace); ;} //throw new Exception("The method or operation is not implemented."); }
public System.Data.DataSet GetETTU_ReturnDsByTextPackage(TextPackage[] txt) { Cmd cmd; byte[] data = new byte[txt[0].ETTU_Text.Length + (txt[0].ETTU_Text.Length - 2) * (txt.Length - 1)]; // int inx = 0; for (int i = 0; i < txt.Length; i++) { if (i == 0) System.Array.Copy(txt[0].ETTU_Text, data, txt[0].ETTU_Text.Length); else System.Array.Copy(txt[i].ETTU_Text, 2, data, txt[0].ETTU_Text.Length + (i - 1) * (txt[0].ETTU_Text.Length - 2), txt[0].ETTU_Text.Length - 2); } cmd = getCmdByTextPackage(txt[0], CmdType.CmdQuery); if (cmd == null) { Console.WriteLine(txt.ToString() + "look up fail!"); return null; } TextPackage txtpkg = new TextPackage(); txtpkg.Text = data; return cmd.GetETTUReturnDsByTextPackage(txt.Length,txtpkg); }
public override void sensorDev_OnReceiveText(object sender, TextPackage txtObj) { if (txtObj.Text[0] == 0x02 && txtObj.Text[1] == 0x31) //eph data { UBIDBase idbase = new UBIDBase(txtObj.Text); if (++eph_cnt >= 32) eph_cnt = 32; if (idbase == null) return; eph_datas[idbase.svid - 1] = idbase; Console.WriteLine(this.SensorName+" svid:" + idbase.svid+" "+ idbase.IsValid); //if (idbase.IsValid) //{ // eph_datas[idbase.svid - 1] = idbase; // // double[] xyz=idbase.eph_xyz(0); // // Console.WriteLine("svid={0} x:{1} y:{2} z:{3} at t=0", idbase.svid,xyz[0], xyz[1], xyz[2]); //} //else // eph_datas[idbase.svid - 1] = null; } else if (txtObj.Text[0] == 0x01 && txtObj.Text[1] == 0x22) { //Console.WriteLine("01 22"); UBIDBase idbase = new UBIDBase(txtObj.Text); // Console.WriteLine("0x01 0x22, itow=" + System.Convert.ToInt32(idbase["itow"] / 1000.0)); idbase0122 = idbase; // Console.WriteLine(idbase0122.ToString()); } else if (txtObj.Text[0] == 0x02 && txtObj.Text[1] == 0x20) { UBIDBase idbase = new UBIDBase(txtObj.Text); // Console.WriteLine("0x02 0x20, itow=" + System.Convert.ToInt32(idbase["itow"] / 1000.0)); idbase0220 = idbase; PrepareGPSDataMatrix(); // Console.WriteLine(idbase0220.ToString()); } else if (txtObj.Text[0] == 0x02 && txtObj.Text[1] == 0x10) { UBIDBase idbase = new UBIDBase(txtObj.Text); idbase0210 = idbase; // Console.WriteLine("0x02 0x10, itow=" + System.Convert.ToInt32(idbase["itow"] / 1000.0)); // Console.WriteLine(idbase0210.ToString()); } else if (txtObj.Text[0] == 0x01 && txtObj.Text[1] == 0x32) { UBIDBase idbase = new UBIDBase(txtObj.Text); idbase0132 = idbase; // Console.WriteLine("0x01 0x32, itow=" + idbase.itow); // Console.WriteLine(idbase0132.ToString()); } else if (txtObj.Text[0] == 0x01 && txtObj.Text[1] == 0x01) { UBIDBase idbase = new UBIDBase(txtObj.Text); idbase0101 = idbase; // Console.WriteLine("0x01 0x01, itow=" + idbase.itow); } else if (txtObj.Text[0] == 0x02 && txtObj.Text[1] == 0x30) { // dummy } else { UBIDBase idbase = new UBIDBase(txtObj.Text); Console.WriteLine("unknow id {0:X4}", idbase.GetMessageID()); } }
//----------------------Read CDU private TextPackage ReadText() { System.IO.MemoryStream ms = new System.IO.MemoryStream(); byte data; TextPackage ret = new TextPackage(); while (true) { data =(byte) stream.ReadByte(); ms.WriteByte(data); if (data == 0xF8 || data == 0xC7) break; } byte[] databuff = ms.ToArray(); uint LCR = 0; byte lcr1, lcr2; for (int i = 0; i < databuff.Length - 3; i++) //cal lcr LCR += databuff[i]; LCR =(uint)( (~LCR) + 1); //2's complement lcr1 =(byte)( LCR & 0x0f); lcr2 =(byte)( (LCR >> 4) & 0x0f); ret.Text = new byte[databuff.Length - 3]; ret.CCU_EndCode = databuff[databuff.Length - 1]; System.Array.Copy(databuff, ret.Text, ret.Text.Length); if (!(lcr1 == databuff[databuff.Length - 2] && lcr2 == databuff[databuff.Length - 3])) { ret.SetErrBit((int)V2DLE.DLE_ERR_LCR,true); ret.eErrorDescription="LCR Error!"; ret.LRC =(byte)( (lcr2 << 4) | lcr1); } else { ret.LRC = (byte)LCR; } if(this.OnReceiveText!=null) this.OnReceiveText(this, ret); return ret; }
private void ProcessSC(TextPackage txt) { switch (txt.Text[0]*256+txt.Text[1]) { case 0x2020: //連線設定 WriteStream(CONNECT_AGREE); break; case 0x2121: //連線同意 ProcessDC(txt); break; case 0x2122: //離線設定 WriteStream(DISCONNECT_AGREE); break; case 0x2123: //離線同意 ProcessDC(txt); break; case 0xfefe: //重社要求 WriteStream(RESET_AGREE); break; case 0xffff: // 重設同意 ProcessDC(txt); break; } }
private void ProcessDC(TextPackage txt) { if (currentSendingPackage.type == CmdType.CmdQuery) { if (currentSendingPackage!=null && currentSendingPackage.ETTU_RetCmd == txt.Text[0] && currentSendingPackage.ETTU_RetSubCmd == txt.Text[1]) { currentSendingPackage.ETTU_ReturnList.Add(txt); currentSendingPackage.result = CmdResult.ACK; if (txt.CCU_EndCode == 0xc7) { lock (stream) { System.Threading.Monitor.Pulse(stream); } } } else { if (this.OnReport != null) this.OnReport(this, txt); } } }
private void ProcessCC(TextPackage txt) { switch (txt.Text[0] * 256 + txt.Text[1]) { case 0x2400: //reack this.currentRespObj = CmdResult.REACK; break; case 0x2401: //GOOD_C this.currentRespObj = CmdResult.GOOD_C; if (currentSendingPackage.type == CmdType.CmdQuery) return; break; case 0x2402: //GOOD_R this.currentRespObj = CmdResult.GOOD_R; break; case 0x2403: //resend1_c this.currentRespObj = CmdResult.RESEND1_C; break; case 0x2404: //resend1_r this.currentRespObj = CmdResult.RESEND1_R; break; case 0x2405: // resend2_c this.currentRespObj = CmdResult.RESEND2_C; break; case 0x2406: // resend2_r this.currentRespObj = CmdResult.RESEND2_R; break; case 0x2407: //resend3_c this.currentRespObj = CmdResult.RESEND3_C; break; case 0x2408://resend3_r this.currentRespObj = CmdResult.RESEND3_R; break; } lock (stream) { System.Threading.Monitor.Pulse(stream); } }
private bool IsSC(TextPackage txt) { if (txt.Text[0] == 0x20 || txt.Text[0] == 0x21 || txt.Text[0] == 0x22 || txt.Text[0] == 0x23 || txt.Text[0] == 0xfe || txt.Text[0] == 0xff) return true; else return false; }
void RGSTC_OnTCReport(object tc, TextPackage txt) { #if DEBUG //if (this.DeviceName != "RGS-N1-S-203.7") // return; #endif if (txt.Text[0] == 0x90) { RGS_GenericDisplay_Data data= RGS30_Extend.GetGenericDisplayData(txt.Text); if (curr_display_data == null && data.mode == 0 && data.graph_code_id == 0) return; this.InvokeOutPutWrongEvent((curr_display_data==null)?"熄滅":curr_display_data.ToString(), data.ToString()); } //throw new Exception("The method or operation is not implemented."); }
public RGS_SetBackgroundPic_frame(TextPackage txt) { if (txt.Cmd != 0x97 && txt.Cmd != 0x98) throw new Exception("wrong cmd package,0x97,0x98 are required"); mode = txt.Text[1]; g_code_id = txt.Text[2]; frame_no = txt.Text[3]; frame_id = txt.Text[4]; g_width =(ushort)( txt.Text[5] * 256 + txt.Text[6]); g_height =(ushort)(txt.Text[7] * 256 + txt.Text[8]); Array.Copy(txt.Text, 9, g_desc, 0, 32); g_pattern_color = new byte[txt.Text.Length - 41]; Array.Copy(txt.Text, 41, g_pattern_color, 0,g_pattern_color.Length); }
public System.Data.DataSet GetETTU_SendDsByReportTextPackage(TextPackage txtpkg) { Cmd cmd; TextPackage txt = new TextPackage(); txt.Text = txtpkg.ETTU_Text; txt.Seq = txtpkg.Seq; txt.Err = txtpkg.Err; txt.Address = txtpkg.Address; //if (txt.Cmd == 0x04) // cmd = getCmd((byte)txt.Cmd, txt.Text[1], cmdtype); //else // cmd = getCmd((byte)txt.Cmd, (txt.Cmd == 0x0f) ? txt.Text[1] : (byte)0xff, cmdtype); cmd = getCmdByTextPackage(txt, CmdType.CmdReport); if (cmd == null) return null; else return cmd.GetSendDsByTextPackage(txt); }
void DoReport(TextPackage txtObj) { if (!this.IsEnable) return; byte[] diff = new byte[4]; bool IsOpmodeChanged=false,IsOpstatusChanged=false; if (txtObj == null) return; try { if (this.m_protocol.DeviceType == "SCM") { if (txtObj.Text[0] == 0x0f && txtObj.Text[1] == 0x04) //硬體狀態主動回報 { for (int i = 0; i < 2; i++) diff[i] = (byte)(txtObj.Text[2 +i] ^ m_hwstaus[i]); System.Array.Copy(txtObj.Text, 2, m_hwstaus, 0, 2); if (this.OnHwStatusChanged != null && (diff[0] + diff[1] + diff[2] + diff[3] != 0)) { hw_statuscnt++; if (hw_statuscnt <= 5) this.OnHwStatusChanged(this, diff, m_opmode, m_opstatus); } } } else if (txtObj.Cmd == 0x0a && txtObj.Text.Length == 5 || txtObj.Cmd == 0x01 && txtObj.Text.Length == 5 || txtObj.Cmd==0x0b) { if (txtObj.Cmd == 0x0b) { if(m_opmode!=txtObj.Text[7]) { IsOpmodeChanged=true; m_opmode = txtObj.Text[7]; } if (m_opstatus != txtObj.Text[6]) { m_opstatus = txtObj.Text[6]; IsOpstatusChanged = true; } } for (int i = 0; i < 4; i++) diff[i] = (byte)(txtObj.Text[i + 1] ^ m_hwstaus[i]); System.Array.Copy(txtObj.Text, 1, m_hwstaus, 0, 4); if (IsOpmodeChanged && this.OnOpModeChanged != null) this.OnOpModeChanged(this, m_opmode); if (IsOpstatusChanged && this.OnOpStatusChanged != null) this.OnOpStatusChanged(this, m_opstatus); if (this.OnHwStatusChanged != null && (diff[0] + diff[1] + diff[2] + diff[3] != 0)) { hw_statuscnt++; if(hw_statuscnt<=2) this.OnHwStatusChanged(this, diff, m_opmode, m_opstatus); } } } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+":"+ex.Message + "\n" + ex.StackTrace); } try { if (this.OnTCReport != null) { // Console.WriteLine("<OnReport>" + txtObj.ToString()); this.OnTCReport(this, txtObj); } } catch (Exception ex) { ConsoleServer.WriteLine(this.DeviceName+ex.Message+ex.StackTrace); } }
public System.Data.DataSet GetReturnDsByTextPackage(TextPackage txt) { Cmd cmd; //if (txt.Cmd == 0x04) // cmd = getCmd((byte)txt.Cmd, txt.Text[1], CmdType.CmdQuery); //else // cmd = getCmd((byte)txt.Cmd, (txt.Cmd == 0x0f) ? txt.Text[1] : (byte)0xff, CmdType.CmdQuery); cmd = getCmdByTextPackage(txt, CmdType.CmdQuery); if (cmd == null) { Console.WriteLine(txt.ToString() + "look up fail!"); return null; } else return cmd.GetReturnDsByTextPackage(txt); }
private TextPackage ReadText() { int len,devid; TextPackage txt = new TextPackage(); // devid = stream.ReadByte(); len = stream.ReadByte()*256+stream.ReadByte(); txt.Text = new byte[len]; int rlen = 0; txt.Address = 0; ; // devid; do { rlen += stream.Read(txt.Text, rlen, len - rlen); } while (rlen != len); int cks = 0; foreach (byte d in txt.Text) cks += d; cks &=0x7fff; int tempcks = stream.ReadByte() * 256 + stream.ReadByte(); if (cks != tempcks/*stream.ReadByte()*256+stream.ReadByte()*/) { txt.SetErrBit(SirfDLE.DLE_ERR_LCR, true); txt.eErrorDescription += getDeviceName() + "LRC Error!\r\n"; } return txt; // throw new NotImplementedException(); }
public System.Data.DataSet GetSendDsByTextPackage(TextPackage txt,CmdType cmdtype) { Cmd cmd ; //if (txt.Cmd == 0x04) // cmd = getCmd((byte)txt.Cmd, txt.Text[1], cmdtype); //else // cmd = getCmd((byte)txt.Cmd, (txt.Cmd == 0x0f) ? txt.Text[1] : (byte)0xff, cmdtype); cmd = getCmdByTextPackage(txt, cmdtype); if (cmd == null) return null; else return cmd.GetSendDsByTextPackage(txt); }
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; } } }
//just for receive // 查詢命令專用 ,主動回報 private Cmd getCmdByTextPackage(TextPackage txt,CmdType cmdtype) { Cmd cmd; byte code; switch (txt.Cmd) { case 0x04: code = txt.Text[7]; if ((code & 0x0f) != 0x0f) cmd = getCmd((byte)txt.Cmd, txt.Text[7], cmdtype); else cmd = getCmd((byte)txt.Cmd, txt.Text[7], txt.Text[8], cmdtype); break; case 0x52: if (txt.Text.Length == 2) cmd = getCmd((byte)txt.Cmd, (txt.Cmd == 0x0f) ? txt.Text[1] : (byte)0xff, cmdtype); else cmd = getCmd((byte)txt.Cmd, 0x01, cmdtype); break; case 0xb6: if (txt.Text.Length == 2) cmd = getCmd((byte)txt.Cmd, 0xff, cmdtype); else cmd = getCmd((byte)txt.Cmd, 1, cmdtype); break; case 0x5f: // mas 5f 22 if (txt.SubCmd==0x22) { if (txt.Text.Length == 4) cmd= getCmd((byte)txt.Cmd, 0x22, cmdtype); else cmd = getCmd((byte)txt.Cmd, 0xfe, cmdtype); } else if (txt.SubCmd == 0x12) //tts { if(txt.Text.Length==4) cmd = getCmd((byte)txt.Cmd, 0x12, cmdtype); else cmd = getCmd((byte)txt.Cmd, 0xfe, cmdtype); } else goto default; break; case 0xAD: if(txt.Text.Length==3) cmd = getCmd((byte)txt.Cmd, (byte)0xff, cmdtype); else cmd = getCmd((byte)txt.Cmd, 0x01, cmdtype); break; case 0xdf: if (txt.Text[1] == 0xd2 && txt.Text.Length == 3) cmd = getCmd((byte)txt.Cmd, txt.Text[1], 0x01, cmdtype); //else if (txt.Text[1] == 0xd5) //{ // if (txt.Text[10] == 0) //txt // cmd = getCmd((byte)txt.Cmd, txt.Text[1],(byte) 0x01, CmdType.CmdQuery); // else // cmd = getCmd((byte)txt.Cmd, txt.Text[1], CmdType.CmdQuery); // // if((this.findCmditem(this.ReturnCmdItems,"data_type").Min!=0 )) //graphic,or default msg // // return V2DLE.ToHexString(new byte[] { cmd, subCmd, 0x01 }).Replace(' ', '_') + this.cmdType; // //else // // return V2DLE.ToHexString(new byte[] { cmd, subCmd }).Replace(' ', '_') + this.cmdType; //} else goto default; break; default: if (this.DeviceType != "ETTU") cmd = getCmd((byte)txt.Cmd, ((txt.Cmd & 0x0f) == 0x0f) ? txt.Text[1] : (byte)0xff, cmdtype); else cmd = getCmd((byte)txt.ETTU_Cmd, txt.ETTU_SubCmd, cmdtype); break; } return cmd; }
void CMSTC_OnTCReport(object tc, TextPackage txt) { #if DEBUG #endif try { if (txt.Cmd == 0x5a || txt.Cmd == 0x5b) { if (this.currentDispalyDataset == null) return; if (IsModuleErr(txt)) { ConsoleServer.WriteLine(DeviceName + "," + "顯示模組錯誤!"); return; } System.Data.DataSet ds = this.m_protocol.GetSendDsByTextPackage(txt, CmdType.CmdReport); //Console.WriteLine(GetDisplayDesc(ds)); //Console.WriteLine(GetDisplayDesc(currentDispalyDataset)); if (ds != null && !IsEqualToCurrentDisplay(ds)) { ConsoleServer.WriteLine(this.DeviceName + "," + Util.ToHexString((byte)txt.Cmd) + ",顯示資料比對錯誤!"); //if (txt.Cmd == 0x5b) this.InvokeOutPutWrongEvent(GetCurrentDisplayDecs(), GetDisplayDesc(ds)); } else { this.InvokeOutPutWrongEvent(GetCurrentDisplayDecs(), GetCurrentDisplayDecs()); } } } catch (Exception ex) { ConsoleServer.WriteLine("in CmsTCOnReport:ex.Message"+ "," + ex.StackTrace); } }
static void dev_OnReceiveText(object sender, TextPackage txtObj) { try { if (txtObj.Text[0] == 0x02 && txtObj.Text[1] == 0x30 || txtObj.Text[0] == 0x02 && txtObj.Text[1] == 0x31) { // Console.WriteLine("[" + string.Format("{0:X2}", txtObj.Text[0]) + " " + string.Format("{0:X2}", txtObj.Text[1]) + "],"+txtObj.Text.Length); // Console.WriteLine(V2DLE.ToHexString(txtObj.Text)); UBIDBase idbase = new GPSDevice.GPSMessage.UBIDBase(txtObj.Text); Console.WriteLine(idbase.ToString()); if (Matrix != null) { int svid =(int) idbase[1]; if (idbase.GetMessageID() == 0x0230) //alm { //for (int i = 0; i < 8; i++) // Matrix[svid - 1, i] = (uint)idbase[3 + i]; Matrix[svid - 1, 0] = idbase.alm_Eccentricity; Matrix[svid - 1, 1] = idbase.alm_toa; Matrix[svid - 1, 2] = idbase.alm_delti; Matrix[svid - 1, 3] = idbase.alm_omegadot; Matrix[svid - 1, 4] = idbase.alm_sqrtA; Matrix[svid - 1, 5] = idbase.alm_omega0; Matrix[svid - 1, 6] = idbase.alm_w; Matrix[svid - 1, 7] = idbase.alm_mean0; Matrix[svid - 1, 8] = idbase.alm_af0; Matrix[svid - 1, 9] = idbase.alm_af1; Console.WriteLine("Eccentricity=" + idbase.alm_Eccentricity); Console.WriteLine("toa=" + idbase.alm_toa); Console.WriteLine("delti=" + idbase.alm_delti); Console.WriteLine("omegadot=" + idbase.alm_omegadot); Console.WriteLine("sqrtA=" + idbase.alm_sqrtA); Console.WriteLine("omega0=" + idbase.alm_omega0); Console.WriteLine("w=" + idbase.alm_w); Console.WriteLine("mean0=" + idbase.alm_mean0); Console.WriteLine("af0=" + idbase.alm_af0); Console.WriteLine("af1=" + idbase.alm_af1); Console.WriteLine("============================="); } if (idbase.GetMessageID() == 0x0231) //eph { //for (int i = 0; i < 24; i++) //{ // fill eph here //Matrix[svid - 1, 8 + i] = (uint)idbase[3 + i]; Matrix[svid-1,10]=idbase.eph_toc; Matrix[svid - 1, 11] = idbase.eph_af2; Matrix[svid - 1, 12] = idbase.eph_af1; Matrix[svid - 1, 13] = idbase.eph_af0; Matrix[svid - 1, 14] = idbase.eph_crs; Matrix[svid - 1, 15] = idbase.eph_deltan; Matrix[svid - 1, 16] = idbase.eph_m0; Matrix[svid - 1, 17] = idbase.eph_cuc; Matrix[svid - 1, 18] = idbase.eph_e; Matrix[svid - 1, 19] = idbase.eph_cus; Matrix[svid - 1, 20] = idbase.eph_sqrtA; Matrix[svid - 1, 21] = idbase.eph_toe; Matrix[svid - 1, 22] = idbase.eph_cic; Matrix[svid - 1, 23] = idbase.eph_w0; Matrix[svid - 1, 24] = idbase.eph_cis; Matrix[svid - 1, 25] = idbase.eph_i0; Matrix[svid - 1, 26] = idbase.eph_crc; Matrix[svid - 1, 27] = idbase.eph_w; Matrix[svid - 1, 28] = idbase.eph_wdot; Matrix[svid - 1, 29] = idbase.eph_idot; Console.WriteLine("eph_toc="+ idbase.eph_toc); Console.WriteLine("eph_af2=" + idbase.eph_af2); Console.WriteLine("eph_af1=" + idbase.eph_af1); Console.WriteLine("eph_af0=" + idbase.eph_af0); Console.WriteLine("eph_crs=" + idbase.eph_crs); Console.WriteLine("eph_deltan=" + idbase.eph_deltan); Console.WriteLine("eph_m0=" + idbase.eph_m0); Console.WriteLine("eph_cuc=" + idbase.eph_cuc); Console.WriteLine("eph_e=" + idbase.eph_e); Console.WriteLine("eph_cus=" + idbase.eph_cus); Console.WriteLine("eph_sqrtA=" + idbase.eph_sqrtA); Console.WriteLine("eph_toe=" + idbase.eph_toe); Console.WriteLine("eph_cic=" + idbase.eph_cic); Console.WriteLine("eph_w0=" + idbase.eph_w0); Console.WriteLine("eph_cis=" + idbase.eph_cis); Console.WriteLine("eph_i0=" + idbase.eph_i0); Console.WriteLine("eph_crc=" + idbase.eph_crc); Console.WriteLine("eph_w=" + idbase.eph_w); Console.WriteLine("eph_wdot=" + idbase.eph_wdot); Console.WriteLine("eph_idot=" + idbase.eph_idot); double[] xyz = idbase.eph_xyz(0); Console.WriteLine("x:{0} y:{1} z:{2}", xyz[0], xyz[1], xyz[2]); Console.WriteLine("============================="); if (!idbase.IsValid) for (int j = 0; j < 10; j++) Matrix[svid - 1, j] = 0; //} if (svid == 32) // print matrix { string str = "[\r\n"; for (int row = 0; row < 32; row++) { for (int col = 0; col < 30 ; col++) // for alm only str+=Matrix[row, col] + ","; str = str.TrimEnd(",".ToCharArray())+";" + "\r\n"; } str = str.TrimEnd(",".ToCharArray()) + "]\r\n"; Console.Write(str); System.IO.File.AppendAllText("log.txt", str); //Write File Here Console.WriteLine(); } } } if (idbase.GetMessageID() == 0x0231 && (int)idbase[1] == 32) Matrix = new double[32, 30]; } } catch (Exception ex) { Console.WriteLine(ex.Message + "," + ex.StackTrace); } //throw new NotImplementedException(); }
CmdResult GetCmdResult(TextPackage pkg) { if (pkg.GetErrBit(TCDLE30.DLE_ERR_ADDR_ERR)) return CmdResult.TC_DLE_30_ADDR_ERR; else if (pkg.GetErrBit(TCDLE30.DLE_ERR_FRAME)) return CmdResult.Frame_ERR; else if (pkg.GetErrBit(TCDLE30.DLE_ERR_LCR)) return CmdResult.LRC_ERR; else if (pkg.GetErrBit(TCDLE30.DLE_ERRR_LEN_ERR)) return CmdResult.TC_DEL_30_LEN_ERR; else return CmdResult.Unknown; }
public override void sensorDev_OnReceiveText(object sender, TextPackage txtObj) { throw new NotImplementedException(); }
public override void sensorDev_OnReceiveText(object sender, TextPackage txtObj) { // throw new NotImplementedException(); double value1,value2,temperature,orgvalue1,orgvalue2; //volt1 = (txtObj.Text[0] + txtObj.Text[1] * 256 + txtObj.Text[2] * 256 * 256) / Math.Pow(2, 24) * 5; //volt2 = (txtObj.Text[3] + txtObj.Text[4] * 256 + txtObj.Text[5] * 256 * 256) / Math.Pow(2, 24) * 5; //double temp1, temp2; //temp1 = (txtObj.Text[0] - 197.0) / -1.083; ; //temp2 = (txtObj.Text[1] - 197.0) / -1.083; ; //volt1 = Comm.Util.ThreeBytesToInt(new byte[] { txtObj.Text[0], txtObj.Text[1], txtObj.Text[2] }) / Math.Pow(2, 24) * 4.2 * 2; //volt2 = Comm.Util.ThreeBytesToInt(new byte[] { txtObj.Text[3], txtObj.Text[4], txtObj.Text[5] }) / Math.Pow(2, 24) * 4.2 * 2; //volt1 = Comm.Util.ThreeBytesToInt(new byte[] { txtObj.Text[2], txtObj.Text[3], txtObj.Text[4] }) / Math.Pow(2, 24) * 4.2 * 2; //volt2 = Comm.Util.ThreeBytesToInt(new byte[] { txtObj.Text[5], txtObj.Text[6], txtObj.Text[7] }) / Math.Pow(2, 24) * 4.2 * 2; //value1 = volt1 / 0.28; //value2 =volt2 / 0.28; orgvalue1=value1 = System.BitConverter.ToInt32(txtObj.Text, 0) / 1e6; orgvalue2=value2 = System.BitConverter.ToInt32(txtObj.Text, 4) / 1e6; temperature = (txtObj.Text[8] - 197.0) / -1.083; string formula = this.controller.config.sensors[ID].sensor_values[0].ConvertFormula; try { value1 = System.Convert.ToDouble(Eval.JScriptEvaluate(string.Format(formula, value1, value2, temperature), jseng)); } catch (Exception ex) { Console.WriteLine("snrid:" + ID + "valueinx:0" + ex.Message + "," + ex.StackTrace + string.Format(formula, value1, value2, temperature)); return; } formula = this.controller.config.sensors[ID].sensor_values[1].ConvertFormula; try{ value2 = System.Convert.ToDouble(Eval.JScriptEvaluate(string.Format(formula, value1, value2, temperature), jseng)); } catch(Exception ex) { Console.WriteLine("snrid:"+ID+"valueinx:1"+ex.Message+","+ex.StackTrace+ string.Format(formula, value1, value2, temperature)); return; } // object res = Eval.JScriptEvaluate("var a=10;a+2*6+5;Math.sin(0);", eng); SetDataToQueue(new double[] { value1, value2,temperature }); Console.WriteLine(this.SensorName + ":" + "X:{0:0.0000} Y:{1:0.0000} temperature1:{2:0.0000} OrgX:{3:0.0000} OrgY:{4:0.0000} ", value1, value2, temperature,orgvalue1,orgvalue2); #if DEBUG //if (readcnt++ % 100 == 0) //{ //System.IO.StreamWriter sw; //if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "log.csv")) // sw = System.IO.File.CreateText(AppDomain.CurrentDomain.BaseDirectory + "log.csv"); //else // sw = System.IO.File.AppendText(AppDomain.CurrentDomain.BaseDirectory + "log.csv"); //sw.WriteLine(volt1 + "," + temp1 + "," + volt2 + "," + temp2); //sw.Flush(); //sw.Close(); //Console.WriteLine(this.SensorName + ":" + " Volt1:{0:0.0000}/{2:0.0000} Volt2:{1:00.0000}/{3:00.0000} temperature1:{4:00.0000} temperature2:{5:00.0000}", volt1, volt2, volt1 / 0.28, volt2 / .28, temp1, temp2); //} #endif }
void m_device_OnReceiveText(object sender, TextPackage txtObj) { // Console.WriteLine(txtObj.ToString()); //throw new Exception("The method or operation is not implemented."); }