Skip to content

Making it work into RS232 #29

Open
@tomascrespo

Description

@tomascrespo

Hi Frakkkkk!

I have read your code and it is great

I would like to make it work through RS232 because my Pylon are using RS485 interface to communicate with my inversor.

As far as I know Pylontech RS485 protocol and RS232 are almost the same, but I am not completly sure.

My batteries communicate with RS232 with BatteryView (Pylontech software) perfectly, using and RS232 to USB adapter connected to console port.

I think the first step is putting the serial port in 1200 bps, because this is the default for Pylontech RS232 (although they could go faster setting them up with a specific command)

Before I deep more into this I want to know if someone has tried before or your knowledge, if it is possible or not

Lots of thanks

Let's start!

Changing only the baud rate from 115200 to 1200 and adding some print for debug (same port, /dev/ttyUSB0)

----> Sending:  b'~20024642E002FFFD09\r'
7e3230303234363432453030324646464430390d
<---- Receiving:  b'~200146900000FDAA\r'
7e323030313436393030303030464441410d
Traceback (most recent call last):
  File "/home/pi/python-pylontech/tommy_test.py", line 4, in <module>
    print(p.get_values())
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 277, in get_values
    d = self.get_values_fmt.parse(f.info[1:])
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 288, in parse
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 300, in parse_stream
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 312, in _parsereport
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 2120, in _parse
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 312, in _parsereport
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 2653, in _parse
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 312, in _parsereport
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 1041, in _parse
  File "/usr/local/lib/python3.10/site-packages/construct-2.10.68-py3.10.egg/construct/core.py", line 91, in stream_read
construct.core.StreamError: Error in path (parsing) -> NumberOfModules
stream read less than specified amount, expected 1, found 0

Error parsing number of modules... 🤔 So now I have changed the address from 2 to 1 in get_values():
From this:

 def get_values(self):
        self.send_cmd(**2**, 0x42, b'FF')

To this

 def get_values(self):
        self.send_cmd(**1**, 0x42, b'FF')

No what I get is:

----> Sending:  b'~20014642E002FFFD0A\r'
7e3230303134363432453030324646464430410d
<---- Receiving:  b'~20014600B0D800020F0CF70C\r\n'
7e3230303134363030423044383030303230463043463730430d0a
Traceback (most recent call last):
  File "/home/pi/python-pylontech/tommy_test.py", line 4, in <module>
    print(p.get_values())
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 274, in get_values
    f = self.read_frame()
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 204, in read_frame
    f = self._decode_hw_frame(raw_frame=raw_frame)
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 183, in _decode_hw_frame
    assert got_frame_checksum == int(frame_chksum, 16)
AssertionError

🤔 I think we have not caught the full response. So I updated the timeout from 2 to 3. Now I get:

----> Sending:  b'~20014642E002FFFD0A\r'
7e3230303134363432453030324646464430410d
<---- Receiving:  b'~20014600B0D811020F0CF70CF60CF70CF70CF70CF80CF70CF70CF70CF70CF80CF50CF40CF60CF7050BA50B870B870B870B87FFEEC274B5A402C35000010F0CF50CF60CF60CF50CF70CF60CF70CF70CF60CF~20024692E00202FD2E\r6050B9B0B870B870B870B87FFEDC268BF6802C350027FCC3A\r\r\r\n'
7e323030313436303042304438313130323046304346373043463630434637304346373043463730434638304346373043463730434637304346373043463830434635304346343043463630434637303530424135304238373042383730423837304238374646454543323734423541343032433335303030303130463043463530434636304346363043463530434637304346363043463730434637304346363043467e3230303234363932453030323032464432450d363035304239423042383730423837304238373042383746464544433236384246363830324333353030323746434333410d0d0d0a
Traceback (most recent call last):
  File "/home/pi/python-pylontech/tommy_test.py", line 4, in <module>
    print(p.get_values())
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 274, in get_values
    f = self.read_frame()
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 204, in read_frame
    f = self._decode_hw_frame(raw_frame=raw_frame)
  File "/home/pi/python-pylontech/pylontech/pylontech.py", line 183, in _decode_hw_frame
    assert got_frame_checksum == int(frame_chksum, 16)
AssertionError

This response looks quite longer, but same error. I am thinking in changing the self.s.read() for something like read_until('\r') or something similar, I mean reading until certain byte value, to detect the end of the frame and avoid receiving garbage. What do you think? Have you seen something I can not see?

I would like learning to break down the response. I have read the protocol PDF but I will need some detailed example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions