发表于:2004-05-31 11:47:00
2楼
我用c写了一段代码,不知道有无用处,用网上下的modbus软件能够收到数据
unsigned char Com1OutBuf[StrSize]={0};
Com1OutBuf[0] = 0x01; //地址01
Com1OutBuf[1] = 0x03; //功能号03
Com1OutBuf[2] = 0x09; //9个数据
Com1OutBuf[4] = a[0]&0xff; //第一个数据
Com1OutBuf[3] = a[0]>>8;
Com1OutBuf[6] = a[1]&0xff;
Com1OutBuf[5] = a[1]>>8;
Com1OutBuf[8] = a[2]&0xff;
Com1OutBuf[7] = a[2]>>8;
Com1OutBuf[10] = a[3]&0xff;
Com1OutBuf[9] = a[3]>>8;
Com1OutBuf[12] = a[4]&0xff;
Com1OutBuf[11] = a[4]>>8;
Com1OutBuf[14] = a[5]&0xff;
Com1OutBuf[13] = a[5]>>8;
Com1OutBuf[16] = a[6]&0xff;
Com1OutBuf[15] = a[6]>>8;
Com1OutBuf[18] = a[7]&0xff;
Com1OutBuf[17] = a[7]>>8;
Com1OutBuf[20] = a[8]&0xff; //第9个数据
Com1OutBuf[19] = a[8]>>8;
crc = CRC16(Com1OutBuf,21); //得到crc校验码
Com1OutBuf[21] = crc>>8;
Com1OutBuf[22] = crc&0xff;
ToCom232(1,Com1OutBuf,23); //发送数据