Improved comments

This commit is contained in:
Jonny007-MKD 2014-08-29 16:13:05 +00:00
parent be86c13ffa
commit d145a51671
2 changed files with 29 additions and 30 deletions

View file

@ -2,18 +2,18 @@
// This file shall contain all information about device specific parameters. // This file shall contain all information about device specific parameters.
/// The aim of this file is to centralize this device specific information so that new Vendors can be added easily /// The aim of this file is to centralize this device specific information so that new Vendors can be added easily
/// Currently supported are Wago 750-881 and B&R X20BC0087. /// Currently supported are Wago 750-881 and B&R X20BC0087 hopefully only the vendors have to be distinguished
/// The Modbus specification leaves room for several parameters than can vary from vendor to vendor (and perhaps also from device to device). These parameters are: /// The Modbus specification leaves room for several parameters than can vary from vendor to vendor (and perhaps also from device to device). These parameters are:
/// - Start addresses for reading input bits/registers /// - Start addresses for reading input bits/registers
/// - Start addresses for reading output bits/registers /// - Start addresses for reading output bits/registers
/// - Start addresses for writing input bits/registers /// - Start addresses for writing input bits/registers
/// - Start addresses for writing output bits/registers /// - Start addresses for writing output bits/registers
/// - Maximum number of connected IO (bits and registers) /// - Maximum number of connected IO (bits and registers)
/// - Size of the receive window (how many telegrams can be processed at the same time) /// - Size of the receive window (how many requests can be received and buffered)
/// This file is used at two position: The majority of the functions are used to analyze devices when making the config. The minority has to be called when initiating a Modbus client so it knows about the addresses and window size. /// This file is used at two positions: The majority of the functions are used to analyze devices when making the config. The minority has to be called when initiating a Modbus client so it knows about the addresses and window size.
variables variables
{ {
// This structure is used by the Modbus Client. // This structure is used by the Modbus Client. It describes the device
struct struct
{ {
struct // Start addresses struct // Start addresses
@ -36,31 +36,31 @@ variables
byte ReceiveWindow; byte ReceiveWindow;
} thisDev; } thisDev;
enum Vendor // The Vendor enum. All Vendors have to listed here and all listed vendors have to be implemented in this file enum Vendor // The Vendor enum. All Vendors have to listed here and all listed vendors have to be implemented in this file
{ {
All = 0xFF, All = 0xFF,
Wago = 23, // Wago Wago = 23, // Wago
BuR = 2 // B&R BuR = 2 // B&R
}; };
struct deviceIOs // A structure which contains quantity information about connected IO. Used in MakeConfig. These info will be written into the SysVars struct deviceIOs // A structure which contains quantity information about connected IO. Used in MakeConfig. These info will be written into the SysVars
{ {
byte InputRegisters; // Count of AI byte InputRegisters; // Count of AI
word InputBits; // Count of DI word InputBits; // Count of DI
byte OutputRegisters; // Count of AO byte OutputRegisters; // Count of AO
word OutputBits; // Count of DO word OutputBits; // Count of DO
char Modules[1024]; // A string representing the connected modules char Modules[1024]; // A string representing the connected modules
}; };
struct device // A structure that contains information about an Modbus device. Used in MakeConfig. struct device // A structure that contains information about an Modbus device. Used in MakeConfig.
{ {
char Ip[16]; // String: The IP address char Ip[16]; // String: The IP address
char Ip4[4]; // String: The last byte of the IP address. char Ip4[4]; // String: The last byte of the IP address.
char Ip3[4]; // String: The third byte of the IP. char Ip3[4]; // String: The third byte of the IP.
char Ip2[4]; // String: The second byte of the IP. char Ip2[4]; // String: The second byte of the IP.
char Ip1[4]; // String: Thefirst byte of the IP. char Ip1[4]; // String: Thefirst byte of the IP.
enum Vendor Vendor; // The Vendor (Wago / B&R) enum Vendor Vendor; // The Vendor (Wago / B&R)
word SerialCode; // Serial Code word SerialCode; // Serial Code
word DeviceCode; // Device Code word DeviceCode; // Device Code
struct deviceIOs DeviceIOs; // A structure with more information about IOs struct deviceIOs DeviceIOs; // A structure with more information about IOs
}; };
} }
@ -113,8 +113,8 @@ void DeviceInit(byte vendor)
/// <MakeConfig> /// <MakeConfig>
void _DeviceParseCode(word dev, enum Vendor vendor, struct deviceIOs dios) void _DeviceParseCode(word dev, enum Vendor vendor, struct deviceIOs dios)
{ {
byte input; byte input; // Yes: INPUT module; No: OUTPUT module
byte numChannels; byte numChannels; // Quantity of channels
char module[10]; char module[10];
strncpy(module, "..%d,", elCount(module)); strncpy(module, "..%d,", elCount(module));
@ -247,14 +247,14 @@ byte _DeviceGetInformation(enum Vendor vendor)
ModbusReadRegisters(0x2031, 64); // Connected IO 2 ModbusReadRegisters(0x2031, 64); // Connected IO 2
ModbusReadRegisters(0x2032, 64); // Connected IO 3 ModbusReadRegisters(0x2032, 64); // Connected IO 3
ModbusReadRegisters(0x2033, 63); // Connected IO 4 ModbusReadRegisters(0x2033, 63); // Connected IO 4
return 10; return 10; // 10 is the number of lines above (number of responses that we expect)
case BuR: case BuR:
ModbusReadRegisters(0x1083, 1); // Product Code ModbusReadRegisters(0x1083, 1); // Product Code
ModbusReadRegisters(0x1101, 1); // Number of AIs ModbusReadRegisters(0x1101, 1); // Number of AIs
ModbusReadRegisters(0x1103, 1); // Number of AOs ModbusReadRegisters(0x1103, 1); // Number of AOs
ModbusReadRegisters(0x1105, 1); // Number of DIs ModbusReadRegisters(0x1105, 1); // Number of DIs
ModbusReadRegisters(0x1107, 1); // Number of DOs ModbusReadRegisters(0x1107, 1); // Number of DOs
return 5; return 5; // 5 is the number of lines above (number of responses that we expect)
default: default:
writeDbg(AlgoError, "DeviceGetInformation: Unknown vendor id: %d", vendor); writeDbg(AlgoError, "DeviceGetInformation: Unknown vendor id: %d", vendor);
OnModbusClientPanics(VendorIdUnknown); OnModbusClientPanics(VendorIdUnknown);

View file

@ -5,7 +5,7 @@ variables
// Some constants // Some constants
const long WSA_IO_PENDING = 997; const long WSA_IO_PENDING = 997;
const long WSAEWOULDBLOCK = 10035; const long WSAEWOULDBLOCK = 10035;
const dword INVALID_IP = 0xffffffff; const dword INVALID_IP = 0xFFFFFFFF;
long gIpLastErr = 0; long gIpLastErr = 0;
char gIpLastErrStr[512] = ""; char gIpLastErrStr[512] = "";
@ -17,7 +17,6 @@ variables
dword gRemoteIP = INVALID_IP; dword gRemoteIP = INVALID_IP;
word gRemotePort = 0; word gRemotePort = 0;
// The buffer where to received telegrams are put // The buffer in which received telegrams are saved
byte gRxBuffer[8192]; byte gRxBuffer[8192];
} }