Improve comments

This commit is contained in:
Jonny007-MKD 2014-07-04 09:57:03 +00:00
parent 1e893112dd
commit bf03b46d34
3 changed files with 46 additions and 8 deletions

View File

@ -31,7 +31,7 @@ on start
DeviceInit(@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::Vendor); // Set all device specific parameters (Wago / B&R)
writeDbg(MbInfo, "Connecting to %s:%d", ip, @sysvar::Config::Modbus::Port);
ModbusConnectTo(ip, @sysvar::Config::Modbus::Port); // Connect to device. Opens socket and connection or what ever
ModbusInit(ip, @sysvar::Config::Modbus::Port); // Connect to device. Opens socket and connection or what ever
ModbusReadOutBits(gDevOutputBitAddrR, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits); // Read the start status of the output bits
ModbusReadOutRegisters(gDevOutputRegAddrR, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputRegisters); // Read the start status of the output registers

View File

@ -1,11 +1,39 @@
/*@!Encoding:1252*/
// This is the main file providing functions for talking to Modbus devices.
// Don't include this file directly! Choose one transportation protocol (TCP, UDP, EthernetIL) and include the corresponding file (Modbus###ClientCommon.cin)
// This is the main file providing functions for talking to Modbus servers.
// Additionally include a network layer: ModbusUdp.cin, ModbusTcp.cin or ModbusEil.cin
/// This layer provides functions to send Modbus telegrams, enqueues this messages and watch for timeouts. When responses are received, the corresponding callback method will be called
/// The Modbus telegrams are distinguished in the queues by their TxID
/// This layer provides functions to send Modbus requests, enqueues these messages and watch for timeouts. When responses are received, the corresponding callback method will be called
/// There are three queues available: Pending, Sent & Ack. Only the latter shall be used by the higher layer. Pending telegrams are waiting to be sent, sent telegrams are waiting to be responded and acknowledged telegrams were already responded and can now be processed further.
/// The Modbus telegrams are distinguished in the queues by their TxID
/// It provides following methods
/// - ModbusInit() Prepare anything that Modbus works (open connection etc.)
/// - ModbusReadOutBits() Modbus Function Code: 0x01 (Discrete inputs)
/// - ModbusReadInBits() Modbus Function Code: 0x02 (Coils)
/// --> results in OnModbusReadBitsSuccess() or OnModbusReadBitsFailed() (have to be implemented by you)
/// - ModbusReadOutRegisters() Modbus Function Code: 0x03 (Input registers)
/// - ModbusReadInRegisters() Modbus Function Code: 0x04 (Holding registers)
/// --> results in OnModbusReadRegistersSuccess() or OnModbusReadRegistersFailed() (have to be implemented by you)
/// - ModbusWriteBit() Modbus Function Code: 0x05 (Coils)
/// --> results in OnModbusWriteBitSuccess() or OnModbusWriteBitFailed() (have to be implemented by you)
/// - ModbusWriteRegister() Modbus Function Code: 0x06 (Holding registers)
/// --> results in OnModbusWriteRegisterSuccess() or OnModbusWriteRegisterFailed() (have to be implemented by you)
/// - ModbusWriteBits() Modbus Function Code: 0x0F (Coils)
/// - ModbusWriteBitsB() Wrapper for ModbusWriteBits: Encodes a bit array with size N to an array with size N/8
/// --> results in OnModbusWriteBitsSuccess() or OnModbusWriteBitsFailed() (have to be implemented by you)
/// - ModbusWriteRegisters() Modbus Function Code: 0x10 (Holding registers)
/// - ModbusReadWriteRegisters() Modbus Function Code: 0x17 (Holding registers)
/// --> results in OnModbusWriteRegistersSuccess() or OnModbusWriteRegistersFailed() (have to be implemented by you)
/// - ModbusWriteMasks() Modbus Function Code: 0x10 (Holding registers)
/// --> results in OnModbusWriteMasksSuccess() or OnModbusWriteMasksFailed() (have to be implemented by you)
includes
{
@ -21,7 +49,7 @@ variables
struct QueueElement
{
word TimeoutTicks; // Time counter [ms]. Used to watch for timeouts (see @sysvar::Config::Modubs::RequestTimeout)
byte Timeouts;
byte Timeouts;
word Length;
byte Buffer[gModbusMaxTelegramSize];
};
@ -44,6 +72,15 @@ variables
};
}
// This method prepares anything that sending Modbus requests works. Currently this is only the connection.
// It has to be called by the user/modbus client at the beginning with IP and Port of the Modbus server
void ModbusInit(char Remote_IP[], word remotePort)
{
ModbusConnectTo(ip, @sysvar::Config::Modbus::Port);
}
// This method fills the ModbusApHeader structure 'mbap'.
// It gets called by the Modbus request methods
void ModbusMakeHeader(struct ModbusApHeader mbap, word length, byte funcCode)
{
mbap.TxID = gTxID++; // [2] Transaction ID
@ -57,6 +94,7 @@ void ModbusMakeHeader(struct ModbusApHeader mbap, word length, byte funcCode)
// REGION: ModbusReadBits -------------------------------------------------------------
/// <ModbusReadBits>
// This method will submit a request to the Modbus server to read
void ModbusReadInBits(word address, long count)
{
ModbusReadBits(0x02, address, count);
@ -861,4 +899,4 @@ on timer gtModbusRobin
writeDbg(ConnDebug, "Stopping Timer gtModbusRobin");
this.Cancel();
}
}
}

View File

@ -1,6 +1,6 @@
/*@!Encoding:1252*/
// This file connected functions that abstract the TCP/IP API
// This file connected 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