-
Testing with a FC4 request i noticed that some of the values returned are wrong, we try also with several modbus windows clients. With FC3 all is fine. Anyone has any idea where can be the problem? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 25 replies
-
FC3 and FC4 are pretty much exactly the same on packet level. See this Example FC4 response: Example FC3 response: Are you deducing that values are wrong because with different modbus clients the returned values are different compared to other clients? |
Beta Was this translation helpful? Give feedback.
-
I would suggest trying to use wireshark or network sniffing tool like that and see if packets that are send are different (except transaction id part). See https://github.com/aldas/modbus-tcp-client/wiki/Debugging-guide#capture-network-traffic-to-see-what-is-actually-sendreceived |
Beta Was this translation helpful? Give feedback.
-
So with this library fc4 example when you set For example Modpoll https://www.modbusdriver.com/modpoll.html has option
note: |
Beta Was this translation helpful? Give feedback.
-
Im starting over, with the example fc4 script, only edited the ip address i get this error: Packet to be sent (in hex): 8a5d00000006000400090001 F:\www\modbus\vendor\aldas\modbus-tcp-client\src\Network\BinaryStreamConnectionBuilder.php(31): ModbusTcpClient\Network\InternetDomainStreamCreator->createStream() #1 |
Beta Was this translation helpful? Give feedback.
-
Your response is printed as byte pairs (not register values)
Register is 16 bit of memory. 16bit is 2 bytes. So if we would combine bytes from that output we would get this
This line prints raw bytes. print_r($response->getData()); To print register values as (int16?) you would need to use: foreach ($response->asWords() as $word) {
print_r($word->getInt16());
}
// or
foreach ($response as $word) {
print_r($word->getInt16());
} I strongly recommend checking and trying this example https://github.com/aldas/modbus-tcp-client/blob/master/examples/index.php this showcases how raw bytes from response can be used/converted to almost any type |
Beta Was this translation helpful? Give feedback.
-
Well, that fixed it, so many thanks. now i get almost everithing, just left one probe that give me this error: An exception occurred Illegal data address #0 F:\www\modbus\vendor\aldas\modbus-tcp-client\examples\fc4.php(39): ModbusTcpClient\Packet\ResponseFactory::parseResponseOrThrow() #1 {main} |
Beta Was this translation helpful? Give feedback.
-
last detail: Packet to be sent (in hex): 565200000006090400000008 0 In the hex chain, i get b594 that is 46484 why in getInt16() translate it to -19052? |
Beta Was this translation helpful? Give feedback.
FC3 and FC4 are pretty much exactly the same on packet level. See this
Example FC4 response:
modbus-tcp-client/src/Packet/ModbusFunction/ReadInputRegistersResponse.php
Line 11 in c39a0e5
Example FC3 response:
modbus-tcp-client/src/Packet/ModbusFunction/ReadHoldingRegistersResponse.php
Line 20 in c39a0e5
Are you deducing that values are wrong because with different modbus clients the returned values are different compared to other clients?