void WaitingStart(object LockWatingThread) { while (true) { TcpModbusPacket tp = form1.ReadPLC(); if (tp != null) { ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]); if (BytesOP.GetBit(D100, 0))//系统已经启动 { form1.SetMotor(motorRev, motorTorque); this.Invoke((EventHandler)(delegate { chart1.Series[0].Points.Clear(); waitTimer.Enabled = true; })); return; } } Thread.Sleep(1000); lock (LockWatingThread) { wpStart.SetProcessBarPerformStep(); if (wpStart.HasBeenCancelled()) { return; } } } }
private void waitTimer_Tick(object sender, EventArgs e) { form1.ReadDeweData(); this.Invoke((EventHandler)(delegate { chart1.Series[0].Points.AddY(form1.deweNiuZhen); chart2.Series[0].Points.AddY(form1.deweNiuJu); chart2.Series[1].Points.AddY(Torque); chart2.Series[2].Points.AddY(motorTorque); })); t = t + waitTimer.Interval / 1000; motorTorque = Torque + Amplitude * Math.Sin(omega * t); form1.SetMotor(motorRev, motorTorque); TcpModbusPacket tp = form1.ReadPLC(); if (tp != null) { ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]); if (!BytesOP.GetBit(D100, 0))//系统外部停机 { MessageBox.Show("测试停止"); this.Invoke((EventHandler)(delegate { waitTimer.Enabled = false; toolStripButton1.Enabled = true; })); } } }
private void waitTimer_Tick(object sender, EventArgs e) { form1.ReadDeweRev(); this.Invoke((EventHandler)(delegate { double d = form1.deweRev; chart1.Series[0].Points.AddY(d); lRev.Text = d.ToString("f1"); })); TcpModbusPacket tp = form1.ReadPLC(); if (tp != null) { ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]); if (!BytesOP.GetBit(D100, 0))//系统外部停机 { MessageBox.Show("测试停止"); this.Invoke((EventHandler)(delegate { waitTimer.Enabled = false; toolStripButton1.Enabled = true; })); } } }
void checkPLC() { TcpModbusPacket tp = ReadPLC(); if (tp != null) { ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]); if (!BytesOP.GetBit(D100, 0))//系统外部停机 { this.Invoke((EventHandler)(delegate { openTimer.Enabled = false; waitTimer.Enabled = false; splitContainer1.Enabled = false; toolStripButton4.Enabled = true; listView1.BackColor = SystemColors.Window; listView2.BackColor = SystemColors.Window; tbTime1.Visible = false; tbTime.Visible = false; timer1.Enabled = false; })); MessageBox.Show("测试停止"); } } }
void GetGQTable(CurveData cd, DataTable dt) { DataRow dr = dt.NewRow(); for (int i = 0; i < 101; i++) { dr = dt.NewRow(); if (BytesOP.GetBit(cd.exWorkTepy, 2))//自动,则0.5V { if (i % 2 == 1) { continue; } dr["GQ"] = ((float)i) / 2; } else { dr["GQ"] = i; } //dr["BC"] = "L1=" + (10 + 5.23).ToString(); if (cd.bGQExist[0] && i < cd.GQDataCount[0]) { dr["工作电流1mA"] = cd.GQData[0, i]; } if (cd.bGQExist[1] && i < cd.GQDataCount[1]) { dr["工作电流2mA"] = cd.GQData[1, i]; } if (cd.bGQExist[2] && i < cd.GQDataCount[2]) { dr["工作电流4mA"] = cd.GQData[2, i]; } if (cd.bGQExist[3] && i < cd.GQDataCount[3]) { dr["工作电流5mA"] = cd.GQData[3, i]; } if (cd.bGQExist[0] && ((i + 1) == cd.GQDataCount[0])) { dr["L1"] = cd.GQData[0, i]; } if (cd.bGQExist[1] && ((i + 1) == cd.GQDataCount[1])) { dr["L2"] = cd.GQData[1, i]; } if (cd.bGQExist[2] && ((i + 1) == cd.GQDataCount[2])) { dr["L3"] = cd.GQData[2, i]; } if (cd.bGQExist[3] && ((i + 1) == cd.GQDataCount[3])) { dr["L4"] = cd.GQData[3, i]; } dt.Rows.Add(dr); } }
void WaitingStart(object LockWatingThread) { while (true) { TcpModbusPacket tp = ReadPLC(); if (tp != null) { ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]); if (BytesOP.GetBit(D100, 0)) //系统已经启动 { if (BytesOP.GetBit(D100, 1)) //判断正反转 { bForeward = true; this.Invoke((EventHandler)(delegate { listView1.Items[6].SubItems[1].Text = "正转"; })); } else { bForeward = false; this.Invoke((EventHandler)(delegate { listView1.Items[6].SubItems[1].Text = "反转"; })); } SetMotor(openRev, NiuJuPID.sp); motorRev = openRev; motorTorque = NiuJuPID.sp; this.Invoke((EventHandler)(delegate { listView1.Items[6].SubItems[1].Text = openRev.ToString("F3"); listView2.Items[6].SubItems[1].Text = NiuJuPID.sp.ToString(); listView1.Items[1].SubItems[1].Text = ""; listView2.Items[1].SubItems[1].Text = ""; chart1.Series[0].Points.Clear(); chart1.Series[1].Points.Clear(); chart2.Series[0].Points.Clear(); chart2.Series[1].Points.Clear(); openTimes = 0; openTimer.Enabled = true; })); return; } } Thread.Sleep(1000); lock (LockWatingThread) { wpStart.SetProcessBarPerformStep(); if (wpStart.HasBeenCancelled()) { return; } } } }
static void ShiftFshKey() { FlashAddr = 0X2074; R0X41 = ReadFshData(R0XC1); if (R0X41 != 0) { for (; ;) { // asm("BANKSEL _A.R0XAB"); // asm("RRCF _A.R0XAB, F, B"); // asm("RRCF _A.R0XAC, F, B"); // asm("RRCF _A.R0XAD, F, B"); // asm("RRCF _A.R0XAE, F, B "); ulR0XAB >>= 1; BytesOP.ClrBit(ref ulR0XAB, 7); if (BytesOP.GetBit(ulR0XAB, 27)) { BytesOP.SetBit(ref ulR0XAB, 7); } ; // asm("BANKSEL _A.R0XAF"); // asm("RRCF _A.R0XAF, F, B"); // asm("RRCF _A.R0XB0, F, B"); // asm("RRCF _A.R0XB1, F, B"); // asm("RRCF _A.R0XB2, F, B"); ulR0XAF >>= 1; BytesOP.ClrBit(ref ulR0XAF, 7); if (BytesOP.GetBit(ulR0XAF, 27)) { BytesOP.SetBit(ref ulR0XAF, 7); } ; R0X41--; if (R0X41 == 0) { break; } } } R0XBB = 0XAB; R0XBC = 0XB3; R0X52 = 0X7F; R0X53 = 0X3F; BytesOP.SetBit(ref R0XCB, 6); GetFshKey(); }
static void ShiftMixKey() { byte t; int p0; R0XBD = 0XE0; for (; ;) { FlashAddr = 0X1F74; p0 = R0XBB; t = RAMBUF[p0 - 0x83]; t = (byte)((t >> 1) | R0XBD); R0X52 = ReadFshData(t); t = RAMBUF[p0 - 0x83]; if ((t & 1) == 0) { R0X52 = (byte)(R0X52 >> 4); } R0X52 &= 0XF; p0 = R0XBC; if (!BytesOP.GetBit(R0XBD, 5)) { R0XBC++; t = RAMBUF[p0 - 0x83]; t <<= 4; R0X52 |= t; } RAMBUF[p0 - 0x83] = R0X52; R0XBB++; t = R0XBD; R0XBD = (byte)(R0XBD - 0X20); //if (CARRY==0) break; if (t < 0x20) { break; } } }
public EZSData(byte[] pBuf) { SSID = new byte[4]; PSW = new byte[8]; Key0 = new byte[8]; Key1 = new byte[8]; Key2 = new byte[8]; Key3 = new byte[8]; Key4 = new byte[8]; Key5 = new byte[8]; Key6 = new byte[8]; Key7 = new byte[8]; SerialNum = new byte[8]; Dealer = new byte[8]; Transport = new byte[8]; for (int i = 0; i < 4; i++) { SSID[i] = pBuf[0x0BE + i]; } int BaseAddress = 0x1ac - 0x12; for (int i = 0; i < 8; i++) { Dealer[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key0[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key1[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key2[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key3[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key4[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key5[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key6[i] = pBuf[BaseAddress + i]; } BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Key7[i] = pBuf[BaseAddress + i]; } //BaseAddress += 0x12; for (int i = 0; i < 8; i++) { Transport[i] = pBuf[0xa6 + i]; } for (int i = 0; i < 8; i++) { SerialNum[i] = pBuf[0xb6 + i]; } for (int i = 0; i < 8; i++) { PSW[i] = pBuf[0x8e + i]; } byte KeyStatus1, KeyStatus2; KeyStatus1 = 0; //pBuf[4]; KeyStatus2 = 0; //pBuf[6]; if (BytesOP.GetBit(KeyStatus1, 7)) { Key0Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 7)) { Key0Status = KeyStatus.NoUsed; } else { Key0Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 6)) { Key1Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 6)) { Key1Status = KeyStatus.NoUsed; } else { Key1Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 5)) { Key2Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 5)) { Key2Status = KeyStatus.NoUsed; } else { Key2Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 4)) { Key3Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 4)) { Key3Status = KeyStatus.NoUsed; } else { Key3Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 3)) { Key4Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 3)) { Key4Status = KeyStatus.NoUsed; } else { Key4Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 2)) { Key5Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 2)) { Key5Status = KeyStatus.NoUsed; } else { Key5Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 1)) { Key6Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 1)) { Key6Status = KeyStatus.NoUsed; } else { Key6Status = KeyStatus.Used; } } if (BytesOP.GetBit(KeyStatus1, 0)) { Key7Status = KeyStatus.Lock; } else { if (BytesOP.GetBit(KeyStatus2, 0)) { Key7Status = KeyStatus.NoUsed; } else { Key7Status = KeyStatus.Used; } } Status = pBuf[0x080];; if (BytesOP.GetBit(Status, 0)) { bInitialised = true; } else { bInitialised = false; } if (BytesOP.GetBit(Status, 1)) { bTPremoved = true; } else { bTPremoved = false; } if (BytesOP.GetBit(Status, 2)) { bPersonalised = true; } else { bPersonalised = false; } if (BytesOP.GetBit(Status, 3)) { bActivated = true; } else { bActivated = false; } //byte usedkey = BytesOP.MakeByte(BytesOP.GetLowNibble(pBuf[0x0DA + 8]), BytesOP.GetLowNibble(pBuf[0x0D8 + 8])); LastKey = BytesOP.GetLowNibble(pBuf[0xd8 + 8]); PreviousKey = BytesOP.GetHighNibble(pBuf[0xda + 8]); }
public void SetAllData(byte[] pBuf, int len) { AllFile = new byte[len]; Array.Copy(pBuf, AllFile, len); Array.Copy(pBuf, 0, SSID, 0, 4); Array.Copy(pBuf, 0x0270, Key0, 0, 8); Array.Copy(pBuf, 0x0280, Key1, 0, 8); Array.Copy(pBuf, 0x0290, Key2, 0, 8); Array.Copy(pBuf, 0x02a0, Key3, 0, 8); Array.Copy(pBuf, 0x02b0, Key4, 0, 8); Array.Copy(pBuf, 0x02c0, Key5, 0, 8); Array.Copy(pBuf, 0x02d0, Key6, 0, 8); Array.Copy(pBuf, 0x02e0, Key7, 0, 8); Array.Copy(pBuf, 0x0230, SerialNum, 0, 8); Array.Copy(pBuf, 0x10, Dealer, 0, 8); Array.Copy(pBuf, 0x0260, Transport, 0, 8); if (BytesOP.GetBit(pBuf[4], 7)) { Key0Status = KeyStatus.Lock; } else { Key0Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 6)) { Key1Status = KeyStatus.Lock; } else { Key1Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 5)) { Key2Status = KeyStatus.Lock; } else { Key2Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 4)) { Key3Status = KeyStatus.Lock; } else { Key3Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 3)) { Key4Status = KeyStatus.Lock; } else { Key4Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 2)) { Key5Status = KeyStatus.Lock; } else { Key5Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 1)) { Key6Status = KeyStatus.Lock; } else { Key6Status = KeyStatus.Used; } if (BytesOP.GetBit(pBuf[4], 0)) { Key7Status = KeyStatus.Lock; } else { Key7Status = KeyStatus.Used; } bInitialised = BytesOP.GetBit(pBuf[5], 0); bTPremoved = BytesOP.GetBit(pBuf[5], 1); bPersonalised = BytesOP.GetBit(pBuf[5], 2); bActivated = BytesOP.GetBit(pBuf[5], 3); LastKey = BytesOP.GetLowNibble(pBuf[7]); PreviousKey = BytesOP.GetHighNibble(pBuf[7]); }
void GetVATable(CurveData cd, DataTable dt) { DataRow dr = dt.NewRow(); for (int i = 0; i < 101; i++) { dr = dt.NewRow(); if (BytesOP.GetBit(cd.exWorkTepy, 0))//自动,则0.5V { if (i % 2 == 1) { continue; } dr["GQ"] = ((float)i) / 2; } else { dr["GQ"] = i; } //dr["BC"] = "L1=" + (10 + 5.23).ToString(); if (cd.bVAExist[0] && i < cd.VADataCount[0]) { dr["紫光400nm"] = cd.VAData[0, i]; } if (cd.bVAExist[1] && i < cd.VADataCount[1]) { dr["蓝光460nm"] = cd.VAData[1, i]; } if (cd.bVAExist[2] && i < cd.VADataCount[2]) { dr["绿光520nm"] = cd.VAData[2, i]; } if (cd.bVAExist[3] && i < cd.VADataCount[3]) { dr["黄光590nm"] = cd.VAData[3, i]; } if (cd.bVAExist[4] && i < cd.VADataCount[4]) { dr["橙光603nm"] = cd.VAData[4, i]; } if (cd.bVAExist[5] && i < cd.VADataCount[5]) { dr["红光625nm"] = cd.VAData[5, i]; } if (cd.bVAExist[0] && ((i + 1) == cd.VADataCount[0])) { dr["L1"] = cd.VAData[0, i]; } if (cd.bVAExist[1] && ((i + 1) == cd.VADataCount[1])) { dr["L2"] = cd.VAData[1, i]; } if (cd.bVAExist[2] && ((i + 1) == cd.VADataCount[2])) { dr["L3"] = cd.VAData[2, i]; } if (cd.bVAExist[3] && ((i + 1) == cd.VADataCount[3])) { dr["L4"] = cd.VAData[3, i]; } if (cd.bVAExist[4] && ((i + 1) == cd.VADataCount[4])) { dr["L5"] = cd.VAData[4, i]; } if (cd.bVAExist[5] && ((i + 1) == cd.VADataCount[5])) { dr["L6"] = cd.VAData[5, i]; } dt.Rows.Add(dr); } }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(mcuSocketIP.Address)) if (mcuClientContext != null && e.Client == mcuClientContext) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x01) { double f; byte[] fb = new byte[4]; int fbIndex; string str; bool bSave = false; DateTime dt = DateTime.Now; //温度 f = BytesOP.MakeShort(rx.Data[0], rx.Data[1]); f = f / 100; listView1.Items[0].SubItems[1].Text = f.ToString("F2"); string filePT; filePT = System.Windows.Forms.Application.StartupPath + "\\TextLog\\PT" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[0].SubItems[1].Text, filePT, false); //电子罗盘 fbIndex = 2; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[1].SubItems[1].Text = f.ToString("F2"); fbIndex = 6; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[2].SubItems[1].Text = f.ToString("F2"); fbIndex = 10; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[3].SubItems[1].Text = f.ToString("F2"); string fileTC; fileTC = System.Windows.Forms.Application.StartupPath + "\\TextLog\\TC" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[1].SubItems[1].Text + " " + listView1.Items[2].SubItems[1].Text + " " + listView1.Items[3].SubItems[1].Text, fileTC, false); //授时 str = Encoding.UTF8.GetString(rx.Data, 14, 10); listView1.Items[4].SubItems[1].Text = str; str = Encoding.UTF8.GetString(rx.Data, 24, 6); listView1.Items[5].SubItems[1].Text = str; //MS8607 f = BitConverter.ToSingle(rx.Data, 30); listView1.Items[6].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 34); listView1.Items[7].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 38); listView1.Items[8].SubItems[1].Text = f.ToString("F2"); string fileMS; fileMS = System.Windows.Forms.Application.StartupPath + "\\TextLog\\MS" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[6].SubItems[1].Text + " " + listView1.Items[7].SubItems[1].Text + " " + listView1.Items[8].SubItems[1].Text, fileMS, false); //光源 f = BytesOP.MakeShort(rx.Data[44], rx.Data[45]); f = f / 10; rioCur = f; listView1.Items[14].SubItems[1].Text = f.ToString("F1"); ushort rioStatus = BytesOP.MakeShort(rx.Data[42], rx.Data[43]); listView1.Items[15].SubItems[1].Text = rioStatus.ToString("X04"); if (BytesOP.GetBit(rioStatus, 0)) { listView1.Items[16].SubItems[1].Text = "是"; listView1.Items[16].BackColor = Color.Lime; } else { listView1.Items[16].SubItems[1].Text = "否"; listView1.Items[16].BackColor = Color.Red; } if (BytesOP.GetBit(rioStatus, 6)) { listView1.Items[17].SubItems[1].Text = "是"; listView1.Items[17].BackColor = Color.Red; } else { listView1.Items[17].SubItems[1].Text = "否"; listView1.Items[17].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 7)) { listView1.Items[18].SubItems[1].Text = "是"; listView1.Items[18].BackColor = Color.Red; } else { listView1.Items[18].SubItems[1].Text = "否"; listView1.Items[18].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 11))//当前为新数据,需要存储 { string fileLA; fileLA = System.Windows.Forms.Application.StartupPath + "\\TextLog\\LA" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[14].SubItems[1].Text + " " + listView1.Items[15].SubItems[1].Text, fileLA, false); } //通信错误帧统计 listView1.Items[9].SubItems[1].Text = rx.Data[46].ToString(); if (rx.Data[46] > 5) { bSave = true; listView1.Items[9].BackColor = Color.Red; } else { listView1.Items[9].BackColor = SystemColors.Window; } listView1.Items[10].SubItems[1].Text = rx.Data[47].ToString(); if (rx.Data[47] > 5) { bSave = true; listView1.Items[10].BackColor = Color.Red; } else { listView1.Items[10].BackColor = SystemColors.Window; } listView1.Items[11].SubItems[1].Text = rx.Data[48].ToString(); if (rx.Data[48] > 5) { bSave = true; listView1.Items[11].BackColor = Color.Red; } else { listView1.Items[11].BackColor = SystemColors.Window; } listView1.Items[12].SubItems[1].Text = rx.Data[49].ToString(); if (rx.Data[49] > 5) { bSave = true; listView1.Items[12].BackColor = Color.Red; } else { listView1.Items[12].BackColor = SystemColors.Window; } listView1.Items[13].SubItems[1].Text = rx.Data[50].ToString(); if (rx.Data[50] > 5) { bSave = true; listView1.Items[13].BackColor = Color.Red; } else { listView1.Items[13].BackColor = SystemColors.Window; } listView1.Items[19].SubItems[1].Text = rx.Data[51].ToString(); //漏水1 listView1.Items[20].SubItems[1].Text = rx.Data[52].ToString(); //漏水2 listView1.Items[21].SubItems[1].Text = rx.Data[53].ToString(); //备用IO1 listView1.Items[22].SubItems[1].Text = rx.Data[54].ToString(); //备用IO1 listView1.Items[23].SubItems[1].Text = rx.Data[55].ToString(); //备用IO1 listView1.Items[24].SubItems[1].Text = rx.Data[56].ToString(); //备用IO1 listView1.Items[25].SubItems[1].Text = rx.Data[57].ToString(); //备用IO1 listView1.Items[26].SubItems[1].Text = rx.Data[58].ToString(); //备用IO1 for (int i = 0; i < 6; i++) { bIO[i] = rx.Data[53 + i]; } if (rx.Data[59] == 0) { listView1.Items[27].SubItems[1].Text = "打开"; bPower1 = true; } else { listView1.Items[27].SubItems[1].Text = "关闭"; bPower1 = false; } if (rx.Data[60] == 0) { listView1.Items[28].SubItems[1].Text = "打开"; bPower2 = true; } else { listView1.Items[28].SubItems[1].Text = "关闭"; bPower2 = false; } if (bSave) { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); NetLog("\r\n"); } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } } else if (rx.Header.Command == 0x08)//读取光源状态 { timer2.Enabled = false; toolStrip1.Enabled = true; timer1.Enabled = true; textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到手动读取光源数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); if (rx.Header.Len == 0)//读取失败 { MessageBox.Show("读取光源状态失败,请稍后重试!!"); } else { //光源 double f; f = BytesOP.MakeShort(rx.Data[2], rx.Data[3]); f = f / 10; rioCur = f; listView1.Items[14].SubItems[1].Text = f.ToString("F1"); ushort rioStatus = BytesOP.MakeShort(rx.Data[0], rx.Data[1]); listView1.Items[15].SubItems[1].Text = rioStatus.ToString("X04"); if (BytesOP.GetBit(rioStatus, 0)) { listView1.Items[16].SubItems[1].Text = "是"; listView1.Items[16].BackColor = Color.Lime; } else { listView1.Items[16].SubItems[1].Text = "否"; listView1.Items[16].BackColor = Color.Red; } if (BytesOP.GetBit(rioStatus, 6)) { listView1.Items[17].SubItems[1].Text = "是"; listView1.Items[17].BackColor = Color.Red; } else { listView1.Items[17].SubItems[1].Text = "否"; listView1.Items[17].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 7)) { listView1.Items[18].SubItems[1].Text = "是"; listView1.Items[18].BackColor = Color.Red; } else { listView1.Items[18].SubItems[1].Text = "否"; listView1.Items[18].BackColor = Color.Lime; } DateTime dt = DateTime.Now; string fileLA; fileLA = System.Windows.Forms.Application.StartupPath + "\\TextLog\\LA" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[14].SubItems[1].Text + " " + listView1.Items[15].SubItems[1].Text, fileLA, false); } } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } })); } else { this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText("\r\n"); CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0xf0) { if (rx.Data[0] == 0x01) //传感器采集板接入 { toolStripButton2.Enabled = true; toolStripButton3.Enabled = true; mcuClientContext = e.Client; //mcuSocketIP.Port = ip.Port; this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("单片机采集板接入"); NetLog("\r\n"); })); } } })); } }
public static void KeyDataWorkThread() { int retryMax = 10; int retry = retryMax; iniFileOP.iniFilePath = "c:\\LCY.ini"; while (true) { bCalc = false; autoResetEvent.WaitOne(); bCalc = true; while (true) { bool bOK = false; KeyDataQueueData eq = KeyDataQueueDataDBOption.GetFirst(); if (eq == null) { break; } KeyDataWorkLogData kl = new KeyDataWorkLogData(); kl.IP = eq.IP; kl.DeviceID = eq.DeviceID; kl.sTime = eq.sTime; kl.SSID = eq.SSID; try { byte[] data = WFNetLib.StringFunc.StringsFunction.strToHexByte(eq.BIN, ""); string folder = "e:\\mb2\\" + eq.SSID; if (WFNetLib.FileOP.IsExist(folder, FileOPMethod.Folder)) { WFNetLib.FileOP.Delete(folder, FileOPMethod.Folder); } GetST12(data); uint keyoption = (uint)eq.KeyOption; for (int i = 0; i < 8; i++) { if (BytesOP.GetBit(keyoption, i)) { iniFileOP.Write("DuoXuan", i.ToString(), "1"); } else { iniFileOP.Write("DuoXuan", i.ToString(), "0"); } } if (BytesOP.GetBit(keyoption, 8)) { iniFileOP.Write("DuoXuan", "all", "1"); } else { iniFileOP.Write("DuoXuan", "all".ToString(), "0"); } iniFileOP.Write("KaiGuan", "KG", "1"); retry = 60; bool bStart = false; while (retry != 0) { Thread.Sleep(1000); retry--; try { int kg = int.Parse(iniFileOP.Read("KaiGuan", "KG")); if (kg == 2) { bStart = true; break; } } catch { } } if (bStart) { retry = 5 * 60; bool bFinish = false; while (retry != 0) { Thread.Sleep(1000); retry--; try { int kg = int.Parse(iniFileOP.Read("KaiGuan", "KG")); if (kg == 3) { bFinish = true; break; } } catch { } } if (bFinish) { if (WFNetLib.FileOP.IsExist(folder, FileOPMethod.Folder)) { byte format = (byte)eq.format; string filename; if (BytesOP.GetBit(format, 0))//11格式 { if (BytesOP.GetBit(keyoption, 0)) { FileInfo f; filename = folder + "\\key_0_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key0_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 1)) { FileInfo f; filename = folder + "\\key_1_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key1_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 2)) { FileInfo f; filename = folder + "\\key_2_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key2_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 3)) { FileInfo f; filename = folder + "\\key_3_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key3_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 4)) { FileInfo f; filename = folder + "\\key_4_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key4_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 5)) { FileInfo f; filename = folder + "\\key_5_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key5_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 6)) { FileInfo f; filename = folder + "\\key_6_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key6_11 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 7)) { FileInfo f; filename = folder + "\\key_7_" + eq.SSID + "_11.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key7_11 = StringsFunction.byteToHexStr(bin, ""); } } if (BytesOP.GetBit(format, 1))//41格式 { if (BytesOP.GetBit(keyoption, 0)) { FileInfo f; filename = folder + "\\key_0_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key0_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 1)) { FileInfo f; filename = folder + "\\key_1_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key1_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 2)) { FileInfo f; filename = folder + "\\key_2_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key2_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 3)) { FileInfo f; filename = folder + "\\key_3_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key3_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 4)) { FileInfo f; filename = folder + "\\key_4_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key4_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 5)) { FileInfo f; filename = folder + "\\key_5_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key5_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 6)) { FileInfo f; filename = folder + "\\key_6_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key6_41 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 7)) { FileInfo f; filename = folder + "\\key_7_" + eq.SSID + "_41.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key7_41 = StringsFunction.byteToHexStr(bin, ""); } } if (BytesOP.GetBit(format, 2))//51格式 { if (BytesOP.GetBit(keyoption, 0)) { FileInfo f; filename = folder + "\\key_0_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key0_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 1)) { FileInfo f; filename = folder + "\\key_1_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key1_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 2)) { FileInfo f; filename = folder + "\\key_2_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key2_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 3)) { FileInfo f; filename = folder + "\\key_3_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key3_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 4)) { FileInfo f; filename = folder + "\\key_4_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key4_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 5)) { FileInfo f; filename = folder + "\\key_5_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key5_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 6)) { FileInfo f; filename = folder + "\\key_6_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key6_51 = StringsFunction.byteToHexStr(bin, ""); } if (BytesOP.GetBit(keyoption, 7)) { FileInfo f; filename = folder + "\\key_7_" + eq.SSID + "_51.bin"; f = new FileInfo(filename); Stream stream = File.OpenRead(f.FullName); byte[] bin = new byte[stream.Length]; stream.Read(bin, 0, (int)stream.Length); stream.Close(); kl.Key7_51 = StringsFunction.byteToHexStr(bin, ""); } } kl.bOK = true; KeyDataWorkLogDataDBOption.Insert(kl); //WFNetLib.FileOP.Delete(folder, FileOPMethod.Folder); } else { kl.bOK = false; KeyDataWorkLogDataDBOption.Insert(kl); } } else { kl.bOK = false; KeyDataWorkLogDataDBOption.Insert(kl); } } else { kl.bOK = false; KeyDataWorkLogDataDBOption.Insert(kl); } KeyDataQueueDataDBOption.delete(eq); } catch// (System.Exception ex) { kl.bOK = false; KeyDataWorkLogDataDBOption.Insert(kl); KeyDataQueueDataDBOption.delete(eq); } } } }
void CH368IntProc() { byte[] readHeaderList = new byte[7]; byte[] readDataList = new byte[0x100]; byte read = 0; /************************************************************************/ /* 读ram */ /************************************************************************/ //拉低片选 if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, 0xb0) == 0) { MessageBox.Show("1"); return; } //读7个字节,判断是否为有效帧 // CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr, readList, 64); // this.Invoke((EventHandler)(delegate { textBox1.Text = StringsFunction.byteToHexStr(readList, 0, (int)64, " "); })); //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, (int)9, " ")); if (CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr, readHeaderList, 7) == 0) { MessageBox.Show("2"); return; } if (bLog) { this.Invoke((EventHandler)(delegate { try { textBox1.AppendText(DateTime.Now.ToString() + ":"); textBox1.AppendText(StringsFunction.byteToHexStr(readHeaderList, 0, 7, " ")); } catch { } })); //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, 7, " ")); } if (readHeaderList[0] == 0xfa && readHeaderList[1] == 0xf3 && readHeaderList[2] == 0x30) { //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, 7, " ")); uint readDataLen = readHeaderList[6];// BytesOP.MakeShort(readHeaderList[5], readHeaderList[6]); if (CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr + 7, readDataList, readDataLen) == 0) { MessageBox.Show("3"); return; } if (bLog) { string str = StringsFunction.byteToHexStr(readDataList, 0, (int)readDataLen, " "); try { this.Invoke((EventHandler)(delegate { textBox1.AppendText(str); })); } catch { } } if (readHeaderList[3] == 0xe0 || readHeaderList[3] == 0xe2) { MeasureE0Data e0 = new MeasureE0Data(); e0.Source = readHeaderList[3]; Fuction.AnalyzeE0Data(ref e0, readDataList, readDataLen); e0.Time = DateTime.Now; MeasureE0DataDBOption.Insert(e0); } else if (readHeaderList[3] == 0xe1 || readHeaderList[3] == 0xe3) { MeasureE1Data e1 = new MeasureE1Data(); e1.Source = readHeaderList[3]; Fuction.AnalyzeE1Data(ref e1, readDataList, readDataLen); e1.Time = DateTime.Now; MeasureE1DataDBOption.Insert(e1); } //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, (int)len, " ")); } if (bLog) { this.Invoke((EventHandler)(delegate { try { // bLog = false; // timerLog.Enabled = true; textBox1.AppendText("\r\n"); } catch { } })); } //拉高片选 if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, 0xb1) == 0) { MessageBox.Show("4"); return; } /************************************************************************/ /* 完成读取,告知单片机 */ /************************************************************************/ //拉低SCS,表示在处理完成 if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, 0x03) == 0) { MessageBox.Show("5"); return; } //等待单片机退出通信流程 while (true) { if (CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xf8, ref read) == 0) { MessageBox.Show("10"); return; } if (BytesOP.GetBit(read, 3)) { break; } } //SCS 高电平 if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, 0x07) == 0) { MessageBox.Show("12"); return; } }
static void GetFshKey() { byte t; int p0, p1; R0XBD = R0X52; R0XBE = R0X53; for (; ;) { R0X40 = R0XBE; R0X40 = (byte)((R0X40 >> 3) & 0X1F); t = (byte)(R0XBC + R0X40); p0 = t; FlashAddr = 0x1E14; if (BytesOP.GetBit(R0XCB, 6)) { FlashAddr = 0X1EF4; } R0X41 = ReadFshData(R0XBD); if ((R0X41 & 0x80) == 0) { R0XC0 = (byte)(R0X41 & 0X7); FlashAddr = 0X1E14; if (BytesOP.GetBit(R0XCB, 6)) { FlashAddr = 0X1EF4; } R0X40 = ReadFshData(R0XBD); R0X40 = (byte)((R0X40 >> 3) & 0x1F); // 去掉了高三位,即去掉了循环右移影响 t = (byte)(R0XBB + R0X40); p1 = t; FlashAddr = 0X2084; t = ReadFshData(R0XC0);//(A.R0XC0); t = (byte)(t & (RAMBUF[p1 - 0x83])); if (t != 0) { t = 0x80; } } else { t = 0x80; } RAMBUF[p0 - 0x83] = (byte)(((RAMBUF[p0 - 0x83]) >> 1) | t); R0XBD--; R0XBE--; if ((R0XBE & 0X80) != 0) { break; } } }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(mcuSocketIP.Address)) if (mcuClientContext != null && e.Client == mcuClientContext) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x01) { double f; byte[] fb = new byte[4]; int fbIndex; string str; bool bSave = false; //温度 f = BytesOP.MakeShort(rx.Data[0], rx.Data[1]); f = f / 100; listView1.Items[0].SubItems[1].Text = f.ToString("F2"); //电子罗盘 fbIndex = 2; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[1].SubItems[1].Text = f.ToString("F2"); fbIndex = 6; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[2].SubItems[1].Text = f.ToString("F2"); fbIndex = 10; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[3].SubItems[1].Text = f.ToString("F2"); //授时 str = Encoding.UTF8.GetString(rx.Data, 14, 10); listView1.Items[4].SubItems[1].Text = str; str = Encoding.UTF8.GetString(rx.Data, 24, 6); listView1.Items[5].SubItems[1].Text = str; //MS8607 f = BitConverter.ToSingle(rx.Data, 30); listView1.Items[6].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 34); listView1.Items[7].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 38); listView1.Items[8].SubItems[1].Text = f.ToString("F2"); //光源 f = BytesOP.MakeShort(rx.Data[44], rx.Data[45]); f = f / 10; rioCur = f; listView1.Items[14].SubItems[1].Text = f.ToString("F1"); ushort rioStatus = BytesOP.MakeShort(rx.Data[42], rx.Data[43]); listView1.Items[15].SubItems[1].Text = rioStatus.ToString("X04"); if (BytesOP.GetBit(rioStatus, 0)) { listView1.Items[16].SubItems[1].Text = "是"; listView1.Items[16].BackColor = Color.Lime; } else { listView1.Items[16].SubItems[1].Text = "否"; listView1.Items[16].BackColor = Color.Red; } if (BytesOP.GetBit(rioStatus, 6)) { listView1.Items[17].SubItems[1].Text = "是"; listView1.Items[17].BackColor = Color.Red; } else { listView1.Items[17].SubItems[1].Text = "否"; listView1.Items[17].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 7)) { listView1.Items[18].SubItems[1].Text = "是"; listView1.Items[18].BackColor = Color.Red; } else { listView1.Items[18].SubItems[1].Text = "否"; listView1.Items[18].BackColor = Color.Lime; } //通信错误帧统计 listView1.Items[9].SubItems[1].Text = rx.Data[46].ToString(); if (rx.Data[46] > 5) { bSave = true; listView1.Items[9].BackColor = Color.Red; } else { listView1.Items[9].BackColor = SystemColors.Window; } listView1.Items[10].SubItems[1].Text = rx.Data[47].ToString(); if (rx.Data[47] > 5) { bSave = true; listView1.Items[10].BackColor = Color.Red; } else { listView1.Items[10].BackColor = SystemColors.Window; } listView1.Items[11].SubItems[1].Text = rx.Data[48].ToString(); if (rx.Data[48] > 5) { bSave = true; listView1.Items[11].BackColor = Color.Red; } else { listView1.Items[11].BackColor = SystemColors.Window; } listView1.Items[12].SubItems[1].Text = rx.Data[49].ToString(); if (rx.Data[49] > 5) { bSave = true; listView1.Items[12].BackColor = Color.Red; } else { listView1.Items[12].BackColor = SystemColors.Window; } listView1.Items[13].SubItems[1].Text = rx.Data[50].ToString(); if (rx.Data[50] > 5) { bSave = true; listView1.Items[13].BackColor = Color.Red; } else { listView1.Items[13].BackColor = SystemColors.Window; } listView1.Items[19].SubItems[1].Text = rx.Data[51].ToString(); //漏水1 listView1.Items[20].SubItems[1].Text = rx.Data[52].ToString(); //漏水2 listView1.Items[21].SubItems[1].Text = rx.Data[53].ToString(); //备用IO1 listView1.Items[22].SubItems[1].Text = rx.Data[54].ToString(); //备用IO1 listView1.Items[23].SubItems[1].Text = rx.Data[55].ToString(); //备用IO1 listView1.Items[24].SubItems[1].Text = rx.Data[56].ToString(); //备用IO1 listView1.Items[25].SubItems[1].Text = rx.Data[57].ToString(); //备用IO1 listView1.Items[26].SubItems[1].Text = rx.Data[58].ToString(); //备用IO1 for (int i = 0; i < 6; i++) { bIO[i] = rx.Data[53 + i]; } if (rx.Data[59] == 0) { listView1.Items[27].SubItems[1].Text = "打开"; bPower1 = true; } else { listView1.Items[27].SubItems[1].Text = "关闭"; bPower1 = false; } if (rx.Data[60] == 0) { listView1.Items[28].SubItems[1].Text = "打开"; bPower2 = true; } else { listView1.Items[28].SubItems[1].Text = "关闭"; bPower2 = false; } if (bSave) { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); NetLog("\r\n"); } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } })); } else { this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText("\r\n"); CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0xf0) { if (rx.Data[0] == 0x01) //传感器采集板接入 { mcuClientContext = e.Client; //mcuSocketIP.Port = ip.Port; this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("单片机采集板接入"); NetLog("\r\n"); })); } } })); } }