日期:2014-05-17 浏览次数:21199 次
void comm1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
int n = comm.BytesToRead;
byte[] buf = new byte[n];
comm.Read(buf, 0, n);
buffer.AddRange(buf);
if (buffer.Count==9)
{
byte[] binary_data_1 = new byte[9];
byte[] binary_crc=new byte [7];
buffer.CopyTo(0, binary_data_1, 0, 9);
buffer.CopyTo(0, binary_crc, 0, 7);
buffer.Clear();
modbus mb = new modbus();
if (mb.CRC16(binary_crc)[0] == binary_data_1[8] && mb.CRC16(binary_crc)[1] == binary_data_1[7])
{