diff --git a/Modbus/Common.cin b/Modbus/Common.cin index 1edac38..d28df3d 100644 --- a/Modbus/Common.cin +++ b/Modbus/Common.cin @@ -2,7 +2,7 @@ void bin_to_strhex(byte bin[], char result[]) { - char hex_str[17]= "0123456789ABCDEF"; + char hex_str[17] = "0123456789ABCDEF"; word i; word binsz; @@ -24,4 +24,58 @@ void bin_to_strhex(byte bin[], char result[]) result[58] = '.'; } result[binsz * 3 - 1] = 0; +} + +void hbin_to_strhex(byte bin[], char result[]) +{ + char hex_str[17] = "0123456789ABCDEF"; + word i; + word binsz; + + binsz = elCount(bin); + if (binsz > 20) + binsz = 20; + + for (i = 0; i < binsz; i++) + { + result[i * 2 + 0] = hex_str[bin[i] & 0x0F]; + result[i * 2 + 1] = ' '; + } + + if (elCount(bin) > 20) // trailing "..." + { + result[36] = '.'; + result[37] = '.'; + result[38] = '.'; + } + result[binsz * 2 - 1] = 0; +} + +void dbin_to_strhex(word bin[], char result[]) +{ + char hex_str[17] = "0123456789ABCDEF"; + word i; + word binsz; + byte offset; + + binsz = elCount(bin); + if (binsz > 20) + binsz = 20; + + for (i = 0; i < binsz; i++) + { + result[i * 5 + 0] = hex_str[(bin[i] >> 12) & 0x0F]; + result[i * 5 + 1] = hex_str[(bin[i] >> 8) & 0x0F]; + result[i * 5 + 2] = hex_str[(bin[i] >> 4) & 0x0F]; + result[i * 5 + 3] = hex_str[(bin[i] ) & 0x0F]; + result[i * 5 + 4] = ' '; + } + + if (elCount(bin) > 20) // trailing "..." + { + result[96] = '.'; + result[97] = '.'; + result[98] = '.'; + } + result[(byte)(binsz * 2.5) - 1] = 0; } \ No newline at end of file diff --git a/Modbus/ModbusClientCommon.cin b/Modbus/ModbusClientCommon.cin index f343788..f7cb138 100644 --- a/Modbus/ModbusClientCommon.cin +++ b/Modbus/ModbusClientCommon.cin @@ -2,173 +2,424 @@ // Additionally include ModbusTcpCommon.cin or ModbusUdpCommon.cin includes { + #include "ModbusCommonStructs.cin" } variables { - struct ModbusApHeader { - word TxID; - word Protocol; - word Length; - byte UnitID; - byte FuncCode; - }; - struct ModbusRead { - struct ModbusApHeader Header; - word Address; - word Count; - }; - struct ModbusWriteSingle { - struct ModbusApHeader Header; - word Address; - word Value; - }; - struct ModbusWriteMultiple { - struct ModbusApHeader Header; - word Address; - word Count; - byte ByteCount; - }; -} + const word gMaxPacketLength = __size_of(struct ModbusReqWriteRegisters); -// TODO: Add request timeout timers + // Global storage for pending requests, associated by funcCode + struct + { + byte Count; + word Length; + byte Buffer[gMaxPacketLength]; + } gRequests[int64, 8]; + + + + msTimer gTimerModbusReadBits; + msTimer gTimerModbusReadRegisters; + msTimer gTimerModbusWriteBit; + msTimer gTimerModbusWriteRegister; + msTimer gTimerModbusWriteBits; + msTimer gTimerModbusWriteRegisters; + msTimer gTimerModbusWriteMasks; + msTimer gTimerModbusReadWriteRegisters; +} void ModbusInit(char Remote_IP[], word Remote_Port) { - ModbusConnectTo("192.168.1.3", 502); + sysDefineVariableString("%NETWORK_NAME%::%BASE_FILE_NAME%::Info", "IP", Remote_IP); + sysDefineVariableInt("%NETWORK_NAME%::%BASE_FILE_NAME%::Info", "Port", Remote_Port); + + ModbusConnectTo(Remote_IP, Remote_Port); } -void ModbusMakeHeader(struct ModbusApHeader mbap, byte length) +void ModbusMakeHeader(struct ModbusApHeader mbap, word length) { mbap.TxID = 0x1234; // [2] Transaction ID. Not needed here? mbap.Protocol = 0x0000; // [2] Protocol ID = 0 = Modbus - mbap.Length = length-6; // [2] Length; Number of bytes following + mbap.Length = length - __offset_of(struct ModbusApHeader, UnitID); // [2] Length; Number of bytes following mbap.UnitID = 0xFF; // [1] Unit identifier; not relevant - - // 2:Read DIO; 3:Read AIO; 4:Read AI; 5:Write 1 DO; 6:Write 1 AO; 7: Read Exeption, 15:Write n DO; 16:Write n AO; } +// REGION: ModbusReadBits ------------------------------------------------------------- +/// void ModbusReadBits(word address, word count) { - const byte length = 12; + const byte length = __size_of(struct ModbusReqRead); + const byte funcCode = 0x01; byte buffer[length]; - struct ModbusRead mbr; - + struct ModbusReqRead mbr; + + if (gRequests[funcCode].Count > 0) // TODO: a transmission is in progress. What shall we do? + return; + ModbusMakeHeader(mbr.Header, length); // Payload - mbr.Header.FuncCode = 0x01; // [1] Function Code; 1: Read Coils (DI), 2: Read Discret Inputs (DIO), seems to be the same for WAGO 750-881 + mbr.Header.FuncCode = funcCode; // [1] Function Code; 1: Read Coils (DI), 2: Read Discret Inputs (DIO), seems to be the same for WAGO 750-881 mbr.Address = address; // [2] Start address mbr.Count = count; // [2] Number of items; 1:max 2000=0x7D0 memcpy_h2n(buffer, mbr); ModbusSend(buffer); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, length); + gRequests[funcCode].Length = length; + gTimerModbusReadBits.Set(@sysvar::Config::Modbus::RequestTimeout); ModbusRecv(); } -void OnModbusReceiveBits(byte response[], dword size) +/// +void OnModbusReceiveBits(byte buffer[]) { - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceiveBits: Received %d bytes: %d...", response[0], response[1]); + const byte funcCode = 0x01; + struct ModbusResReceiveBits mbr; + byte bitStatus[1968]; + word numBits; + byte i, j; + + gTimerModbusReadBits.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbr, buffer); + + numBits = (gRequests[funcCode].Buffer[10] << 8) + gRequests[funcCode].Buffer[11]; + + for (i = 0; i < mbr.ByteCount; i++) + { + for (j = 0; j < 8; j++) + { + bitStatus[8*i+j] = mbr.Data[i] & (0x01 << j); + } + } + + OnModbusReadBitsSuccess(mbr, bitStatus, numBits); +} + +/// +void OnModbusReceiveBitsException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x01; + + gTimerModbusReadBits.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusReadBits +{ + const byte length = __size_of(struct ModbusReqRead); + const byte funcCode = 0x01; + byte buffer[length]; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusReadBitsFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + memcpy(buffer, gRequests[funcCode].Buffer, length); + + ModbusSend(buffer); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); } + + + +// REGION: ModbusReadRegisters ------------------------------------------------------- +/// void ModbusReadRegisters(word address, word count) // 16 bit { - const byte length = 12; + const byte length = __size_of(struct ModbusReqRead); + const byte funcCode = 0x03; byte buffer[length]; - struct ModbusRead mbr; + struct ModbusReqRead mbr; + + if (gRequests[funcCode].Count > 0) + return; ModbusMakeHeader(mbr.Header, length); // Payload - mbr.Header.FuncCode = 0x03; // [1] Function Code; 3: Read Holding Registers (AI), 4: Read Input Registers (AIO), seems to be the same for WAGO 750-881 + mbr.Header.FuncCode = funcCode; // [1] Function Code; 3: Read Holding Registers (AI), 4: Read Input Registers (AIO), seems to be the same for WAGO 750-881 mbr.Address = address; // [2] Start address - mbr.Count = count; // [2] Number of items; 1:max 2000=0x7D0 + mbr.Count = count; // [2] Number of items; 1:max 125=0x7D memcpy_h2n(buffer, mbr); ModbusSend(buffer); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, length); + gRequests[funcCode].Length = length; + gTimerModbusReadRegisters.Set(@sysvar::Config::Modbus::RequestTimeout); ModbusRecv(); } -void OnModbusReceiveRegisters(byte response[], dword size) +/// +void OnModbusReceiveRegisters(byte buffer[]) { - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceiveRegisters: Received %d bytes: %d...", response[0]/2, response[1]<<8+response[2]); + const byte funcCode = 0x03; + struct ModbusResReceiveRegisters mbr; + word numRegs; + + gTimerModbusReadRegisters.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbr, buffer); + numRegs = (gRequests[funcCode].Buffer[10] << 8) + gRequests[funcCode].Buffer[11]; + + OnModbusReadRegistersSuccess(mbr, numRegs); +} + +/// +void OnModbusReceiveRegistersException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x03; + + gTimerModbusReadRegisters.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusReadRegisters +{ + const byte length = __size_of(struct ModbusReqRead); + const byte funcCode = 0x03; + byte buffer[length]; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusReadRegistersFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + memcpy(buffer, gRequests[funcCode].Buffer, length); + + ModbusSend(buffer); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); } + + + +// REGION: ModbusWriteBit ------------------------------------------------------------- +/// void ModbusWriteBit(word address, byte value) { - const byte length = 12; + const byte length = __size_of(struct ModbusReqWriteSingle); + const byte funcCode = 0x05; byte buffer[length]; - struct ModbusWriteSingle mbw; + struct ModbusReqWriteSingle mbw; + + if (gRequests[funcCode].Count > 0) + return; if (value >= 1) value = 0xFF; ModbusMakeHeader(mbw.Header, length); // Payload - mbw.Header.FuncCode = 0x05; // [1] Function Code; 5: Write Single Coil (DO) + mbw.Header.FuncCode = funcCode; // [1] Function Code; 5: Write Single Coil (DO) mbw.Address = address; // [2] Output address mbw.Value = value << 8; // [2] Output value (0x0000: Off, 0xFF00: On) memcpy_h2n(buffer, mbw); ModbusSend(buffer); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, length); + gRequests[funcCode].Length = length; + gTimerModbusWriteBit.Set(@sysvar::Config::Modbus::RequestTimeout); ModbusRecv(); } -void OnModbusConfirmBit(byte response[], dword size) +/// +void OnModbusConfirmBit(byte buffer[]) { - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmBit: Set bit 0x%X to %d", (response[0]<<8) + response[1], ((response[2]<<8) + response[3] > 0 ? 1 : 0)); + const byte funcCode = 0x05; + struct ModbusResConfirmSingle mbc; + + gTimerModbusWriteBit.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbc, buffer); + + OnModbusWriteBitSuccess(mbc); +} + +/// +void OnModbusConfirmBitException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x05; + + gTimerModbusWriteBit.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusWriteBit +{ + const byte length = __size_of(struct ModbusReqWriteSingle); + const byte funcCode = 0x05; + byte buffer[length]; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusWriteBitFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + memcpy(buffer, gRequests[funcCode].Buffer, length); + + ModbusSend(buffer); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); } -void ModbusWriteRegister(word address, word value) + + + +// REGION: ModbusWriteRegister ------------------------------------------------------ +/// +void ModbusWriteRegister(word address, int value) { - const byte length = 12; + const byte length = __size_of(struct ModbusReqWriteSingle); + const byte funcCode = 0x06; byte buffer[length]; - struct ModbusWriteSingle mbw; + struct ModbusReqWriteSingle mbw; + + if (gRequests[funcCode].Count > 0) + return; ModbusMakeHeader(mbw.Header, length); // Payload - mbw.Header.FuncCode = 0x06; // [1] Function Code; 5: Write Single Register (AO) + mbw.Header.FuncCode = funcCode; // [1] Function Code; 5: Write Single Register (AO) mbw.Address = address; // [2] Output address mbw.Value = value; // [2] Output value memcpy_h2n(buffer, mbw); ModbusSend(buffer); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, length); + gRequests[funcCode].Length = length; + gTimerModbusWriteRegister.Set(@sysvar::Config::Modbus::RequestTimeout); ModbusRecv(); } -void OnModbusConfirmRegister(byte response[], dword size) +/// +void OnModbusConfirmRegister(byte buffer[]) { - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmRegister: Set register 0x%X to %d", (response[0]<<8) + response[1], (response[2]<<8) + response[3]); + const byte funcCode = 0x06; + struct ModbusResConfirmSingle mbc; + + gTimerModbusWriteRegister.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbc, buffer); + + OnModbusWriteRegisterSuccess(mbc); +} + +/// +void OnModbusConfirmRegisterException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x06; + + gTimerModbusWriteRegister.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusWriteRegister +{ + const byte length = __size_of(struct ModbusReqWriteSingle); + const byte funcCode = 0x06; + byte buffer[length]; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusWriteRegisterFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + memcpy(buffer, gRequests[funcCode].Buffer, length); + + ModbusSend(buffer); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); } + + +// REGION: ModbusWriteBits ---------------------------------------------------------- +/// void ModbusWriteBits(word address, word count, byte values[]) { - const byte length = 13 + 2; //_ceil(count / 8.0) - byte buffer[length]; - struct ModbusWriteMultiple mbw; + const word maxLength = __size_of(struct ModbusReqWriteBits); + const byte funcCode = 0x0F; + byte buffer[maxLength]; + struct ModbusReqWriteBits mbw; + byte dataLength; + byte overallLength; word i; - ModbusMakeHeader(mbw.Header, length); + if (gRequests[funcCode].Count > 0) + return; + + dataLength = _ceil(count / 8.0); + overallLength = maxLength - 1968/8 + dataLength; + ModbusMakeHeader(mbw.Header, overallLength); // Payload - mbw.Header.FuncCode = 0x0F; // [1] Function Code; 15: Write Multiple Bits (DOs) + mbw.Header.FuncCode = funcCode; // [1] Function Code; 15: Write Multiple Bits (DOs) mbw.Address = address; // [2] Output address mbw.Count = count; // [2] Number of items; 1:max 1968=0x7B0 - mbw.ByteCount = 2; // [1] Number of bytes; = ceil(count/8) + mbw.ByteCount = dataLength; // [1] Number of bytes; = ceil(count/8) + memcpy(mbw.Data, values, dataLength); // this is 1 memcpy too much -.- memcpy_h2n(buffer, mbw); - - for (i = 0; i < length-13; i++) - { - buffer[i+13] = values[i]; - } - ModbusSend(buffer); + + ModbusSend(buffer, overallLength); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, overallLength); + gRequests[funcCode].Length = overallLength; + gTimerModbusWriteBits.Set(@sysvar::Config::Modbus::RequestTimeout); ModbusRecv(); } +/// void ModbusWriteBitsB(word address, word count, byte values[]) { byte buffer[2]; // length @@ -176,7 +427,7 @@ void ModbusWriteBitsB(word address, word count, byte values[]) dword ellCount; dword i; dword j; - char str1[20*3], str2[20*3]; + char str1[20*2], str2[20*3]; ellCount = elCount(values); length = (word)_ceil(ellCount / 8.0); @@ -202,139 +453,499 @@ void ModbusWriteBitsB(word address, word count, byte values[]) } //writeLineEx(0, 3, "%d: %X", length-1, buffer[length-1]); - bin_to_strhex(values, str1); + hbin_to_strhex(values, str1); bin_to_strhex(buffer, str2); writeLineEx(0, 1, "<%BASE_FILE_NAME%> ModbusWriteBitsB: Encoded %s to %s", str1, str2); ModbusWriteBits(address, count, buffer); } -void OnModbusConfirmBits(byte response[], dword size) +/// +void OnModbusConfirmBits(byte buffer[]) { - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmBits: Set %d bits beginning with 0x%X", (response[2]<<8) + response[3], (response[0]<<8) + response[1]); + const byte funcCode = 0x0F; + struct ModbusResConfirmMultiple mbc; + + gTimerModbusWriteBits.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbc, buffer); + + OnModbusWriteBitsSuccess(mbc); } - -void ModbusWriteRegisters(word address, word count, word values[]) +/// +void OnModbusConfirmBitsException(struct ModbusApHeader mbap, enum ModbusException ex) { - const byte length = 13 + 2; //13 + 2*count - byte buffer[length]; - struct ModbusWriteMultiple mbw; - word i; + const byte funcCode = 0x0F; - ModbusMakeHeader(mbw.Header, length); - // Payload - mbw.Header.FuncCode = 0x10; // [1] Function Code; 16: Write Multiple Registers (AOs) - mbw.Address = address; // [2] Output address - mbw.Count = count; // [2] Number of items; 1:max 123=0x7B - mbw.ByteCount = 2 * count; // [1] Number of bytes; = 2 * count + gTimerModbusWriteBits.Cancel(); + gRequests[funcCode].Count = 0; - memcpy_h2n(buffer, mbw); + OnModbusReadBitsFailed(Exception, ex, mbap); +} - for (i = 0; i < length-13; i += 2) +/// +on timer gTimerModbusWriteBits +{ + const byte funcCode = 0x0F; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) { - buffer[i+13] = values[i] >> 8; - buffer[i+14] = values[i] & 0xFF; + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusWriteBitsFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; } - ModbusSend(buffer); + + ModbusSend(gRequests[funcCode].Buffer, gRequests[funcCode].Length); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); ModbusRecv(); } -void OnModbusConfirmRegisters(byte response[], dword size) + + + +// REGION: ModbusWriteRegisters ------------------------------------------------------- +/// +void ModbusWriteRegisters(word address, word count, int values[]) { - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmRegisters: Set %d registers beginning with 0x%X", (response[2]<<8) + response[3], (response[0]<<8) + response[1]); + const word maxLength = __size_of(struct ModbusReqWriteRegisters); + const byte funcCode = 0x10; + byte buffer[maxLength]; + struct ModbusReqWriteRegisters mbw; + byte dataLength; + word overallLength; + word i; + + if (gRequests[funcCode].Count > 0) + return; + + dataLength = 2 * count; + overallLength = maxLength - 2*123 + dataLength; + + ModbusMakeHeader(mbw.Header, overallLength); + // Payload + mbw.Header.FuncCode = funcCode; // [1] Function Code; 16: Write Multiple Registers (AOs) + mbw.Address = address; // [2] Output address + mbw.Count = count; // [2] Number of items; 1:max 123=0x7B + mbw.ByteCount = dataLength; // [1] Number of bytes; = 2 * count + + for (i = 0; i < dataLength; i++) + mbw.Data[i] = values[i]; + + memcpy_h2n(buffer, mbw); + + ModbusSend(buffer, overallLength); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, overallLength); + gRequests[funcCode].Length = overallLength; + gTimerModbusWriteRegisters.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); +} + +/// +void OnModbusConfirmRegisters(byte buffer[]) +{ + const byte funcCode = 0x10; + struct ModbusResConfirmMultiple mbc; + + gTimerModbusWriteRegisters.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbc, buffer); + + OnModbusWriteRegistersSuccess(mbc); +} + +/// +void OnModbusConfirmRegistersException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x10; + + gTimerModbusWriteRegisters.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusWriteRegisters +{ + const byte funcCode = 0x10; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusWriteRegistersFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + ModbusSend(gRequests[funcCode].Buffer, gRequests[funcCode].Length); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); +} + + +// REGION: ModbusWriteMasks ------------------------------------------------------------ +/// +void ModbusWriteMasks(word address, word and, word or) +{ + const word length = __size_of(struct ModbusReqWriteMasks); + const byte funcCode = 0x16; + byte buffer[length]; + struct ModbusReqWriteMasks mbw; + + if (gRequests[funcCode].Count > 0) + return; + + ModbusMakeHeader(mbw.Header, length); + // Payload + mbw.Header.FuncCode = funcCode; // [1] Function Code; 22: Mask Write Registers (AO) + mbw.Address = address; // [2] Output address + mbw.And = and; // [2] AND mask + mbw.Or = or; // [2] OR mask + + memcpy_h2n(buffer, mbw); + + ModbusSend(buffer); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, length); + gRequests[funcCode].Length = length; + gTimerModbusWriteMasks.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); +} + +/// +void OnModbusConfirmMasks(byte buffer[]) +{ + const byte funcCode = 0x15; + struct ModbusResConfirmMasks mbc; + + gTimerModbusWriteMasks.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbc, buffer); + + OnModbusWriteMasksSuccess(mbc); +} + +/// +void OnModbusConfirmMasksException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x15; + + gTimerModbusWriteMasks.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusWriteMasks +{ + const byte funcCode = 0x16; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusWriteMasksFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + ModbusSend(gRequests[funcCode].Buffer, gRequests[funcCode].Length); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); +} + + +// REGION: ModbusReadWriteRegisters ------------------------------------------------------- +/// +void ModbusReadWriteRegisters(word readAddress, word readCount, word writeAddress, word writeCount, int values[]) +{ + const word maxLength = __size_of(struct ModbusReqReadWriteRegisters); + const byte funcCode = 0x17; + byte buffer[maxLength]; + struct ModbusReqReadWriteRegisters mbw; + byte dataLength; + word overallLength; + word i; + + if (gRequests[funcCode].Count > 0) + return; + + dataLength = 2 * writeCount; + overallLength = maxLength - 2*121 + dataLength; + + ModbusMakeHeader(mbw.Header, overallLength); + // Payload + mbw.Header.FuncCode = funcCode; // [1] Function Code; 16: Write Multiple Registers (AOs) + mbw.ReadAddress = readAddress; // [2] Input address + mbw.ReadCount = readCount; // [2] Number of items; 1:max 125=0x7D + mbw.WriteAddress = writeAddress;// [2] Output address + mbw.WriteCount = writeCount; // [2] Number of items; 1:max 121=0x79 + mbw.ByteCount = dataLength; // [1] Number of bytes; = 2 * count + + for (i = 0; i < dataLength; i++) + mbw.Data[i] = values[i]; + + memcpy_h2n(buffer, mbw); + + ModbusSend(buffer, overallLength); + gRequests[funcCode].Count = 1; + memcpy(gRequests[funcCode].Buffer, buffer, overallLength); + gRequests[funcCode].Length = overallLength; + gTimerModbusWriteRegisters.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); +} + +/// +void OnModbusReceiveConfirmRegisters(byte buffer[]) +{ + const byte funcCode = 0x17; + byte numRegs; + struct ModbusResReceiveRegisters mbr; + + gTimerModbusReadWriteRegisters.Cancel(); + gRequests[funcCode].Count = 0; + + memcpy_n2h(mbr, buffer); + numRegs = (gRequests[funcCode].Buffer[10] << 8) + gRequests[funcCode].Buffer[11]; + + OnModbusReadRegistersSuccess(mbr, numRegs); +} + +/// +void OnModbusReceiveConfirmRegistersException(struct ModbusApHeader mbap, enum ModbusException ex) +{ + const byte funcCode = 0x17; + + gTimerModbusReadWriteRegisters.Cancel(); + gRequests[funcCode].Count = 0; + + OnModbusReadBitsFailed(Exception, ex, mbap); +} + +/// +on timer gTimerModbusReadWriteRegisters +{ + const byte funcCode = 0x17; + struct ModbusApHeader mbap; + + if (gRequests[funcCode].Count == @sysvar::Config::Modbus::MaxRetransmissionCount) + { + memcpy_n2h(mbap, gRequests[funcCode].Buffer); + OnModbusReadWriteRegistersFailed(Timeout, None, mbap); + gRequests[funcCode].Count = 0; + return; + } + + ModbusSend(gRequests[funcCode].Buffer, gRequests[funcCode].Length); + gRequests[funcCode].Count++; + this.Set(@sysvar::Config::Modbus::RequestTimeout); + ModbusRecv(); } +// ------------------------------------------------------------------------------------ +// REGION: OnModbusReceive ------------------------------------------------------------ +/// +void OnModbusReceive(dword socket, long result, dword address, dword port, byte buffer[], dword size) +{ + if (result == 0) + { + if (size == 0) + { + // Size of zero indicates that the socket was closed by the communication peer. + writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive: Socket closed by peer"); + gSocket.Close(); + gSocketState = CLOSED; + } + else + { + // Sucessfully received some bytes over the TCP/IP connection. + OnModbusReceive2(buffer, size); + } + } + else + { + gIpLastErr = gSocket.GetLastSocketError(); + gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr)); + writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr); + gSocket.Close(); + gSocketState = CLOSED; + } +} -void OnModbusReceive(byte buffer[], dword size) +/// +void OnModbusReceive2(byte buffer[], dword size) +{ + struct ModbusApHeader mbap; + int offset; + + if (size < 8) // No complete Modbus Application Header + return; + + offset = 0; + //write("OnModbusReceive2: size = %d", size); + do + { + //write("OnModbusReceive2: offset pre = %d", offset); + memcpy_n2h(mbap, buffer, offset); + OnModbusReceive2OnePacket(buffer, offset, mbap); + + offset += __offset_of(struct ModbusApHeader, UnitID) + mbap.Length; + //write("OnModbusReceive2: offset post = %d. %d <= %d?", offset, offset, size-8); + } + while(offset <= size-8); // We need at least 8 bytes for a new packet + //write("OnModbusReceive2: yes. finished", offset); + + if (offset != size) // Can be removed. + { + write("Error while going through receive buffer. Our final offset is %d, but the size of the buffer is %d!", offset, size); + runError(1002, 1); + } +} + +/// +void OnModbusReceive2OnePacket(byte buffer[], int offset, struct ModbusApHeader mbap) { // Test transaction identifier? // Test unit/device identifier? - char str[20*3]; - byte x[2]; - byte mbuffer[8192]; - dword i; - struct ModbusApHeader mbap; - - memcpy_n2h(mbap, buffer); + word i; // counter + word length; // length of current packet + byte mbuffer[__size_of(struct ModbusResReceiveRegisters)]; // second buffer where we copy the message. This way the user won't overwrite other packages. - if (size < 8) // No complete Modbus Application Header + length = __offset_of(struct ModbusApHeader, UnitID) + mbap.Length; + // We cannot check this properly anymore. We have to trust the TCP/UDP stack and the sender... *sigh* + if (elCount(buffer) < offset + length) // TCP packet not as large enough { - writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnModbusReceive Error: Tcp packet is too short: Length = %d", size); + writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Error: Modbus packet did not fit into Buffer: buffer length = %d, packet length = %d, offset = %d", elCount(buffer), __offset_of(struct ModbusApHeader, UnitID) + mbap.Length, offset); + // I REALLY don't want to assemble the two package fragments. + runError(1001,1); return; } - if (size != 6 + mbap.Length) // TCP packet not as large as specified in length field - { - writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnModbusReceive Error: Size of Tcp packet is incorrect: Length = %d, has to be %d", size, 6 + mbap.Length); - return; - } - if (mbap.Protocol != 0) // Protocol is not Modbus (0x0000) + if (mbap.Protocol != 0) // Protocol is not Modbus (0x0000). Wayne. { writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnModbusReceive Error: Tcp packet is no Modbus packet: Protocol = %d", mbap.Protocol); return; } // MBAP Header is OK :) Go on - - - if (mbap.FuncCode > 0x80) // Oh no, we got a exception! + + if (mbap.FuncCode > 0x80) // Oh no, we got a exception! { - switch(buffer[08]) // Let's have a look at the reason - { - case 0x01: // Illegal function code: Implementation failure! - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Illegal function code (0x01). The function code %d is unknown by the server.", buffer[7] & 0x0F); - return; - case 0x02: // Illegal data address: Configuration failure! - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Illegal data address (0x02). Please check your configuration!"); - return; - case 0x03: // Illegal data value: Depends. - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Illegal data value (0x03)."); - return; - case 0x04: // Server failure: We can't do anything about that, can we? - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Server failure (0x04). The server failed during execution."); - return; - case 0x05: // Acknowledge: That's ok. - writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Acknowledge (0x05). The server simply needs more time to generate the response."); - return; - case 0x06: // Server busy: We should resend the request. - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Server busy (0x06). The request could not be accepted."); - return; - case 0x0A: // Gateway problem: We don't have gateways :) - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Gateway problem (0x0A). Gateway paths not available."); - return; - case 0x0B: // Gateway problem: We don't have gateways :) - writeLineEx(0, 3, "<%BASE_FILE_NAME%> OnModbusReceive Exception: Gateway problem (0x0B). The targeted device failed to respond."); - return; - } + OnModbusReceive2Exceptions(buffer[offset+08], mbap); + return; } - // Extract the PDU for further processing - size -= 8; - for (i = 0; i < size; i++) - mbuffer[i] = buffer[i+8]; + // Copy the message + memcpy_off(mbuffer, 0, buffer, offset, length); // Let's give the PDU to the corresponding function switch (mbap.FuncCode) { case 0x01: case 0x02: - OnModbusReceiveBits(mbuffer, size); + OnModbusReceiveBits(mbuffer); break; case 0x03: case 0x04: - OnModbusReceiveRegisters(mbuffer, size); + OnModbusReceiveRegisters(mbuffer); break; case 0x05: - OnModbusConfirmBit(mbuffer, size); + OnModbusConfirmBit(mbuffer); + break; + case 0x06: + OnModbusConfirmRegister(mbuffer); break; case 0x0F: - OnModbusConfirmBits(mbuffer, size); + OnModbusConfirmBits(mbuffer); break; case 0x10: - OnModbusConfirmRegisters(mbuffer, size); + OnModbusConfirmRegisters(mbuffer); + break; + case 0x16: + OnModbusConfirmMasks(mbuffer); + break; + case 0x17: + OnModbusReceiveConfirmRegisters(mbuffer); + break; + default: + writeLineEx(0, 3, "We received funcCode 0x%X?", mbap.FuncCode); + } +} + +/// +void OnModbusReceive2Exceptions(byte exCode, struct ModbusApHeader mbap) +{ + enum ModbusException ex; + ex = (enum ModbusException)exCode; + switch(exCode) // Let's have a look at the reason + { + case 0x01: // Illegal function code: Implementation failure! + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Illegal function code (0x01). The function code %d is unknown by the server.", mbap.FuncCode & 0x0F); + break; + case 0x02: // Illegal data address: Configuration failure! + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Illegal data address (0x02). Please check your configuration!"); + break; + case 0x03: // Illegal data value: Depends. + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Illegal data value (0x03)."); + break; + case 0x04: // Server failure: We can't do anything about that, can we? + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Server failure (0x04). The server failed during execution."); + break; + case 0x05: // Acknowledge: That's ok. + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Exception: Acknowledge (0x05). The server simply needs more time to generate the response."); + break; + case 0x06: // Server busy: We should resend the request. + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Server busy (0x06). The request could not be accepted."); + break; + case 0x0A: // Gateway problem: We don't have gateways :) + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Gateway problem (0x0A). Gateway paths not available."); + break; + case 0x0B: // Gateway problem: We don't have gateways :) + writeLineEx(0, 3, "<%BASE_FILE_NAME%> Exception: Gateway problem (0x0B). The targeted device failed to respond."); + break; + } + + switch (mbap.FuncCode) + { + case 0x81: + case 0x82: + OnModbusReceiveBitsException(mbap, ex); + break; + case 0x83: + case 0x84: + OnModbusReceiveRegistersException(mbap, ex); + break; + case 0x85: + OnModbusConfirmBitException(mbap, ex); + break; + case 0x86: + OnModbusConfirmRegisterException(mbap, ex); + break; + case 0x8F: + OnModbusConfirmBitsException(mbap, ex); + break; + case 0x90: + OnModbusConfirmRegistersException(mbap, ex); + break; + case 0x96: + OnModbusConfirmMasksException(mbap, ex); + break; + case 0x97: + OnModbusReceiveConfirmRegistersException(mbap, ex); break; } } \ No newline at end of file diff --git a/Modbus/ModbusClientTCP.can b/Modbus/ModbusClientTCP.can index 2dd44f2..96c5d0d 100644 --- a/Modbus/ModbusClientTCP.can +++ b/Modbus/ModbusClientTCP.can @@ -7,7 +7,7 @@ includes variables { - msTimer muster; + msTimer muster, clock; byte gX[2] = {1, 0}; } @@ -16,7 +16,7 @@ variables on preStart { writeClear(0); - setStartdelay(1000); + setStartdelay(10); } on start @@ -47,23 +47,33 @@ void OnModbusWriteRegistersFailed(enum ModbusRequestError error, enum ModbusExce { } -void OnModbusReadBitsSuccess(byte result[]) + +void OnModbusReadBitsSuccess(struct ModbusResReceiveBits mbr, byte bitStatus[], word numBits) { + char str[20*2]; + + hbin_to_strhex(mbr.Data, str); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceiveBits: Received %d bits (in %d bytes): %s", numBits, mbr.ByteCount, str); } -void OnModbusReadRegistersSuccess(byte result[]) +void OnModbusReadRegistersSuccess(struct ModbusResReceiveRegisters mbr, word numRegs) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceiveRegisters: Received %d registers (%d bytes): %X %X %X %X...", mbr.ByteCount, mbr.Data[0], mbr.Data[1], mbr.Data[2], mbr.Data[3]); } -void OnModbusWriteBitSuccess(byte result[]) +void OnModbusWriteBitSuccess(struct ModbusResConfirmSingle mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmBit: Set bit 0x%X to %d", mbc.Address, (mbc.Value > 0 ? 1 : 0)); } -void OnModbusWriteRegisterSuccess(byte result[]) +void OnModbusWriteRegisterSuccess(struct ModbusResConfirmSingle mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmRegister: Set register 0x%X to %d", mbc.Address, mbc.Value); } -void OnModbusWriteBitsSuccess(byte result[]) +void OnModbusWriteBitsSuccess(struct ModbusResConfirmMultiple mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmBits: Set %d bits beginning with 0x%X", mbc.Count, mbc.Address); } -void OnModbusWriteRegistersSuccess(byte result[]) +void OnModbusWriteRegistersSuccess(struct ModbusResConfirmMultiple mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmRegisters: Set %d registers beginning with 0x%X", mbc.Count, mbc.Address); } @@ -132,11 +142,11 @@ on key '-' ModbusWriteBits(0, 16, x); } -on key 't' +on key 'z' { setTimerCyclic(muster, 100); } -on key 'T' +on key 'Z' { cancelTimer(muster); } @@ -167,4 +177,20 @@ on timer muster //ModbusReadBits(0, 512); } -/**/ +on key 't' +{ + setTimerCyclic(clock, 100); +} +on key 'T' +{ + clock.Cancel(); +} + +on timer clock +{ + byte s, x[2]; + s = (timeNow() / 100000) % 30; + x[0] = (s & 0x01) | (s & 0x02) | ((s & 0x04) << 1) | ((s & 0x08) << 4); + x[1] = (s & 0x10) << 3; + ModbusWriteBits(0, 16, x); +} diff --git a/Modbus/ModbusClientUDP.can b/Modbus/ModbusClientUDP.can index 60d6464..7b9ba60 100644 --- a/Modbus/ModbusClientUDP.can +++ b/Modbus/ModbusClientUDP.can @@ -7,8 +7,13 @@ includes variables { - msTimer muster; + char gNodeName[10] = "ClientUDP"; + + msTimer muster, clock; byte gX[2] = {1, 0}; + + enum MbClientState {INIT, ConfWago1, ConfWago2, ConfWago3, ConfWago4, DATA}; + enum MbClientState gState = INIT; } // Get information of local network interface such like ip address @@ -16,14 +21,18 @@ variables on preStart { writeClear(0); - setStartdelay(1000); + sysDefineNamespace("%NETWORK_NAME%::%BASE_FILE_NAME%::Info"); + sysDefineNamespace("%NETWORK_NAME%::%BASE_FILE_NAME%::Data"); + setStartdelay(10); } on start { - long fehler; - ModbusInit("192.168.1.3", 502); + + // Read serial code, additional stuff is done in OnModbusReceiveRegisters + gState = ConfWago1; + ModbusReadRegisters(0x2011, 1); } @@ -46,50 +55,110 @@ void OnModbusWriteBitsFailed(enum ModbusRequestError error, enum ModbusException void OnModbusWriteRegistersFailed(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 OnModbusReadBitsSuccess(byte result[]) + +void OnModbusReadBitsSuccess(struct ModbusResReceiveBits mbr, byte bitStatus[], word numBits) { + char str[20*2]; + + hbin_to_strhex(mbr.Data, str); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceiveBits: Received %d bits (in %d bytes): %s", numBits, mbr.ByteCount, str); } -void OnModbusReadRegistersSuccess(byte result[]) +void OnModbusReadRegistersSuccess(struct ModbusResReceiveRegisters mbr, word numRegs) { + char str[20*5]; + long fehler; + dbin_to_strhex(mbr.Data, str); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusReceiveRegisters: Received %d bytes: %s", mbr.ByteCount, str); + + switch (gState) + { + case ConfWago1: + sysDefineVariableInt("%NETWORK_NAME%::%BASE_FILE_NAME%::Info", "SerialCode", mbr.Data[0]); + gState = ConfWago2; + ModbusReadRegisters(0x2012, 1); + break; + case ConfWago2: + sysDefineVariableInt("%NETWORK_NAME%::%BASE_FILE_NAME%::Info", "DeviceCode", mbr.Data[0]); + gState = ConfWago3; + ModbusReadRegisters(0x2030, 1); + break; + case ConfWago3: + break; + default: + break; + } } -void OnModbusWriteBitSuccess(byte result[]) +void OnModbusWriteBitSuccess(struct ModbusResConfirmSingle mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmBit: Set bit 0x%X to %d", mbc.Address, (mbc.Value > 0 ? 1 : 0)); } -void OnModbusWriteRegisterSuccess(byte result[]) +void OnModbusWriteRegisterSuccess(struct ModbusResConfirmSingle mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmRegister: Set register 0x%X to %d", mbc.Address, mbc.Value); } -void OnModbusWriteBitsSuccess(byte result[]) +void OnModbusWriteBitsSuccess(struct ModbusResConfirmMultiple mbc) { + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmBits: Set %d bits beginning with 0x%X", mbc.Count, mbc.Address); } -void OnModbusWriteRegistersSuccess(byte result[]) +void OnModbusWriteRegistersSuccess(struct ModbusResConfirmMultiple mbc) +{ + writeLineEx(0, 1, "<%BASE_FILE_NAME%> OnModbusConfirmRegisters: Set %d registers beginning with 0x%X", mbc.Count, mbc.Address); +} +void OnModbusWriteMasksSuccess(struct ModbusResConfirmMasks mbc) { } // Key events ------------------------------------------------------------------------- -on key 'r' +on key 'i' // read the configuration { - ModbusReadBits(0, 512); +} +on key 'r' // read the first bits +{ + ModbusReadBits(0, 51); +} +on key 'R' // read constant registers +{ + ModbusReadRegisters(0x2000, 8); } -on key 'a' +on key 'a' // set left bar { byte x[16] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; ModbusWriteBitsB(0, 16, x); } +on key 'A' // read the output bits +{ + ModbusReadBits(0x200, 16); +} -on key 's' +on key 's' // set right bar { byte x[16] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; ModbusWriteBitsB(0, 16, x); } -on key 'Y' +on key 'e' // write register +{ + ModbusWriteRegister(0, 0x5555); +} +on key 'E' // read register +{ + ModbusWriteRegister(0, 0); +} + +on key 'Y' // write bit on { ModbusWriteBit(0, 0); } -on key 'y' +on key 'y' // write bit off { ModbusWriteBit(0, 1); } @@ -121,22 +190,22 @@ on key 'v' ModbusWriteBit(3, 1); } -on key '+' +on key '+' // set all bits on { byte x[2] = {0xFF, 0xFF}; ModbusWriteBits(0, 16, x); } -on key '-' +on key '-' // set all bits off { byte x[2] = {0x00, 0x00}; ModbusWriteBits(0, 16, x); } -on key 't' +on key 'z' // start timer muster { setTimerCyclic(muster, 100); } -on key 'T' +on key 'Z' // stop timer muster { cancelTimer(muster); } @@ -167,4 +236,20 @@ on timer muster //ModbusReadBits(0, 512); } -/**/ +on key 't' // show clock on output +{ + setTimerCyclic(clock, 1000); +} +on key 'T' // show clock on output +{ + clock.Cancel(); +} + +on timer clock +{ + byte s, x[2]; + s = (timeNow() / 100000) % 30; + x[0] = (s & 0x01) | (s & 0x02) | ((s & 0x04) << 1) | ((s & 0x08) << 4); + x[1] = (s & 0x10) << 3; + ModbusWriteBits(0, 16, x); +} diff --git a/Modbus/ModbusCommonStructs.cin b/Modbus/ModbusCommonStructs.cin new file mode 100644 index 0000000..d13daec --- /dev/null +++ b/Modbus/ModbusCommonStructs.cin @@ -0,0 +1,122 @@ +/*@!Encoding:1252*/ +variables +{ + // A normal Modbus Application Header. Every Modbus Packet begins with these 7 (+FuncCode) Bytes + _align(1) struct ModbusApHeader + { + word TxID; + word Protocol; + word Length; + byte UnitID; + byte FuncCode; + }; + // Read Data from the host. We only need the start address and the number of bits/registers we want to read + _align(1) struct ModbusReqRead + { + struct ModbusApHeader Header; + word Address; + word Count; + }; + // Write a single value to a bit/register + _align(1) struct ModbusReqWriteSingle + { + struct ModbusApHeader Header; + word Address; + word Value; + }; + // Write several values to a bit/register starting with Address + _align(1) struct ModbusReqWriteBits + { + struct ModbusApHeader Header; + word Address; + word Count; + byte ByteCount; + byte Data[246]; // Max length: 1968 bits + }; + // Write several values to bits starting with Address + _align(1) struct ModbusReqWriteRegisters + { + struct ModbusApHeader Header; + word Address; + word Count; + byte ByteCount; + word Data[123]; // Max length: 123 registers + }; + // Write AND and OR masks to a holding register + _align(1) struct ModbusReqWriteMasks + { + struct ModbusApHeader Header; + word Address; + word And; + word Or; + }; + // Read and write multiple registers + _align(1) struct ModbusReqReadWriteRegisters + { + struct ModbusApHeader Header; + word ReadAddress; + word ReadCount; + word WriteAddress; + word WriteCount; + byte ByteCount; + word Data[121]; // Max length: 123-2 registers + }; + + + // Receive several bit values + _align(1) struct ModbusResReceiveBits + { + struct ModbusApHeader Header; + byte ByteCount; + byte Data[250]; // Max length: 2000 bits + }; + // Receive several register values + _align(1) struct ModbusResReceiveRegisters + { + struct ModbusApHeader Header; + byte ByteCount; + word Data[125]; // Max length: 125 registers + }; + // Confirm the write of a single bit/register + _align(1) struct ModbusResConfirmSingle + { + struct ModbusApHeader Header; + word Address; + int Value; + }; + // Confirm the write of several bits/registers + _align(1) struct ModbusResConfirmMultiple + { + struct ModbusApHeader Header; + word Address; + word Count; + }; + // Confirm the write of AND and OR mask + _align(1) struct ModbusResConfirmMasks + { + struct ModbusApHeader Header; + word Address; + word And; + word Or; + }; + + + + enum ModbusRequestError + { + Exception, + Timeout + }; + enum ModbusException + { + None = 0x00, + IllegalFuncCode = 0x01, + IllegalDataAddress = 0x02, + IllegalDataValue = 0x03, + ServerFailure = 0x04, + Acknowledge = 0x05, + ServerBusy = 0x06, + GatewayPathsNA = 0x0A, + TargetOffline = 0x0B + }; +} \ No newline at end of file diff --git a/Modbus/TcpCommon.cin b/Modbus/TcpCommon.cin index 1e85748..36aa71a 100644 --- a/Modbus/TcpCommon.cin +++ b/Modbus/TcpCommon.cin @@ -34,19 +34,19 @@ word TcpOpenSocket() if (gSocket.GetLastSocketError() != 0) { gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText)); - writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, gSocket.GetLastSocketError()); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Tcp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, gSocket.GetLastSocketError()); } } while (gSocket.GetLastSocketError() != 0 && i++ < 9); if (gSocket.GetLastSocketError() != 0) { - writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket!"); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Tcp socket!"); return gSocket.GetLastSocketError(); } else { - writeLineEx(0, 1, "<%NODE_NAME%> Tcp socket opened on %s:%d.", Local_IP, localPort); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Tcp socket opened on %s:%d.", Local_IP, localPort); } return 0; @@ -60,7 +60,7 @@ word TcpConnectTo(char Remote_IP[], word remotePort) remoteIp = IpGetAddressAsNumber(Remote_IP); if (remoteIp == INVALID_IP) { - writeLineEx(0, 1, "<%NODE_NAME%> Error: invalid server Ip address!"); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: invalid server Ip address!"); return 1; } @@ -91,7 +91,7 @@ word TcpConnectTo(dword remoteIp, word remotePort) if (fehler != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise { - write("<%NODE_NAME%> No Port-Connection: %d", fehler); + write("<%BASE_FILE_NAME%> No Port-Connection: %d", fehler); gSocketState = ERROR; return fehler; } @@ -99,7 +99,7 @@ word TcpConnectTo(dword remoteIp, word remotePort) } else { - writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server"); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Successfully connected to server"); gSocketState = OK; return 0; } @@ -110,13 +110,13 @@ void OnTcpConnect(dword socket, long result) if (result != 0) { gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr)); - writeLineEx(0, 2, "<%NODE_NAME%> OnTcpConnect error (%d): %s", gSocket.GetLastSocketError(), gIpLastErrStr); + writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpConnect error (%d): %s", gSocket.GetLastSocketError(), gIpLastErrStr); gSocketState = ERROR; return; } else { - writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server"); + writeLineEx(0, 1, "<%BASE_FILE_NAME%> Successfully connected to server"); gSocketState = OK; } } @@ -140,7 +140,7 @@ void TcpRecv() if (gIpLastErr != WSA_IO_PENDING) // Calling OnTcpReceive otherwise { gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr)); - writeLineEx(0, 2, "<%NODE_NAME%> TcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr); + writeLineEx(0, 2, "<%BASE_FILE_NAME%> TcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr); gSocket.Close(); gSocketState = CLOSED; } @@ -151,7 +151,7 @@ void TcpRecv() void TcpSnd(byte buffer[], word length) { - char str[20*3]; + //char str[20*3]; switch (gSocketState) { @@ -159,18 +159,18 @@ void TcpSnd(byte buffer[], word length) TcpConnectTo(gRemoteIP, gRemotePort); if (gSocketState != OK) { - writeLineEx(0, 2, "TcpSnd: Reconnecting failed!"); + writeLineEx(0, 2, "<%BASE_FILE_NAME%> TcpSnd: Reconnecting failed!"); return; } case OK: break; default: - writeLineEx(0, 2, "TcpSnd: Socket status is not OK!"); + writeLineEx(0, 2, "<%BASE_FILE_NAME%> TcpSnd: Socket status is not OK!"); return; } - bin_to_strhex(buffer, str); - writeLineEx(0, 1, "<%NODE_NAME%> TcpSnd: %s (Länge: %d)", str, length); + //bin_to_strhex(buffer, str); + //writeLineEx(0, 1, "<%BASE_FILE_NAME%> TcpSnd: %s (Länge: %d)", str, length); if (gSocket.Send(buffer, length) != 0) { @@ -179,7 +179,7 @@ void TcpSnd(byte buffer[], word length) if (gIpLastErr != WSA_IO_PENDING) { gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr)); - writeLineEx(0, 2, "<%NODE_NAME%> TcpSnd error (%d): %s", gIpLastErr, gIpLastErrStr); + writeLineEx(0, 2, "<%BASE_FILE_NAME%> TcpSnd error (%d): %s", gIpLastErr, gIpLastErrStr); gSocket.Close(); gSocketState = CLOSED; } diff --git a/Modbus/TcpUdpCommon.cin b/Modbus/TcpUdpCommon.cin index 173c2b7..a095fb9 100644 --- a/Modbus/TcpUdpCommon.cin +++ b/Modbus/TcpUdpCommon.cin @@ -29,7 +29,7 @@ dword SetupIp(char Local_IP[]) long error; adapterCount = IpGetAdapterCount(); - adapterIndex = @sysvar::TCPIP::AdapterIndex; + adapterIndex = @sysvar::Config::TcpIp::AdapterIndex; switch (adapterCount) { diff --git a/Modbus/UdpCommon.cin b/Modbus/UdpCommon.cin index ef261cb..a4f952a 100644 --- a/Modbus/UdpCommon.cin +++ b/Modbus/UdpCommon.cin @@ -116,7 +116,7 @@ void UdpRecv() void UdpSnd(byte buffer[], word length) { - char str[20*3]; + //char str[20*3]; switch (gSocketState) { @@ -134,8 +134,8 @@ void UdpSnd(byte buffer[], word length) return; } - bin_to_strhex(buffer, str); - writeLineEx(0, 1, "<%BASE_FILE_NAME%> UdpSnd: %s (Länge: %d)", str, length); + //bin_to_strhex(buffer, str); + //writeLineEx(0, 1, "<%BASE_FILE_NAME%> UdpSnd: %s (Länge: %d)", str, length); if (gSocket.SendTo(gRemoteIP, gRemotePort, buffer, length) != 0) { diff --git a/Modbus/modbus.cfg b/Modbus/modbus.cfg index a56433f..d195149 100644 --- a/Modbus/modbus.cfg +++ b/Modbus/modbus.cfg @@ -1,17 +1,17 @@ -;CANoe Version |4|7|1|42336 modbus +;CANoe Version |4|7|1|42353 modbus Version: 8.2.40 Build 40 32 PRO 10 -APPDIR Vector.CANoe.SignalGenerators.DLL -Vector.CANoe.SignalGenerators, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null -Vector.CANoe.SignalGenerators.ComponentWrapper -1 -1.0.1 APPDIR Vector.CANoe.Debugger.DLL Vector.CANoe.Debugger, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null Vector.CANoe.Debugger.DebuggerComponent -2 +1 1.0.0 +APPDIR Vector.CANoe.SignalGenerators.DLL +Vector.CANoe.SignalGenerators, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null +Vector.CANoe.SignalGenerators.ComponentWrapper +2 +1.0.1 VGlobalConfiguration 1 Begin_Of_Object 17 VGlobalParameters 2 Begin_Of_Object @@ -56,7 +56,7 @@ Version 5 DialogBegin 1 -497 1104 1028 1638 +493 746 1024 1280 SymbolExplorerDialogBegin 1 @@ -416,16 +416,18 @@ VCaplOptionsStreamer 3 Begin_Of_Object End_Of_Object VCaplOptionsStreamer 3 VSVConfigurationStreamer 3 Begin_Of_Object 1 -1394 +1461 - - - - - - + + + + + + + + @@ -526,7 +528,7 @@ NValueObjectDisplay::VNameDisplaySettings 3 Begin_Of_Object 0 4 1 -4 +6 2 4 3 @@ -695,11 +697,11 @@ Begin_Of_Multi_Line_String Copyright (c) 2001-2006 Actipro Software LLC. All rights reserved. http://www.ActiproSoftware.com/Products/DotNet/ ---> kPersistNoLineBreak -14911-9568-49CC-A9CE-3B0905658C4A}" Guid="db27ffca-d17e-40f0-a70b-be70fe5eb4ec" State="DockableInsideHost" DockedSize="381, 0" FloatingLocation="1151, 79" FloatingSize="300, 180"> + End_Of_Serialized_Data 3 End_Of_Object VDesktop 3 VDesktop 3 Begin_Of_Object @@ -1333,37 +1335,9 @@ Grafik-Fenster 237 0 0 -1 0 0 0 --11 -0 -0 -0 -0 -0 -0 -0 -400 -0 -Tahoma -0 -1 -0 -0 -0 --11 -0 -0 -0 -34 -0 -0 -0 -400 -0 -Tahoma 0 1 1 @@ -1547,7 +1521,7 @@ End_Of_Serialized_Data 14 6 1 14 -ver=2: FT TF TF FF FT FT;F T GLLogger;F T Modbus;F T TCPIP;T F _Statistics +ver=2: FT TF TF FF FT FT;F T Config;F T Ethernet;F T GLLogger;T F _Statistics;F T sysvar End_Of_Serialized_Data 14 7 0 @@ -1573,7 +1547,10 @@ End_Of_Serialized_Data 14 16 0 17 -0 +1 +14 +ver=2: FT +End_Of_Serialized_Data 14 18 0 19 @@ -2596,8 +2573,8 @@ End_Of_Object VTNColumnData 16 VTNColumnData 16 Begin_Of_Object 3 6 -65 --1 +29 +7 Payload Length 1 0 @@ -2608,7 +2585,7 @@ VTNColumnData 16 Begin_Of_Object 3 7 433 -8 +9 Payload Data 1 0 @@ -2829,7 +2806,7 @@ End_Of_Object VTNColumnData 16 VTNColumnData 16 Begin_Of_Object 3 27 -32 +28 6 Packet Length 1 @@ -3083,7 +3060,7 @@ VTNColumnData 16 Begin_Of_Object 3 50 185 -7 +8 Payload Data ASCII 1 0 @@ -3448,7 +3425,7 @@ End_Of_Serialized_Data 14 J:\Public\Documents\Vector\CANwin\Public\Documents\Vector\CANwin 8.0.918\templates End_Of_Serialized_Data 14 0 -1627403825 +0 1 1 14 @@ -3825,7 +3802,7 @@ VDataBox 14 Begin_Of_Object VBoxRoot 15 Begin_Of_Object 1 1 -1 2 0 1 -1 -1 -1 -1 480 46 1157 263 +1 1 2 3 -1 -1 -8 -30 480 46 1157 263 1 @@ -3833,15 +3810,15 @@ MDI_DOCK_INFO_END 5 1 6 -0 1 -1 -1 -1 -1 480 46 1157 263 +2 3 -1 -1 -8 -30 480 46 1157 263 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 -0 -2 +1 +1 0 0 1 -1188 901 +963 382 END_OF_DESKTOP_DATA 6 0 1 0 0 -1 -1 238 146 956 584 @@ -3864,13 +3841,13 @@ End_Of_Object VBoxRoot 15 End_Of_Object VDataBox 14 1 6 -8 +4 VSysVarObject 14 Begin_Of_Object 1 VHostSignal 15 Begin_Of_Object 2 3 -TcpServerPort +Ethernet::ModbusClientUDP.can::Info::IP 0 End_Of_Object VHostSignal 15 14 @@ -3885,20 +3862,20 @@ VConfigSysVar 18 Begin_Of_Object VConfigEvent 19 Begin_Of_Object 1 End_Of_Object VConfigEvent 19 -TCPIP -TcpServerPort +Ethernet::ModbusClientUDP.can::Info +IP End_Of_Object VConfigSysVar 18 End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 -1 -0 +2 End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 End_Of_Serialized_Data 14 End_Of_Object VSysVarObject 14 [Begin_of_Item] 2 1 -1 1 2 0 0 16777215 +1 8 2 0 0 16777215 -1000 1000 -1000 0 [End_of_Item] VSysVarObject 14 Begin_Of_Object @@ -3906,7 +3883,7 @@ VSysVarObject 14 Begin_Of_Object VHostSignal 15 Begin_Of_Object 2 3 -TcpClientData +Ethernet::ModbusClientUDP.can::Info::Port 0 End_Of_Object VHostSignal 15 14 @@ -3921,91 +3898,19 @@ VConfigSysVar 18 Begin_Of_Object VConfigEvent 19 Begin_Of_Object 1 End_Of_Object VConfigEvent 19 -TCPIP -TcpClientData +Ethernet::ModbusClientUDP.can::Info +Port End_Of_Object VConfigSysVar 18 End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 -1 -0 +2 End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 End_Of_Serialized_Data 14 End_Of_Object VSysVarObject 14 [Begin_of_Item] 2 2 -1 8 2 0 0 16777215 --1000 1000 -1000 0 -[End_of_Item] -VSysVarObject 14 Begin_Of_Object -1 -VHostSignal 15 Begin_Of_Object -2 -3 -TcpClientIp -0 -End_Of_Object VHostSignal 15 -14 -ValueObjectConfiguration::VConfiguredSysVar 15 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 Begin_Of_Object -1 -VConfigSysVar 18 Begin_Of_Object -1 -VConfigEvent 19 Begin_Of_Object -1 -End_Of_Object VConfigEvent 19 -TCPIP -TcpClientIp -End_Of_Object VConfigSysVar 18 -End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 -End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 --1 -0 -End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 - -End_Of_Serialized_Data 14 -End_Of_Object VSysVarObject 14 -[Begin_of_Item] -2 5 -1 8 2 0 0 16777215 --1000 1000 -1000 0 -[End_of_Item] -VSysVarObject 14 Begin_Of_Object -1 -VHostSignal 15 Begin_Of_Object -2 -3 -TcpClientPort -0 -End_Of_Object VHostSignal 15 -14 -ValueObjectConfiguration::VConfiguredSysVar 15 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 Begin_Of_Object -1 -VConfigSysVar 18 Begin_Of_Object -1 -VConfigEvent 19 Begin_Of_Object -1 -End_Of_Object VConfigEvent 19 -TCPIP -TcpClientPort -End_Of_Object VConfigSysVar 18 -End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 -End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 --1 -0 -End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 - -End_Of_Serialized_Data 14 -End_Of_Object VSysVarObject 14 -[Begin_of_Item] -2 6 1 1 2 0 0 16777215 -1000 1000 -1000 0 [End_of_Item] @@ -4014,7 +3919,7 @@ VSysVarObject 14 Begin_Of_Object VHostSignal 15 Begin_Of_Object 2 3 -TcpData +Ethernet::ModbusClientUDP.can::Info::SerialCode 0 End_Of_Object VHostSignal 15 14 @@ -4029,121 +3934,13 @@ VConfigSysVar 18 Begin_Of_Object VConfigEvent 19 Begin_Of_Object 1 End_Of_Object VConfigEvent 19 -TCPIP -TcpData +Ethernet::ModbusClientUDP.can::Info +SerialCode End_Of_Object VConfigSysVar 18 End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 -1 -0 -End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 - -End_Of_Serialized_Data 14 -End_Of_Object VSysVarObject 14 -[Begin_of_Item] -2 7 -1 8 2 0 0 16777215 --1000 1000 -1000 0 -[End_of_Item] -VSysVarObject 14 Begin_Of_Object -1 -VHostSignal 15 Begin_Of_Object 2 -3 -TcpServerIp -0 -End_Of_Object VHostSignal 15 -14 -ValueObjectConfiguration::VConfiguredSysVar 15 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 Begin_Of_Object -1 -VConfigSysVar 18 Begin_Of_Object -1 -VConfigEvent 19 Begin_Of_Object -1 -End_Of_Object VConfigEvent 19 -TCPIP -TcpServerIp -End_Of_Object VConfigSysVar 18 -End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 -End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 --1 -0 -End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 - -End_Of_Serialized_Data 14 -End_Of_Object VSysVarObject 14 -[Begin_of_Item] -2 8 -1 8 2 0 0 16777215 --1000 1000 -1000 0 -[End_of_Item] -VSysVarObject 14 Begin_Of_Object -1 -VHostSignal 15 Begin_Of_Object -2 -3 -Connect_IP -0 -End_Of_Object VHostSignal 15 -14 -ValueObjectConfiguration::VConfiguredSysVar 15 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 Begin_Of_Object -1 -VConfigSysVar 18 Begin_Of_Object -1 -VConfigEvent 19 Begin_Of_Object -1 -End_Of_Object VConfigEvent 19 -TCPIP -Connect_IP -End_Of_Object VConfigSysVar 18 -End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 -End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 --1 -0 -End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 - -End_Of_Serialized_Data 14 -End_Of_Object VSysVarObject 14 -[Begin_of_Item] -2 4 -1 8 2 0 0 16777215 --1000 1000 -1000 0 -[End_of_Item] -VSysVarObject 14 Begin_Of_Object -1 -VHostSignal 15 Begin_Of_Object -2 -3 -Connect_Port -0 -End_Of_Object VHostSignal 15 -14 -ValueObjectConfiguration::VConfiguredSysVar 15 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 Begin_Of_Object -1 -ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 Begin_Of_Object -1 -VConfigSysVar 18 Begin_Of_Object -1 -VConfigEvent 19 Begin_Of_Object -1 -End_Of_Object VConfigEvent 19 -TCPIP -Connect_Port -End_Of_Object VConfigSysVar 18 -End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 -End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 --1 -0 End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 End_Of_Serialized_Data 14 @@ -4153,7 +3950,43 @@ End_Of_Object VSysVarObject 14 1 1 2 0 0 16777215 -1000 1000 -1000 0 [End_of_Item] -20 150 16 169 75 75 50 100 100 100 1 +VSysVarObject 14 Begin_Of_Object +1 +VHostSignal 15 Begin_Of_Object +2 +3 +Ethernet::ModbusClientUDP.can::Info::DeviceCode +0 +End_Of_Object VHostSignal 15 +14 +ValueObjectConfiguration::VConfiguredSysVar 15 Begin_Of_Object +1 +ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 Begin_Of_Object +1 +ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 Begin_Of_Object +1 +VConfigSysVar 18 Begin_Of_Object +1 +VConfigEvent 19 Begin_Of_Object +1 +End_Of_Object VConfigEvent 19 +Ethernet::ModbusClientUDP.can::Info +DeviceCode +End_Of_Object VConfigSysVar 18 +End_Of_Object ValueObjectConfiguration::Detail::AbstractConfiguredValueObject 17 +End_Of_Object ValueObjectConfiguration::Detail::VConfiguredValueObjectBase 16 +-1 +2 +End_Of_Object ValueObjectConfiguration::VConfiguredSysVar 15 + +End_Of_Serialized_Data 14 +End_Of_Object VSysVarObject 14 +[Begin_of_Item] +2 4 +1 1 2 0 0 16777215 +-1000 1000 -1000 0 +[End_of_Item] +20 308 16 169 75 75 50 100 100 100 1 35 35 30 1 1 0 1 0 0 1 1 1 0 1 @@ -4292,7 +4125,7 @@ VUniqueBox 4 Begin_Of_Object VBoxRoot 5 Begin_Of_Object 1 3 -0 0 2 3 -1 -1 -8 -30 0 0 890 487 +0 0 0 1 -1 -1 -8 -30 0 0 890 487 1 @@ -4300,7 +4133,7 @@ MDI_DOCK_INFO_END 5 1 6 -2 3 -1 -1 -8 -30 0 0 890 487 +0 1 -1 -1 -8 -30 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 @@ -4308,7 +4141,7 @@ END_OF_DOCK_INFO 0 0 1 -1188 382 +963 382 END_OF_DESKTOP_DATA 6 0 1 0 0 -1 -1 44 44 1544 1005 @@ -4359,7 +4192,7 @@ End_Of_Object VGrMnBox 3 VDOLocalInfoStruct 3 Begin_Of_Object 3 1 -108 +143 VDAOBus 4 Begin_Of_Object 1 1 @@ -4511,9 +4344,9 @@ VProgrammedNode 7 Begin_Of_Object VConfigurationRoot 8 Begin_Of_Object 1 End_Of_Object VConfigurationRoot 8 - 1 "ClientUDP.can" + 1 "ModbusClientUDP.can" 1 -J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus\ClientUDP.cbf +J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus\ModbusClientUDP.cbf << default >> 5 @@ -4549,7 +4382,7 @@ EOF_MBSSDATA EOF_NLDATA 0 EOF_ASSEMBLYDATA - 1 "ClientUDP.cbf" + 1 "ModbusClientUDP.cbf" VIPBStackSetting 8 Begin_Of_Object 3 0 @@ -4601,12 +4434,7 @@ End_Of_Object VIPBStackSetting 8 NDebugger::VDebuggerHost 8 Begin_Of_Object 2 0 -8 -NDebugger::VFile 9 Begin_Of_Object -1 - 1 "Common.cin" -4 -End_Of_Object NDebugger::VFile 9 +9 NDebugger::VFile 9 Begin_Of_Object 1 1 "ModbusTcpCommon.cin" @@ -4619,21 +4447,6 @@ NDebugger::VFile 9 Begin_Of_Object End_Of_Object NDebugger::VFile 9 NDebugger::VFile 9 Begin_Of_Object 1 - 1 "TcpUdpCommon.cin" -9 -End_Of_Object NDebugger::VFile 9 -NDebugger::VFile 9 Begin_Of_Object -1 - 1 "UdpCommon.cin" -10 -End_Of_Object NDebugger::VFile 9 -NDebugger::VFile 9 Begin_Of_Object -1 - 1 "ClientUDP.can" -11 -End_Of_Object NDebugger::VFile 9 -NDebugger::VFile 9 Begin_Of_Object -1 1 "ModbusClientCommon.cin" 12 End_Of_Object NDebugger::VFile 9 @@ -4642,6 +4455,31 @@ NDebugger::VFile 9 Begin_Of_Object 1 "ModbusUdpClientCommon.cin" 13 End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "ModbusClientUDP.can" +14 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "Common.cin" +15 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "TcpUdpCommon.cin" +16 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "UdpCommon.cin" +17 +End_Of_Object NDebugger::VFile 9 +NDebugger::VFile 9 Begin_Of_Object +1 + 1 "ModbusCommonStructs.cin" +18 +End_Of_Object NDebugger::VFile 9 VNETStandaloneComponent 9 Begin_Of_Object 1 VNETControlBox 10 Begin_Of_Object @@ -4652,7 +4490,7 @@ VBoxRoot 12 Begin_Of_Object 1 3 1 -1 2 3 -1 -1 -8 -30 171 76 688 306 -Debugger - ClientUDP +Debugger - ModbusClientUDP 1 MDI_DOCK_INFO_END @@ -4718,7 +4556,7 @@ End_Of_Object VUniqueBox 11 1 -1 0 0 0 0 0 0 0 0 0 0 0 End_Of_Object VNETControlBox 10 -132 +144 APPDIR Vector.CANoe.Debugger.DLL Vector.CANoe.Debugger, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null Vector.CANoe.Debugger.DebuggerComponent @@ -4760,34 +4598,46 @@ TypeRef:3 3 Int32 NrOfFiles -4 +6 Int32 FileID0 -11 +14 Int32 CurrentLine0 0 Int32 FileID1 -4 +15 Int32 CurrentLine1 0 Int32 FileID2 -9 +12 Int32 CurrentLine2 0 Int32 FileID3 -10 +13 Int32 CurrentLine3 0 Int32 +FileID4 +16 +Int32 +CurrentLine4 +0 +Int32 +FileID5 +17 +Int32 +CurrentLine5 +0 +Int32 SelectedFileID -11 +14 Int32 NrOfWatchedVariables 0 @@ -4874,7 +4724,7 @@ VSimulinkModelViewerConfiguration 7 Begin_Of_Object End_Of_Object VSimulinkModelViewerConfiguration 7 1 0 -2490614275 +545021141 0 NodeSignalPanelBustypeCount 0 End_Of_Object VSimulationNode 6 @@ -4899,9 +4749,9 @@ VProgrammedNode 7 Begin_Of_Object VConfigurationRoot 8 Begin_Of_Object 1 End_Of_Object VConfigurationRoot 8 - 1 "ClientTCP.can" + 1 "ModbusClientTCP.can" 1 -J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus\ClientTCP.cbf +J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus\ModbusClientTCP.cbf << default >> 5 @@ -4911,7 +4761,7 @@ EOF_TITLE_INFO << default >> 1 0 -1 +2 1 0 1 @@ -4932,12 +4782,12 @@ SS_END_COMMON_INFO EOF_MBSSDATA 1 -0 1 +0 0 0 EOF_NLDATA 0 EOF_ASSEMBLYDATA - 1 "ClientTCP.cbf" + 1 "ModbusClientTCP.cbf" VIPBStackSetting 8 Begin_Of_Object 3 0 @@ -5006,7 +4856,7 @@ VSimulinkModelViewerConfiguration 7 Begin_Of_Object End_Of_Object VSimulinkModelViewerConfiguration 7 1 0 -2653277962 +2476798878 0 NodeSignalPanelBustypeCount 0 End_Of_Object VSimulationNode 6 @@ -5039,7 +4889,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 @@ -5116,106 +4966,8 @@ EOF_MBSSDATA 1 0 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -5226,6 +4978,104 @@ EOF_MBSSDATA + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + End_Of_Object VSSPlugInConfiguration 6 NULL @@ -5393,7 +5243,7 @@ NULL End_Of_Object VDOLocalInfoStruct 3 0.000000 0 0 -1 1 0 59420 1 233 1 2882400001 90 323 305 689 2882400002 0 0 0 0 0 0 1 2882400001 1278 1278 307 307 2882400002 0 0 0 361415696 361661552 7670396 3 +1 1 0 59420 1 233 1 2882400001 323 556 335 786 2882400002 0 0 0 0 0 0 1 2882400001 1197 1197 337 337 2882400002 0 0 0 344227128 344230248 344808852 3 SS_BEGIN_COMMON_INFO 1 0 @@ -5405,7 +5255,7 @@ Ethernet 11 1 1 -7639664 1 0 0 0 1 1 0 0 0 2000 1 +344891952 1 0 0 0 1 1 0 0 0 2000 1 SS_BEGIN_COMMON_INFO 1 2 @@ -5514,7 +5364,7 @@ End_Of_Serialized_Data 2 End_Of_Object VWriteBox 2 VWinStore 2 Begin_Of_Object 1 -22 2 3 -1 -1 -1 -1 -10088 -10000 -9070 -9233 +22 2 3 -32088 -32000 -1 -1 -10088 -10000 -9070 -9233 End_Of_Child_List End_Of_Object VWinStore 2 VWinStore 2 Begin_Of_Object @@ -5790,10 +5640,10 @@ FiltersBegin Begin 3 0 0 2 -Busstatistik Signale - ( 1 ( 0 ) 0 ) Netzwerke ( 0) +Busstatistik Signale + ( 1 ( 0 ) 0 ) SymbSelHeaderMgrBegin 1 6 0 1 200 0 0 @@ -5805,10 +5655,10 @@ SymbSelHeaderMgrBegin SymbSelHeaderMgrEnd End Begin -3 0 7 +3 0 37 1 Systemvariablen - ( 1 ( 1 ( 0 ) 0 ) 0 ) + ( 1 ( 1 ( 0 ) 0 ) 2 ( 1 ( 0 ) 2 ( 0 ) 0 ) 3 ( 1 ( 1 ( 0 ) 0 ) 0 ) 0 ) SymbSelHeaderMgrBegin 1 4 0 1 200 0 0 @@ -5833,7 +5683,7 @@ FiltersEnd END_OF_WORKSPACE_MEMBER_DATA END_OF_WORKSPACE_MEMBER 1 -0 +1 0 END_OF_WORKSPACE_DATA