MichaluxPL / Sofar_LSW3

Get MODBUS data from Sofar (K-TLX) inverter through LSW-3 or LSE module
GNU General Public License v3.0
99 stars 47 forks source link

'charmap' codec can't decode byte 0x81 in position 7950: character maps to <undefined> #6

Closed k0201 closed 3 years ago

k0201 commented 3 years ago

Hi! Glad to see that someone did figure out how does protocol v5 works. I tried it on my inverter and I am getting such message:

Chunk no:  0
Sent data:  bytearray(b'\xa5\x17\x00\x10E\x00\x00\xe1,\x1ah\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00(E\xd4\x00\x15')
Received data:  b'\xa5c\x00\x10\x15\x00\x03\xe1,\x1ah\x02\x01\x0f\xa6/\x00H\x00\x00\x00\x00\x00\x00\x00\x01\x03P\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x128\x02\x81\x11\xf6\x02w\x01+\x01"\x028\xff\xbe\x13\x89\t$\x03-\t0\x03-\t\x1e\x03,\x00\x00\x07\xf9\x00\x00\x03V\x05\x01\x01(\x00*\x001\x19\x01\x12*\x11\xf2\x00<\x00\x00\x00\x01\x00\x00\x04\x9e\x0b\x02\t\x10\x00\x0ce=\xd9\x15'
Traceback (most recent call last):
  File "C:\Users\Lenovo\Documents\Sofar_LSW3-main\InverterData.py", line 156, in <module>
    parameters=json.loads(txtfile.read())
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python39-32\lib\encodings\cp1250.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 7950: character maps to <undefined>

The LWS serial numer is 174654****, FW: LSW3_14_FFFF_1.0.34 Inverter type is SF4ES008 (Sofar 8.8KTL-X) V2.40 I did try it on Windows with python 3.9.0 but can also check on linux later.

If you have any ideas what should I change to make it work I would be glad to hear them :D Thanks!

k0201 commented 3 years ago

Changing line 155 to with open("./SOFARMap.xml", encoding="utf8") as txtfile: Did solve the problem, i suppose changing it in the repo is a good idea.

MichaluxPL commented 3 years ago

Glad to hear that :) Don't know if changing it permanently in the code is a good idea - encoding can be OS dependent ... Maybe a better solution would be to add config parameter to change it as required :) I'll thing about that.

k0201 commented 3 years ago

I have added a pull request with CSV file saving support in which i harcoded the encoding

MichaluxPL commented 3 years ago

Please fork Your own project for that. Don't want to add a foreign code to this one.