-
Notifications
You must be signed in to change notification settings - Fork 960
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
Specify encoding when decoding registers to string #2555
Comments
Pull requests are welcome, we use utf-8 because it is the most generic one, and please be aware that it is actually not really used, since the byte value is used directly. What is your problem exactly ? |
Please be aware you are not forced to use the convert functions, you can easily do it in the app. Btw saw the app is actually a custom component of HA, which means you are using a pretty old version of pymodbus (due to the component modbus) where among others the convert functions work quite differently. |
Thanks for the quick response! I used My user has a starting byte of 0x80, which isn't ASCII nor UTF-8, so I need latin-1 extended ASCII specifically. I can create a PR for this.
Not exactly sure how it works, but I can specify a required version of pymodbus and it will get that for me. I'm running on the latest version currently. |
Interesting, if you can use multiple versions of the same lib. Did you actually check either pip what is installed ? The python builtin decode function needs a character type like utf-8, if there is a "raw" or similar I quest that would be the best change.....we do our best to avoid extra parameters. |
Just checked someone updated ha pymodbus version to 3.8.3, which is why you do not have problems. |
I basically need to have a |
A better solution would be to add "errors='ignore'" to the decode call, which should solve all your problems. |
I don't think this would solve my problem. I need the If you don't like the parameter, I can parse the bytes outside of your lib as you said, but I felt it would be cleaner to provide a way to configure it on your end. |
A parameter with a correct default, would be accepted, please remember to add test cases (e.g. what happens if parameter="raw"). |
When calling
convert_from_registers
withdata_type=DATATYPE.STRING
, the encodingutf-8
is used.Please parameterize this encoding so that it works with other text encoding formats (such as
latin-1
in my case).The text was updated successfully, but these errors were encountered: