private void btnMbSend_Click(object sender, EventArgs e) { var sd = ModBus.HexStrToHexByte(txtMbData.Text.Trim());//开 _serverSocket.Send(sd, sd.Length, 0); ShowMsg("已发送:" + txtMbData.Text.Trim()); }
private static string WriteRead(string hexdata, Socket serverSocket) { byte[] recByte = new byte[1024]; var sd = ModBus.HexStrToHexByte(hexdata);//开 serverSocket.Send(sd, sd.Length, 0); int bytes = serverSocket.Receive(recByte, recByte.Length, 0); var rcvbt1 = new byte[bytes]; Array.Copy(recByte, 0, rcvbt1, 0, bytes); var rst = ModBus.HexByteToHexStr(rcvbt1); var s = rst.Replace("7777772E7573722E636E", ""); if (s == "")//排除第一个空 { bytes = serverSocket.Receive(recByte, recByte.Length, 0); rcvbt1 = new byte[bytes]; Array.Copy(recByte, 0, rcvbt1, 0, bytes); rst = ModBus.HexByteToHexStr(rcvbt1); s = rst.Replace("7777772E7573722E636E", ""); } return(s); }