void presetSingleRegister(void) //设置单个寄存器
{
U8 addr;
U8 tempAddr;
U8 setCount;
U16 crcData;
U16 tempData;
//addr = (receBuf[2]<<8) + receBuf[3];
//tempAddr = addr & 0xfff;
addr = receBuf[3];
tempAddr = addr; //& 0xff
tempData = ( receBuf[4]<> 8;
sendBuf[3] = addr & 0xff;
sendBuf[4] = receBuf[4];
sendBuf[5] = receBuf[5] ;
setCount = 6; //共6个字节
crcData = crc16(sendBuf,6);
sendBuf[6] = crcData >> 8;
sendBuf[7] = crcData & 0xff;
sendCount = 8;
beginSend();
}
//设置多个寄存器
void presetMultipleRegisters(void)
{
UINT8 addr;
UINT8 tempAddr;
UINT8 byteCount;
UINT8 setCount;
UINT16 crcData;
UINT16 tempData;
UINT8 i;
//addr = (receBuf[2]<<8) + receBuf[3];
//tempAddr = addr & 0xfff;
addr = receBuf[3];
tempAddr = addr & 0xff;
//setCount = (receBuf[4]<<8) + receBuf[5];
setCount = receBuf[5];
byteCount = receBuf[6];
for (i = 0; i < setCount; i++, tempAddr++) {
//SBUF = receBuf[i*2+7];
//SBUF = receBuf[i*2+8];
tempData = (receBuf[i*2+7] <> 8;
sendBuf[3] = addr & 0xff;
sendBuf[4] = setCount >> 8;
sendBuf[5] = setCount & 0xff;
crcData = crc16(sendBuf, 6);
sendBuf[6] = crcData >> 8;
sendBuf[7] = crcData & 0xff;
sendCount = 8;
beginSend();
}码
2019-12-21 22:05:12
8.16MB
modbus
1