/// <summary> /// 获得添加校验码后的结果 /// </summary> /// <param name="msg"></param> /// <returns></returns> public byte[] GetCRCByte(byte[] msg) { byte[] b = new byte[msg.Length + 2]; msg.CopyTo(b, 0); CRCMethod.ToModbusCRC16Byte(msg).CopyTo(b, msg.Length); return(b); }
/// <summary> /// 接收字节数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Client_DatagramReceived(object sender, TcpDatagramReceivedEventArgs <byte[]> e) { //_master.UpdateDevceBData(Name, e.Datagram); if (CRCMethod.CheckCRC(e.Datagram)) { Bdata = e.Datagram; UpDateTime = DateTime.Now; log.LOG("R:" + CRCMethod.AllByteToString(e.Datagram)); } else { log.LOG("RN:" + CRCMethod.AllByteToString(e.Datagram)); } }
/// <summary> /// 向指定设备发送信息 /// </summary> /// <param name="name"></param> /// <param name="order"></param> public bool SendToClient(string name, string order, out string result) { return(SendToClient(name, CRCMethod.StringToHexByte(order), out result)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="text"></param> internal void Send(byte[] msg) { client.Send(msg); log.LOG("S:" + CRCMethod.AllByteToString(msg)); }