Bachelorthesis/Modbus/include/ModbusFunctions.cin
Jonny007-MKD e0a6d84a9f include/ModbusFunctions.cin
Write values to struct

MakeConfig.can
  Detect devices via IP port scan
  Analyze devices and generate sysVars appropriately

ModbusClientUDP.can
  Don't analyze devices because this has to be done in MakeConfig.can
2014-05-26 10:07:04 +00:00

74 lines
No EOL
1.6 KiB
Text

/*@!Encoding:1252*/
variables
{
struct deviceIOs
{
byte InputRegisters;
word InputBits;
byte OutputRegisters;
word OutputBits;
char Modules[1024];
};
}
void SysvarInit()
{
sysSetVariableString("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info", "Modules", "");
}
void ParseDeviceCode(word dev, struct deviceIOs dios)
{
byte input;
byte numChannels;
char module[10];
if (dev & 0x8000) // Digital Module
{
numChannels = (dev >> 8) & 0x007F;
if (dev & 0x0001) // Input Module
{
input = 1;
strncpy(module, "DI%d,", elCount(module));
dios.InputBits += numChannels;
}
else if (dev & 0x0002) // Output Module
{
input = 0;
strncpy(module, "DO%d,", elCount(module));
dios.OutputBits += numChannels;
}
else // blööd
{
writeLineEx(0, 3, "<%NODE_NAME%> Device code 0x%X cannot be decoded", dev);
runError(1003, 1);
}
}
else
{
switch (dev)
{
case 881: // devices that have no inputs/outputs
return;
case 477: // devices that have 2 outputs
input = 0;
numChannels = 2;
break;
default: // unknown device. Ouch!
writeLineEx(0, 2, "<%NODE_NAME%> Connected device: 750-%d", dev);
return;
}
if (input)
{
strncpy(module, "AI%d,", elCount(module));
dios.InputRegisters += numChannels;
}
else
{
strncpy(module, "AO%d,", elCount(module));
dios.OutputRegisters += numChannels;
}
}
snprintf(module, elCount(module), module, numChannels);
strncat(dios.Modules, module, elCount(dios.Modules));
}