public void ProcessBroadCastingInfo(CommObj commObj) { // 视觉端发送,PLC端接收 if (commObj.SrcId == 0x10 && commObj.DestId == 0x30) { if (commObj.DataType.Equals("PLCControlObj")) { PLCControlObj plcControlObj = PLCControlObj.FromByteJson(commObj.DataBody); SendToPLC(PLCControlObj.ToBytes(plcControlObj)); allSendCount++; } } }
public void ToBytesTest() { PLCControlObj obj = new PLCControlObj(0, 1000, 1, 200, 0, 300, 0, 1000); Assert.IsTrue(obj != null); Byte[] bytes = PLCControlObj.ToBytes(obj); Assert.AreEqual(bytes[0], 0); Assert.AreEqual(bytes[1], 0); Assert.AreEqual(bytes[2], 0x03); Assert.AreEqual(bytes[3], 0xe8); Assert.AreEqual(bytes[4], 0); Assert.AreEqual(bytes[5], 1); Assert.AreEqual(bytes[6], 0); Assert.AreEqual(bytes[7], 0xc8); Assert.AreEqual(bytes[8], 0); Assert.AreEqual(bytes[9], 0); Assert.AreEqual(bytes[10], 0x01); Assert.AreEqual(bytes[11], 0x2c); Assert.AreEqual(bytes[12], 0); Assert.AreEqual(bytes[13], 0); Assert.AreEqual(bytes[14], 0x03); Assert.AreEqual(bytes[15], 0xe8); }