cole8888 / SRNE-Solar-Charge-Controller-Monitor

Read data from SRNE solar charge controllers.
22 stars 4 forks source link

MobusIOException object has no attribute 'registers' #18

Closed magorm closed 9 months ago

magorm commented 10 months ago

Getting the error 'has no attribute registers' when running SolarMonitor.py. Need your help :-)

cole8888 commented 10 months ago

What charge controller are you using and how have you connected to it?

Can you try replacing the line containing read_holding_registers with response = modbus.read_holding_registers(256, 35, unit=1, slave=255).

If your charge controller address is different than mine this will fix it.

magorm commented 10 months ago

Thanks so much. May I know the version of pymodbus you're using? Here is how I connected SNRE SCC to my Laptop running the Python script: x drawio

magorm commented 10 months ago

What charge controller are you using and how have you connected to it?

Can you try replacing the line containing read_holding_registers with response = modbus.read_holding_registers(256, 35, unit=1, slave=255).

If your charge controller address is different than mine this will fix it.

Did not work. I think the issue is related to USB adapter?

cole8888 commented 10 months ago

Which USB adapter are you using? It might not use the right voltage.

cole8888 commented 10 months ago

Also, can you show how you wired the serial adapter up to the RJ12 cable?

magorm commented 10 months ago

Which USB adapter are you using? It might not use the right voltage.

I am using this adapter: USB to TTL converter UART module CH340G CH340 3.3V 5V switch

magorm commented 10 months ago

Also, can you show how you wired the serial adapter up to the RJ12 cable?

![Uploading solar-monitor.png…]()

cole8888 commented 10 months ago

The CH340G won't work, it only does +/-5V where RS232 needs +/-13V.

You'll need to use a usb to RS232 converter like this one: https://www.amazon.ca/StarTech-com-USB-Serial-Adapter-Prolific/dp/B00GRP8EZU

Also, I can't see that image so I'm not sure how you wired it up to your charge controller.

magorm commented 10 months ago

The CH340G won't work, it only does +/-5V where RS232 needs +/-13V.

You'll need to use a usb to RS232 converter like this one: https://www.amazon.ca/StarTech-com-USB-Serial-Adapter-Prolific/dp/B00GRP8EZU

Also, I can't see that image so I'm not sure how you wired it up to your charge controller.

Thanks. Apologies. Here's the connection diagram. Untitled Diagram drawio

magorm commented 10 months ago

The CH340G won't work, it only does +/-5V where RS232 needs +/-13V.

You'll need to use a usb to RS232 converter like this one: https://www.amazon.ca/StarTech-com-USB-Serial-Adapter-Prolific/dp/B00GRP8EZU

Also, I can't see that image so I'm not sure how you wired it up to your charge controller.

If I use Raspberry Pi, is the Pi serial using +-13v? Thanks in advance.

cole8888 commented 10 months ago

The Pi is not using that voltage. In my demo it has to go through a breakout board with a MAX3232 on it which handles the voltage boost to talk to the charge controller.

cole8888 commented 10 months ago

You can see it here: https://github.com/cole8888/SRNE-Solar-Charge-Controller-Monitor/blob/main/RaspberryPi-Examples/RaspberryPi-Overview.jpg

magorm commented 10 months ago

MAX3232

Thanks. Will try this board, see if it will work - https://shopee.ph/MAX3232-RS232-to-TTL-Serial-Port-Converter-Module-DB9-Connector-MAX232-For-Arduino-i.226548939.4317808086

cole8888 commented 9 months ago

@magorm Did you get it to work?

magorm commented 9 months ago

