diff --git a/Modbus/MakeConfig.cfg b/Modbus/MakeConfig.cfg index d757884..7d245f4 100644 --- a/Modbus/MakeConfig.cfg +++ b/Modbus/MakeConfig.cfg @@ -1,4 +1,4 @@ -;CANoe Version |4|7|1|35761 MakeConfig +;CANoe Version |4|7|1|52129 MakeConfig Version: 8.2.40 Build 40 32 PRO 5 @@ -348,15 +348,15 @@ VCaplOptionsStreamer 3 Begin_Of_Object End_Of_Object VCaplOptionsStreamer 3 VSVConfigurationStreamer 3 Begin_Of_Object 1 -812 +829 - - - + + + @@ -2933,7 +2933,7 @@ End_Of_Object VGrMnBox 3 VDOLocalInfoStruct 3 Begin_Of_Object 3 1 -62 +71 VDAOBus 4 Begin_Of_Object 1 1 @@ -3063,7 +3063,7 @@ VSimulinkModelViewerConfiguration 7 Begin_Of_Object End_Of_Object VSimulinkModelViewerConfiguration 7 1 0 -297817094 +3836594437 0 NodeSignalPanelBustypeCount 0 End_Of_Object VSimulationNode 6 @@ -3101,7 +3101,7 @@ NULL End_Of_Object VDOLocalInfoStruct 3 0.000000 0 0 -1 1 0 59420 1 233 1 2882400001 98 331 309 611 2882400002 0 0 0 0 0 0 1 2882400001 1270 1270 311 311 2882400002 0 0 0 610451744 0 608276876 3 +1 1 0 59420 1 233 1 2882400001 98 331 309 611 2882400002 0 0 0 0 0 0 1 2882400001 1270 1270 311 311 2882400002 0 0 0 576526008 0 344968884 3 SS_BEGIN_COMMON_INFO 1 0 @@ -3113,7 +3113,7 @@ Ethernet 11 1 1 -609817640 1 0 1 0 0 1 0 0 0 2000 1 +575153512 1 0 1 0 0 1 0 0 0 2000 1 SS_BEGIN_COMMON_INFO 1 3 diff --git a/Modbus/ModbusNet.cfg b/Modbus/ModbusNet.cfg index 9c1e302..c63308c 100644 --- a/Modbus/ModbusNet.cfg +++ b/Modbus/ModbusNet.cfg @@ -1,4 +1,4 @@ -;CANoe Version |4|7|1|38820 ModbusNet +;CANoe Version |4|7|1|38832 ModbusNet Version: 8.2.40 Build 40 32 PRO 10 @@ -1592,7 +1592,10 @@ End_Of_Serialized_Data 14 16 0 17 -0 +1 +14 +ver=2: FT +End_Of_Serialized_Data 14 18 0 19 @@ -4527,7 +4530,7 @@ VUniqueBox 4 Begin_Of_Object VBoxRoot 5 Begin_Of_Object 1 3 -0 0 0 1 -1 -1 -8 -30 0 0 890 487 +0 0 0 1 -1 -1 -1 -1 0 0 890 487 1 @@ -4535,7 +4538,7 @@ MDI_DOCK_INFO_END 5 1 6 -0 1 -1 -1 -8 -30 0 0 890 487 +0 1 -1 -1 -1 -1 0 0 890 487 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 END_OF_DOCK_INFO 1 @@ -4594,7 +4597,7 @@ End_Of_Object VGrMnBox 3 VDOLocalInfoStruct 3 Begin_Of_Object 3 1 -179 +183 VDAOBus 4 Begin_Of_Object 1 1 @@ -4706,7 +4709,7 @@ End_Of_Object VIPBStackSetting 8 NDebugger::VDebuggerHost 8 Begin_Of_Object 2 0 -16 +23 NDebugger::VFile 9 Begin_Of_Object 1 1 "ModbusTcpCommon.cin" @@ -4787,6 +4790,41 @@ NDebugger::VFile 9 Begin_Of_Object 1 "include\CAPL\ModbusClient.can" 27 End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\Common.cin" +28 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\ModbusClientCommon.cin" +29 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\ModbusCommonStructs.cin" +30 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\ModbusFunctions.cin" +31 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\ModbusUdpClientCommon.cin" +32 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\TcpUdpCommon.cin" +33 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "include\CAPL\include\UdpCommon.cin" +34 +End_Of_Object NDebugger::VFile 9 VNETStandaloneComponent 9 Begin_Of_Object 1 VNETControlBox 10 Begin_Of_Object @@ -5035,7 +5073,7 @@ VBoxRoot 9 Begin_Of_Object 1 3 1 1 2 3 -1 -1 -8 -30 114 0 1146 491 -Ethernet Packet Builder + 1 MDI_DOCK_INFO_END @@ -5112,8 +5150,106 @@ EOF_MBSSDATA 1 0 0 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5124,104 +5260,6 @@ EOF_MBSSDATA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - End_Of_Object VSSPlugInConfiguration 6 NULL @@ -5257,7 +5295,7 @@ NULL End_Of_Object VDOLocalInfoStruct 3 0.000000 0 0 -1 1 0 59420 1 233 1 2882400001 323 556 331 782 2882400002 0 0 0 0 0 0 1 2882400001 1197 1197 333 333 2882400002 0 0 0 0 0 0 3 +1 1 0 59420 1 233 1 2882400001 323 556 331 782 2882400002 0 0 0 0 0 0 1 2882400001 1197 1197 333 333 2882400002 0 0 0 1630953112 0 0 3 SS_BEGIN_COMMON_INFO 1 0 @@ -5269,7 +5307,7 @@ Ether1 11 1 1 -609817640 1 0 1 0 1 1 0 0 0 2000 1 +574156496 1 0 1 0 1 1 0 0 0 2000 1 SS_BEGIN_COMMON_INFO 1 3 @@ -5380,7 +5418,7 @@ End_Of_Serialized_Data 2 End_Of_Object VWriteBox 2 VWinStore 2 Begin_Of_Object 1 -22 2 3 -32088 -32000 -1 -1 -10088 -10000 -9070 -9233 +22 2 3 -1 -1 -1 -1 -10088 -10000 -9070 -9233 End_Of_Child_List End_Of_Object VWinStore 2 VWinStore 2 Begin_Of_Object @@ -5529,7 +5567,7 @@ End_Of_Object VScanBaudrateConfiguration 2 0 VPersistentPath 2 Begin_Of_Object 1 - 1 "modbus.cpd" + 1 "ModbusNet.cpd" End_Of_Object VPersistentPath 2 0 3 diff --git a/Modbus/include/CAPL/MakeConfig.can b/Modbus/include/CAPL/MakeConfig.can index b5dffdf..45816fe 100644 --- a/Modbus/include/CAPL/MakeConfig.can +++ b/Modbus/include/CAPL/MakeConfig.can @@ -12,6 +12,7 @@ variables char Ip[16]; char IpLsb[4]; char IpNet[4]; + enum Vendor Vendor; word SerialCode; word DeviceCode; struct deviceIOs DeviceIOs; @@ -20,7 +21,6 @@ variables char[16] gIps[long]; char gScanFirstIp[16]; char gScanLastIp[16]; - word gScanPort = 502; char fnSysvar[40]; // Filename of Sysvars char fnDbc[40]; // Filename of DBC @@ -33,40 +33,53 @@ variables struct device gIpsSorted[long]; dword gScanFirst, gScanLast; word ADi, ADn, ADl; + + byte gMaxTransmissionCount; } on preStart -{/* +{ + // List of IPs of devices go here + /* strncpy(gIps[0], "192.168.1.3", 16); strncpy(gIps[2], "192.168.1.4", 16); - strncpy(gIps[3], "192.168.1.8", 16);*/ + strncpy(gIps[3], "192.168.1.8", 16); + */ + // Scan a range of IPs for devices. Start and Stop go here strncpy(gScanFirstIp, "192.168.1.1", 16); - strncpy(gScanLastIp, "192.168.1.100", 16); + strncpy(gScanLastIp, "192.168.1.10", 16); + // Name of the project strncpy(name, "Modbus", elCount(name)); + // Paths to the generated files relative to .cfg strncpy(fnSysvar, "include/SysVars/generated.vsysvar", elCount(fnSysvar)); strncpy(fnDbc, "include/DBC/generated.dbc", elCount(fnDbc)); } on start { + gMaxTransmissionCount = @sysvar::Config::Modbus::MaxTransmissionCount; + if (gIps.Size() == 0) DetectDevices(); else MakeIpNets(); } +/// void PutString(file f, char str[]) { f.PutString(str, strlen(str)); } +/// void PutString(file f, word d) { char str[6]; ltoa(d, str, 10); f.PutString(str, strlen(str)); } +/// void PutString(file f, byte d) { char str[4]; @@ -78,10 +91,11 @@ void PutString(file f, byte d) /// void DetectDevices() { + @sysvar::Config::Modbus::MaxTransmissionCount = 1; write("Scanning from %s to %s with timeout of %d ms", gScanFirstIp, gScanLastIp, @sysvar::Config::Modbus::RequestTimeout); gScanFirst = ipGetAddressAsNumber(gScanFirstIp); gScanLast = ipGetAddressAsNumber(gScanLastIp); - ModbusConnectTo(gScanFirst, 502); + ModbusConnectTo(gScanFirst, @sysvar::Config::Modbus::Port); ModbusReadBits(0, 1); } /// @@ -110,6 +124,7 @@ void DetectDevicesNext() } if (gScanFirst == gScanLast) { + @sysvar::Config::Modbus::MaxTransmissionCount = gMaxTransmissionCount; MakeIpNets(); return; } @@ -166,10 +181,11 @@ void AnalyzeDevices() ADi = 0; ADl = gIpsSorted.Size(); write("Analyzing %s...", gIpsSorted[ips[ADi]].Ip); + gIpsSorted[ips[ADi]].Vendor = Wago; if (gRemoteIP != INVALID_IP) gRemoteIP = ips[ADi]; else - ModbusConnectTo(ips[ADi], gRemotePort); + ModbusConnectTo(ips[ADi], @sysvar::Config::Modbus::Port); ModbusReadRegisters(0x2011, 1); ModbusReadRegisters(0x2012, 1); ModbusReadRegisters(0x2030, 65); @@ -249,7 +265,7 @@ void OnModbusReadRegistersSuccess(struct ModbusResReceiveRegisters mbr, word num { if (mbr.Data[i] == 0x0000) break; - ParseDeviceCode(mbr.Data[i], gIpsSorted[ips[ADi]].DeviceIOs); + ParseDeviceCode(mbr.Data[i], gIpsSorted[ips[ADi]].Vendor, gIpsSorted[ips[ADi]].DeviceIOs); } break; } @@ -280,9 +296,15 @@ void GenSysvars() PutString(f, " \n"); PutString(f, " \n"); - PutString(f, " \n"); - PutString(f, " \n"); - PutString(f, " \n"); + PutString(f, " \n"); + PutString(f, " \n"); + PutString(f, " \n"); PutString(f, " \n"); PutString(f, " \n"); PutString(f, " \n"); @@ -325,6 +347,15 @@ void GenSysvars() //Namespace Info PutString(f, " \n"); + // Vendor + PutString(f, " \n"); + PutString(f, " \n"); + PutString(f, " \n"); + PutString(f, " \n"); + PutString(f, " \n"); + PutString(f, " \n"); // SerialCode PutString(f, " \n"); // Modules - gIpsSorted[ipN].DeviceIOs.Modules[strlen(gIpsSorted[ipN].DeviceIOs.Modules)] = 0; + gIpsSorted[ipN].DeviceIOs.Modules[strlen(gIpsSorted[ipN].DeviceIOs.Modules)-1] = 0; PutString(f, " \n"); @@ -359,19 +390,19 @@ void GenSysvars() // Namespace Data PutString(f, " \n"); // InputRegisters - PutString(f, " \n"); // InputBits - PutString(f, " \n"); // OutputRegisters - PutString(f, " \n"); // OutputBits - PutString(f, " \n"); @@ -456,15 +487,25 @@ void GenDbc() - +/// void OnModbusWriteBitFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap){} +/// void OnModbusWriteRegisterFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap){} +/// void OnModbusWriteMasksFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap){} +/// void OnModbusReadWriteRegistersFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap){} +/// void OnModbusWriteBitsFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap){} +/// void OnModbusWriteRegistersFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap){} +/// void OnModbusWriteBitSuccess(struct ModbusResConfirmSingle mbc){} +/// void OnModbusWriteRegisterSuccess(struct ModbusResConfirmSingle mbc){} +/// void OnModbusWriteBitsSuccess(struct ModbusResConfirmMultiple mbc){} +/// void OnModbusWriteRegistersSuccess(struct ModbusResConfirmMultiple mbc){} +/// void OnModbusWriteMasksSuccess(struct ModbusResConfirmMasks mbc){} \ No newline at end of file diff --git a/Modbus/include/CAPL/ModbusClient.can b/Modbus/include/CAPL/ModbusClient.can index ce59c75..13fdb58 100644 --- a/Modbus/include/CAPL/ModbusClient.can +++ b/Modbus/include/CAPL/ModbusClient.can @@ -22,7 +22,6 @@ on preStart on start { ModbusInit(); - SysvarInit(); // Read serial code, additional stuff is done in OnModbusReceiveRegisters diff --git a/Modbus/include/CAPL/include/ModbusFunctions.cin b/Modbus/include/CAPL/include/ModbusFunctions.cin index 5bea383..fcc7ed1 100644 --- a/Modbus/include/CAPL/include/ModbusFunctions.cin +++ b/Modbus/include/CAPL/include/ModbusFunctions.cin @@ -1,6 +1,12 @@ /*@!Encoding:1252*/ variables { + enum Vendor + { + BuR = 2, + Wago = 23 + }; + struct deviceIOs { byte InputRegisters; @@ -10,63 +16,68 @@ variables char Modules[1024]; }; } -void SysvarInit() -{ - sysSetVariableString("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info", "Modules", ""); -} -void ParseDeviceCode(word dev, struct deviceIOs dios) +void ParseDeviceCode(word dev, enum Vendor vendor, struct deviceIOs dios) { byte input; byte numChannels; char module[10]; - if (dev & 0x8000) // Digital Module + switch(vendor) { - numChannels = (dev >> 8) & 0x007F; + case Wago: // if this is a Wago device - 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; - } + 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; + } + } + break; // switch(vendor) + default: + writeLineEx(0, 2, "<%NODE_NAME%> Unknown vendor id: %d", vendor); + return; } snprintf(module, elCount(module), module, numChannels); diff --git a/Modbus/include/SysVars/generated.vsysvar b/Modbus/include/SysVars/generated.vsysvar index 4e0fdf6..f32d34c 100644 --- a/Modbus/include/SysVars/generated.vsysvar +++ b/Modbus/include/SysVars/generated.vsysvar @@ -3,9 +3,9 @@ - + - + @@ -18,19 +18,25 @@ + + + + + + - + - - - - + + + +