Minor improvements

This commit is contained in:
Jonny007-MKD 2014-09-23 09:43:16 +00:00
parent 0c4ea8c13f
commit e534955938
6 changed files with 16 additions and 16 deletions

View file

@ -1,7 +1,7 @@
/*@!Encoding:1252*/
// This file is the Modbus Client for Airbus CIDS
// It automatically and periodically reads all input bits and registers and writes them to SysVars %BUSTYPE%::%NODE_NAME%::Data
// It automatically and periodically reads all input bits and registers and writes them to SysVars Modbus::%NODE_NAME%::Data
// It also reacts on changes in the output SysVars and write those to the Modbus device.
includes

View file

@ -203,17 +203,18 @@ void _DeviceParseCode(word dev, enum Vendor vendor, struct deviceIOs dios)
case 556:
input = 0;
numChannels = 2;
break;
case 555: // devices that have 4 outputs
case 553:
case 557:
case 559:
input = 0;
numChannels = 4;
break;
default: // unknown device
writeDbg(AlgoInfo, "Connected device: 750-%d", dev);
return;
}
// Prepare the format string
}
break; // switch(vendor)
default:

View file

@ -187,7 +187,7 @@ void _ModbusReadBits(enum ModbusFuncCode funcCode, word address, long count)
return;
}
// FC1: Read Coils (DO), FC2: Read Discret Inputs (DI)
// FC 0x01: Read Coils (DO), FC 0x02: Read Discret Inputs (DI)
while (count > 0 && address < devEndAddr)
{
curCount = count > gMaxBitsPerRead ? gMaxBitsPerRead : count; // divide packets that are too large
@ -226,7 +226,7 @@ void _OnModbusReceiveBits(byte buffer[])
memcpy_n2h(mbreq, gQueueAck[mbres.Header.TxID].Buffer);
writeDbg(MbInfo, "Received %d bits from 0x%04X", mbreq.Count, mbreq.Address);
for (i = 0; i < mbres.ByteCount; i++)
for (i = 0; i < mbres.ByteCount; i++) // decode the received data
{
for (j = 0; j < 8; j++)
{
@ -289,7 +289,7 @@ void _ModbusReadRegisters(enum ModbusFuncCode funcCode, word address, long count
return;
}
devStartAddr = funcCode == ReadRegistersOut ? thisDev.Addr.Read.OutputRegisters : thisDev.Addr.Read.InputRegisters; // The start address of the bits
devStartAddr = funcCode == ReadRegistersOut ? thisDev.Addr.Read.OutputRegisters : thisDev.Addr.Read.InputRegisters; // The start address of the registers
devEndAddr = devStartAddr + thisDev.MaxRegisterCount; // The address behind the last register
if (address >= devEndAddr)
devEndAddr = 0xFFFF; // Some other address. We might be reading extra registers (no input)
@ -300,7 +300,7 @@ void _ModbusReadRegisters(enum ModbusFuncCode funcCode, word address, long count
OnModbusClientPanics(AddressFailure);
return;
}
// FC3: Read Holding Registers (AO), FC4: Read Input Registers (AI)
// FC 0x03: Read Holding Registers (AO), FC 0x04: Read Input Registers (AI)
while (count > 0 && address < devEndAddr)
{
curCount = count > gMaxRegsPerRead ? gMaxRegsPerRead : count; // divide packets that are too large
@ -309,7 +309,6 @@ void _ModbusReadRegisters(enum ModbusFuncCode funcCode, word address, long count
writeDbg(MbWarning, "_ModbusReadBits: Impossible to read %d bits at 0x%04X. Changed count to %d.", curCount, address, devEndAddr - address);
curCount = devEndAddr - address;
}
//write("address = 0x%04X, count = %d, curCount = %d, devStartAddr = 0x%04X, devEndAddr = 0x%04X", address, count, curCount, devStartAddr, devEndAddr);
_ModbusMakeHeader(mbreq.Header, length, funcCode);
@ -366,7 +365,7 @@ void ModbusWriteBit(word address, byte value)
if (value >= 1)
value = 0xFF;
// FC5: Write Single Coil (DO)
// FC 0x05: Write Single Coil (DO)
_ModbusMakeHeader(mbreq.Header, length, funcCode);
mbreq.Address = address; // [2] Output address
@ -414,7 +413,7 @@ void ModbusWriteRegister(word address, word value)
byte buffer[length];
struct ModbusReqWriteSingle mbreq;
// 5: Write Single Register (AO)
// FC 0x06: Write Single Register (AO)
_ModbusMakeHeader(mbreq.Header, length, funcCode);
mbreq.Address = address; // [2] Output address
@ -478,7 +477,7 @@ void ModbusWriteBits(word address, long count, byte values[])
return;
}
// FC15: Write Multiple Bits (DOs)
// FC 0x0F: Write Multiple Bits (DOs)
offset = 0;
while (count > 0 && (address + offset) < devEndAddr)
{
@ -612,7 +611,7 @@ void ModbusWriteRegisters(word address, long count, word values[])
return;
}
// FC16: Write Multiple Registers (AOs)
// FC 0x10: Write Multiple Registers (AOs)
offset = 0;
while (count > 0 && (address + offset) > devEndAddr)
{
@ -687,7 +686,7 @@ void ModbusWriteMasks(word address, word and, word or)
byte buffer[length];
struct ModbusReqWriteMasks mbreq;
// FC22: Mask Write Registers (AO)
// FC 0x16: Mask Write Registers (AO)
_ModbusMakeHeader(mbreq.Header, length, funcCode);
mbreq.Address = address; // [2] Output address
@ -754,7 +753,7 @@ void ModbusReadWriteRegisters(word readAddress, long readCount, word writeAddres
dataLength = 2 * writeCount;
overallLength = maxLength - 2*(gMaxRegsPerWrite-2) + dataLength;
// FC16: Write Multiple Registers (AOs)
// FC 0x17: Write Multiple Registers (AOs)
_ModbusMakeHeader(mbreq.Header, overallLength, funcCode);
mbreq.ReadAddress = readAddress; // [2] Input address

View file

@ -93,7 +93,7 @@ word _ModbusConnectTo(dword remoteIp, word remotePort)
EthCompletePacket(gPacket);
EthOutputPacket(gPacket);
EthReleasePacket(gPacket);
gSocketState = NULL;
gSocketState = CONNECTING;
gtModbusArp.set(@sysvar::Config::Modbus::RequestTimeout);
return 0;
}

View file

@ -1,6 +1,6 @@
/*@!Encoding:1252*/
// This file connected functions that abstract the UDP/IP API
// This file contains functions that abstract the UDP/IP API
/// It provides following methods
/// - _ModbusConnectTo() Prepare anything that sending works. Here: Open a TCP socket and connection
/// - _ModbusDisconnect() Gracefully disconnect from the device. Here: Close the TCP connection and socket

View file

@ -1,6 +1,6 @@
/*@!Encoding:1252*/
// This file connected functions that abstract the UDP/IP API
// This file contains functions that abstract the UDP/IP API
/// It provides following methods
/// - ModbusConnectTo() Prepare anything that sending works. Here: Open a UDP socket
/// - ModbusDisconnect() Gracefully disconnect from the device. Here: Close the UDP socket