Closed smarthome-abc closed 8 months ago
Are you sure a baudrate of 38400 is correct? AFAIK the default for Xcom-232 is 115200.
The error message essentially says, that it did not receive any data on the serial bus (b''
is empty).
It is correct, 38400 is default for xcom 232i, and I configured xcom232i to 38400.
I just tested another library, that is working -
DEBUG - TX: AA 00 01 00 00 00 2D 01 00 00 0A 00 38 26 00 01 01 00 3A 0C 00 00 01 00 48 A1
DEBUG - RX: AA 16 2D 01 00 00 01 00 00 00 0E 00 52 D4 02 01 01 00 3A 0C 00 00 01 00 00 00 80 43 0D 20
DEBUG - TX: AA 00 01 00 00 00 2D 01 00 00 0A 00 38 26 00 01 01 00 3B 0C 00 00 01 00 49 A7
DEBUG - RX: AA 16 2D 01 00 00 01 00 00 00 0E 00 52 D4 02 01 01 00 3B 0C 00 00 01 00 00 C0 C4 44 13 F3
Xtender Version: 1.6.38
I am still testing though
if it's too much hassle, please ignore, I think I have solved for my use case
It would help a lot to enable debug logging by adding logging.basicConfig(level=logging.DEBUG)
to your code to see if any data is even transferred.
I know that the package implementation is correct, been using it for over 4 years now myself.
Thanks, I will try to debug and fix for my system. The serial response itself is empty.
DEBUG:XcomRS232:requesting value Datapoint(id=3081, name='AC_POWER_IN_CURR_DAY', type='FLOAT', unit='kWh')
DEBUG:XcomRS232: --> aa0001000000650000000a006f7100010100090c00000d0023930d0a
DEBUG:XcomRS232: <--
Traceback (most recent call last):
File "/root/xcom.py", line 7, in <module>
soc = xcom.getValue(param.AC_ENERGY_IN_CURR_DAY, dstAddr=101)
File "/usr/lib/python3.10/site-packages/xcom_proto/XcomAbs.py", line 43, in getValue
response: Package = self.sendPackage(request)
File "/usr/lib/python3.10/site-packages/xcom_proto/XcomRS232.py", line 33, in sendPackage
retPackage = Package.parseBytes(response[:-len(SERIAL_TERMINATOR)])
File "/usr/lib/python3.10/site-packages/xcom_proto/protocol.py", line 167, in parseBytes
return Package.parse(BytesIO(buf))
File "/usr/lib/python3.10/site-packages/xcom_proto/protocol.py", line 153, in parse
assert sb == Package.start_byte, f"invalid package start byte ({sb})"
AssertionError: invalid package start byte (b'')
yeah as I thought, the incoming data is empty, so there is something wrong with your serial setup or there is another application already listening on the same socket and reading the incoming data instead.
If the data sent were invalid, I would at least expect either garbage data or an error package.
Thanks for your help, I will check and debug
@smarthome-abc have you tried setting the Baudrate to 115200?
I was able to reproduce your situation, where using the default 38400 baud in the configurator didn't work for me either. Weirdly enough despite that setting in the configurator, it still used 115200 baud.
What am I doing wrong, is this a quick fix?
Using
xcom = XcomRS232(serialDevice="/dev/ttyUSB0", baudrate=38400)