Not yet. I already setup the raspberry pi zero 2w, made the code run but I think I bought a wrong RS232 adapter. I already ordered the board (https://www.digikey.ph/en/products/detail/mikroelektronika/MIKROE-602/4495610) similar to what you used. Hopefully I can make it work.

Question: from RS232 adapter going to RJ12 (charge controller), I only have to use tx, rx and gnd connection, right?

magorm commented 9 months ago

IMG_1261

cole8888 commented 9 months ago

Yes, you only need rx, tx, and gnd coming from the charge controller.

I've never had much luck getting the dupont cables to make good contact with the DB9 port, so make sure you have good a good connection there.

You can also try swapping around the positions of the yellow and green wires connected to the Pi and the DB9 connector.

magorm commented 9 months ago

Hi. How did you get the register address? In the code its 256, not sure if it the same with SRNE charge controller?

cole8888 commented 9 months ago

I'm using SRNE charge controllers, which ones are you using?

I got it from the SRNE modbus datasheet

magorm commented 9 months ago

I'm using SRNE charge controllers, which ones are you using?

I got it from the SRNE modbus datasheet

Thanks. I am using the same SCC, specifically ML2440 model.

cole8888 commented 9 months ago

I have that one also, so you definitely should be able to get it to work with it :)

magorm commented 9 months ago

I have that one also, so you definitely should be able to get it to work with it :)

In rj12, did you use pin1 (tx), pin2 (rx) and pin3(gnd)? pin4 is also gnd but not sure if I should use it instead of pin3?

cole8888 commented 9 months ago

It should work either way. I only used pin 3 for ground.

magorm commented 9 months ago

Hi @cole8888 , for RJ12, the pin 1 is from the left side, right?

IMG_1267

magorm commented 9 months ago

This is the log when I run the script; it is sending 0xff 0x3 0x1 0x0 0x0 0x23 0x10 0x31? Connection : True DEBUG:pymodbus.logging:Current transaction state - IDLE DEBUG:pymodbus.logging:Running transaction 1 DEBUG:pymodbus.logging:SEND: 0xff 0x3 0x1 0x0 0x0 0x23 0x10 0x31 DEBUG:pymodbus.logging:New Transaction state "SENDING" WARNING:pymodbus.logging:Cleanup recv buffer before send: 0x0 0x0 0x0 DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY" DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY" DEBUG:pymodbus.logging:RECV: 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 DEBUG:pymodbus.logging:Processing: 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 DEBUG:pymodbus.logging:Getting transaction 255 DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE" Failed to read data, reconnecting... 'ModbusIOException' object has no attribute 'registers'

cole8888 commented 9 months ago

Yes, that's pin one and it is the charge controller tx pin. Here is the pinout: https://github.com/cole8888/SRNE-Solar-Charge-Controller-Monitor/blob/main/Charge-Controller-Connector-Pinout.png

Can you replace the line containing read_holding_registers with response = modbus.read_holding_registers(256, 35, unit=1, slave=255).

This will eliminate any address issues.

Can you follow the steps in this guide to make sure the serial port is enabled in raspi-config: https://pimylifeup.com/raspberry-pi-serial/

Also, can you send a picture of how you've got everything wired everything up now?

magorm commented 9 months ago

For the DB9, its 2(rx), 3(tx) and 5(gnd)?

cole8888 commented 9 months ago

Black (controller rx) goes to pin 2, White (controller tx) goes to pin 3, red (controller gnd) goes to pin 5.

Remember that the pin numbers reverse when comparing the male/female connectors: url(1)

magorm commented 9 months ago

Here's my connection. Not sure if the problem is the RJ12? BTW, I am using pymodbus v3.5.4

Untitled Diagram drawio (1)

magorm commented 9 months ago

Yellow - Tx, Green - Rx, Black - Gnd, Red - Vcc

pi2 pi

magorm commented 9 months ago
Screenshot 2023-12-12 at 12 23 29 AM
magorm commented 9 months ago

slave=255

Screenshot 2023-12-12 at 12 25 03 AM
magorm commented 9 months ago

Serial Enablement: I am using /dev/ttyS0

Screenshot 2023-12-12 at 12 27 54 AM
cole8888 commented 9 months ago

It looks like your RX and TX are flipped compared to my photo. Try doing this: image

magorm commented 9 months ago

I was able to make it work! Thanks so much @cole8888 ! You are right the problem is wrong connection.

Screenshot 2023-12-12 at 5 12 53 PM