public void CheckCommTestButton() { lock (this) Invoke(new MethodInvoker(delegate() { PLCControlObj obj = new PLCControlObj(0, 1000, 1, 1000, 1, 1000, 1, 1000); CommObj commObj = new CommObj(); commObj.SrcId = 0x10; commObj.DestId = 0x30; commObj.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); commObj.DataType = "PLCControlObj"; commObj.DataCmd = ""; commObj.DataBody = PLCControlObj.ToByteJson(obj); string json = CommObj.ToJson(commObj); int N = 20; for (int i = 0; i < N; i++) { visComm.SendToServer(json); Thread.Sleep(1000); } })); }
// 定时发送消息到服务端 private void timer1_Tick(object sender, EventArgs e) { if (allTimerCount % 20 == 0) { this.timer1.Enabled = false; } allTimerCount++; PLCControlObj obj = new PLCControlObj(0, 500, 0, 0, 0, 0, 0, 0); CommObj commObj = new CommObj(); commObj.SrcId = 0x10; commObj.DestId = 0x30; commObj.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); commObj.DataType = "PLCControlObj"; commObj.DataCmd = ""; commObj.DataBody = PLCControlObj.ToByteJson(obj); string json = CommObj.ToJson(commObj); visComm.SendToServer(json); // visComm.SendToServer(json); visLog.DisplaySendToServerInfo(json); }
public void ToByteJsonTest() { PLCControlObj obj = new PLCControlObj(0, 1000, 1, 200, 0, 300, 0, 1000); Assert.IsTrue(obj != null); string json1 = PLCControlObj.ToByteJson(obj); }