-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception: packet byte count does not match bytes in packet! count: 4, actual: 3 #61
Comments
so. this PLC response is If we decode this into modbus packet fields it would be
'register data' field should be 4 bytes not 3. 'quantity' => 2 means that response should contain 2 registers data and each register is 16 bit, 2 bytes length. does request fail for all just to be sure.
|
Wow, you're fast! :) Thankx... Just to be shure that we didn't hunt a ghost: There is a binary data respone, therefore it can't be anything else e.g. network, firewall, etc., righ? It's just unexpected/too short. I tried many different addresses, for the example I've choosen one with simple result data. Unfortunately the part with "Parsed packet (in hex):" isn't reached reproducable, the exception comes earlier... I tried it with the cool qmodmaster - was a good hint, I didn't know this helpfull tool. It provides data for IP / ID / Address /Quantity: Busmonitor qmodmaster: |
use this block to get what is sent with PHP
looking at the busmonitor example
is Request for 2 registers (last 2 bytes is quantity
and response is 2 registers (4 bytes |
I tried it with code from public static function parseResponse($binaryString): ModbusResponse
The 5th line And with your code snippet:
The 3rd line provides no echo anymore as it throws the exception |
So response is transaction id = What version of this library are you using? add echo/or logging just after this line
have you ever used Wireshark (https://www.wireshark.org/) for packet inspection? |
I installed it yesterday with composer. Where do I see the Version. The library code adjustment I'm going to do... |
composer holds library versions in |
composer.lock:
|
I tried your code change...
Wireshark: I know, what it is, but I never used it. Sorry. But shouldn't be the output of QModMaster sufficent? |
This is really strange. even for lowest level of PHP only 3 bytes are returned I really have no idea what is going on. Could you tell me what OS and PHP version you are using? I'll try to replicate with mock modbus server. |
just to single out if PHP is the problematic part maybe you would run modbus slave simulator on your workstation an https://www.modbustools.com/download.html download not that it would fix your problem, but it would be useful to diagnose where problem lies |
CentOS 7:
PHP Of course, I will try the simulator. I'd really like to understand what's the reason for this problem... |
ok, seems you are on Linux. This maybe is better simulator for Linux https://www.modbusdriver.com/diagslave.html downloadit, unpack and run (on port 1502. binding to port 502 need sudo/root access)
|
Linux-Server-Park, but Windows on Workstations... :) I allready installed the Simulator on windows: Set to ID3, same Adress, Value 52. Test your library with coding above:
Value Change in Simulator to 50
=> OK My conclusion by now:
Do we want to investigate what it is? Maybe it worth, as SMA sells a lot power inverter for photovoltaics. May be it's only my installation, I don't know. |
If you have time and patience it would be nice to see what is actually send on ethernet level with packet inspection. On linux maybe using TCPDUMP
|
No problem...ok, tcdump now... :)
last request and output with PHP
and tcdump of the same request - it seems to me that the request was sent twice, the 2nd comes to the output
Maybe a wrong endian? SMA docs says, they use "big-endian". |
Just to be sure that it is not an Issue with my network, server or device: I just installed my old solution with another/old library on the same server in the same context in parallel. For the same address I get data; therefore it is really an issue of the your library requestig the data from SMA power inverter devices. I would really be glad to switch over to your library; I will try to support the investigation. By now I've no idea how to find the reason and I hope my tcdump-data helps to give you an idea. In the best case it's just an endian or codepage issue. |
I can not be endian problem. Request bytes are valid (500a 0000 0006 0303 787d 0002 is perfectly ok packet).
but response arrives with missing last 1 byte as TCPDUMP shows
maybe it is PHP version specific problem with php's streams TCP implementation. I assume that your older library is using PHP ext_sockets extension?
|
I don't know how the other library works, sorry.
Coding I used (according to FC4-example)
|
5.) tcdump with the old library (adduc/phpmodbus)
|
ok, seems packet is fragmented and last fragment is disregarded. I'll try to create dev branch and add some more logic to fread() method to get more packets if it knows it should have more |
sounds good, thank you |
@gutschein could you try changing 1 line in library code. In file vendor/aldas/modbus-tcp-client/src/Network/StreamHandler.php
to
maybe this is all we need. |
I changed the line to ... but same result - sorry.
|
@gutschein hei, this is late response but try this this is slightly modified receive part - it tries to read until expected amount of bytes is received or timeout is reached.
|
Hej, And....it looks good now! :)
|
nice. I'll add this fix to BinaryStreamConnection internals and publish a new release. |
great. Thank you. |
@gutschein could you try this branch #63 ? |
of course....but to be honest: Using git (main) is fine. Change specific code in a file like above: fine. :) |
If think for compose change compose.json
as this branch seems to already visible in packagagist versions list (https://packagist.org/packages/aldas/modbus-tcp-client#dev-issue_61_fixes) and do |
fastest way would be to clone repo and run fc3.php example with your settings
|
I will try, but I'm really busy these days... sorry. Probably next weekend |
sorry...still very busy in my customer projects...I will try, but probably next weekend ~ 25.09. |
It took some time to find time to check again... sorry. But I'm back now to connect my devices finally with your library. Great job! Convenient and simple to use. Thank you. |
Hi,
coming from an other library I tried to move to your modern solution. Unfortunately my first step wasn't successfull. Probaly I just used something wrong and appreciate your support:. Device is an SMA power inverter.
I get this exception:
I would expect an value for that register: 27
The text was updated successfully, but these errors were encountered: