//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff;
addr = receBuf[3]; //get address of ... tempAddr = addr; //temp var
//bitCount = (receBuf[4]<<8) + receBuf[5]; //get count of bits bitCount = receBuf[5];
byteCount = bitCount / 8; //get count of bytes if (bitCount % 8 != 0) byteCount++;
for (k = 0; k < byteCount; k++) {
position = k + 3; sendBuf[position] = 0; for (i = 0; i < 8; i++) {
getCoilVal(tempAddr, &tempData);
sendBuf[position] |= tempData << i; tempAddr++;
if (tempAddr >= addr + bitCount) {
exit = 1; break; } }
if (exit == 1) break; }
sendBuf[0] = localAddr; sendBuf[1] = 0x01; sendBuf[2] = byteCount; byteCount += 3;
crcData = crc16(sendBuf, byteCount); sendBuf[byteCount] = crcData >> 8; byteCount++;
sendBuf[byteCount] = crcData & 0xff; sendCount = byteCount + 1;
beginSend(); }
void readRegisters(void) {
static Uint8 kk = 0; Uint8 xkwy_temp; Uint8 addr; Uint8 tempAddr; Uint16 crcData; Uint8 readCount; Uint8 byteCount; Uint16 i;
Uint16 tempData = 0;
//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3]; tempAddr = addr;
xkwy_temp = M;
kk = ~kk; if (kk) {
if (xkwy_temp&0x08) {
if ((xkwy_temp&0x07) + testRegister2 >= testRegister2) testRegister0 = (xkwy_temp&0x07) + testRegister2; else
testRegister0 = 0xff; } else {
if (testRegister2-(xkwy_temp&0x07) <= testRegister2) testRegister0 = testRegister2 - (xkwy_temp&0x07); else
testRegister0 = 0x00; }
if (testRegister0 > 0xff) testRegister0 = 0xff; } else {
if (xkwy_temp&0x08) {
if ((xkwy_temp&0x07) + testRegister1 >= testRegister1) testRegister1 = (xkwy_temp&0x07) + testRegister1;
else
testRegister1 = 0xff; } else {
if (testRegister1-(xkwy_temp&0x07) <= testRegister1) testRegister1 = testRegister1 - (xkwy_temp&0x07); else
testRegister1 = 0x00; }
if (testRegister1 > 0xff) testRegister1 = 0xff; }
//readCount = (receBuf[4]<<8) + receBuf[5]; readCount = receBuf[5];
byteCount = readCount * 2;
for (i = 0; i < byteCount; i += 2, tempAddr++) { getRegisterVal(tempAddr, &tempData); sendBuf[i+3] = tempData >> 8; sendBuf[i+4] = tempData & 0xff; }
sendBuf[0] = localAddr; sendBuf[1] = 3;
sendBuf[2] = byteCount; byteCount += 3;
crcData = crc16(sendBuf, byteCount); sendBuf[byteCount] = crcData >> 8; byteCount++;
sendBuf[byteCount] = crcData & 0xff;
sendCount = byteCount + 1;
beginSend();
}//void readRegisters(void)
void forceSingleCoil(void) {
Uint8 addr; Uint8 tempAddr; Uint16 tempData;
Uint8 onOff; Uint8 i;
//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3]; tempAddr = addr;
//onOff = (receBuf[4]<<8) + receBuf[5]; onOff = receBuf[4];
//if(onOff == 0xff00) if (onOff == 0xff) {
tempData = 1; }
//else if(onOff == 0x0000) else if (onOff == 0x00) {
tempData = 0; }
setCoilVal(tempAddr, tempData);
for (i = 0; i < receCount; i++) { sendBuf[i] = receBuf[i]; }
sendCount = receCount;
beginSend(); }
void presetSingleRegister(void) {
Uint8 addr; Uint8 tempAddr; Uint8 setCount; Uint16 crcData; Uint16 tempData;
//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3];
tempAddr = addr; //& 0xff
tempData = ( receBuf[4]<<8 ) + receBuf[5]; setRegisterVal(tempAddr,tempData);
sendBuf[0] = localAddr; sendBuf[1] = 6;
sendBuf[2] = addr >> 8; sendBuf[3] = addr & 0xff; sendBuf[4] = receBuf[4]; sendBuf[5] = receBuf[5] ;
setCount = 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) + receBuf[i*2+8];
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于TMS320F2812的三相逆变电源(3)在线全文阅读。
相关推荐: