cannot reading holding register

2,995 views
Skip to first unread message

Heming Liu

unread,
Sep 18, 2013, 7:26:19 PM9/18/13
to pymo...@googlegroups.com
when i do

result = client.read_holding_registers(0, 1, unit = 1)
print result.registers[0]


i get "nonetype" object has no attribute registers

this means my read is not returning anything or is it something wrong with my libraries.

same thing happens when i do

result = client.write_register(0, 0X00FF, unit = 1)
print result.registers[0]

thanks


Galen Collins

unread,
Sep 18, 2013, 7:45:36 PM9/18/13
to pymo...@googlegroups.com
Can you attach your full script so I can see how you are setting up your connection?


--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Heming Liu

unread,
Sep 18, 2013, 8:44:19 PM9/18/13
to pymo...@googlegroups.com
my pymodbus master code is like this
#!/usr/bin/python2.4
import time, serial
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.transaction import ModbusRtuFramer



client = ModbusClient(port = '/dev/ttyS2', retries = 1000,  method = 'ascii', f\
ramer = ModbusRtuFramer, baudrate = 38400, stopbits = 1, parity = 'N', bytesize\
 = 8, timeout = 10)

socket = serial.Serial(port='/dev/ttyS2', baudrate=38400, bytesize=8, parity = \
'N', stopbits = 1, rtscts = True)
val = client.connect()

if not val:
    print "Error in Client Connection"
socket.setRTS(False)
result = client.read_holding_registers(0, 200, unit=1)
print result
client.close()






so my arduino slave code is like this

enum {
        MB_SLAVE = 1,    /* modbus slave id */
};
/* slave registers example */
enum {       
        MB_REG0,
        MB_REGS         /* total number of registers on slave */
};

int regs[MB_REGS];    /* this is the slave's modbus data map */

void setup()
{
        /* Modbus setup example, the master must use the same COM parameters */
        /* 115200 bps, 8N1, two-device network */
        configure_mb_slave(38400, 'n', 2);
        pinMode(3, OUTPUT);
        pinMode(1, OUTPUT);
        pinMode(0, INPUT);
}


void loop()
{
        /* This is all for the Modbus slave */
        unsigned int Txenpin = 2;
    update_mb_slave(MB_SLAVE, regs, MB_REGS);
        if(Serial.available()){
          digitalWrite(Txenpin,HIGH);
          regs[0] = Serial.print("PowerOne");
          Serial.write(regs[0]);
        }
        if(!Serial.available()){
          digitalWrite(Txenpin,LOW);
        }
}


thank you very much for  helping

Heming Liu

unread,
Sep 19, 2013, 8:45:18 PM9/19/13
to pymo...@googlegroups.com
please help,

the problem is that read register doesn't return anything.

why it keeps returning none i don't get it.

Galen Collins

unread,
Sep 19, 2013, 11:24:12 PM9/19/13
to pymo...@googlegroups.com

Can you do a quick test with the modpoll utility (you can Google for it) and see if you can get a valid response.

Heming Liu

unread,
Sep 20, 2013, 6:40:23 PM9/20/13
to pymo...@googlegroups.com
it doesn't work, is it because i'm losing some utility functions?

the main problem is the read holding register method doesn't return anything
should i reinstall pymodbus?

or do other stuff

Galen Collins

unread,
Sep 20, 2013, 6:51:30 PM9/20/13
to pymo...@googlegroups.com
Well the thing I was hoping to figure out is if your device is actually attached and working correctly.  Although I can easily check in the library if you are able to connect to a serial file descriptor (and the library does), I can't really tell if something is on the other end or not.  As such, most every serial connect call is just going to work and never give any errors.

What I would like to see is if you can play with the parameter permutations using modpoll (http://www.modbusdriver.com/modpoll.html) and see if you can find the correct settings.  If you cannot get your application to work using this tool, then I will not be able to help you with pymodbus.  Once you have the correct settings and report them back, I can get up to speed on helping you out.

Also, what modbus server library are you using on your arduino?

Galen

Heming Liu

unread,
Sep 20, 2013, 7:21:31 PM9/20/13
to pymo...@googlegroups.com
right now i'm just trying example codes, and it's still not working.

i'm using synchronous client and asynchronous slave, connected by RS485 ports
exactly using the example code

#!/usr/bin/python2.4


from pymodbus.client.sync import ModbusSerialClient as ModbusClient
#from pymodbus.client.sync import ModbusTcpClient as ModbusClient
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

#client = ModbusClient('localhost', port=502)
client = ModbusClient(method='rtu', port='/dev/ttyS2', timeout=10)
client.connect()

rr = client.read_holding_registers(1,3)
print rr.registers

client.close()

And for the slave:


#!/usr/bin/python2.4

from pymodbus.server.async import StartTcpServer
from pymodbus.server.async import StartUdpServer
from pymodbus.server.async import StartSerialServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
from pymodbus.transaction import ModbusRtuFramer, ModbusAsciiFramer

import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

store = ModbusSlaveContext(
    di = ModbusSequentialDataBlock(1, [15,16,21,23]))
context = ModbusServerContext(slaves=store, single=True)

identity = ModbusDeviceIdentification()
#StartTcpServer(context, identity=identity, address=("localhost", 502))
StartSerialServer(context, identity=identity, port='/dev/ttyS2', framer=ModbusR\
tuFramer)

the  arduino slave i'm using is this one https://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-slave

thank you for looking into this and helping me.

Heming Liu

unread,
Sep 20, 2013, 8:52:23 PM9/20/13
to pymo...@googlegroups.com
i think i have the correct settings

my slave has

StartSerialServer(context, identity=identity, port='/dev/ttyS2', framer=ModbusRtuFramer, stopbits = 2, bytesize = 8, parity = 'N', baudrate = 38400)

and my Modpoll master command is

./modpoll -c 3 -t 4 -b 38400 -p none -d 8 -s 2 -o 10 /dev/ttyS2
this is giving me read timeout constantly,

is it correct to use slave address of 1, start reference of one on the Modpoll?

thanks

Heming


On Friday, September 20, 2013 3:51:30 PM UTC-7, Bashwork wrote:

Heming Liu

unread,
Sep 23, 2013, 2:09:07 PM9/23/13
to pymo...@googlegroups.com
i mean if i'm using RS-485, does the write read holding registers functions automatically enable/disable RTS/CTS?

otherwise how should i set my RTS, the client.read_holding_registers sends a request to the slave, so it should be high, and then i should set it low to get a response? but is it quick enough.

also the server starts, it needs to get a request and send a response back to the client, so its RTS should be False and True .

how do i do that or do i need to do that at all.

Galen Collins

unread,
Sep 23, 2013, 10:20:35 PM9/23/13
to pymo...@googlegroups.com

I don't know what is correct to do in your situation.  The best I can do is pull out one of my arduinos and try yo get a sketch working. I'll try tonight if I get time, otherwise I can try tomorrow.  How are you connecting your arduino to your Dev box?

Message has been deleted

Heming Liu

unread,
Sep 24, 2013, 12:01:03 AM9/24/13
to pymo...@googlegroups.com
it is through a RS-485 breakout board like this one https://www.sparkfun.com/products/10124
the ground connection is not connected.. like one of the senior engineer told me to, but i think i should connect the ground connections..anyways. currently it is not connected.

and then the linux system i'm using is CentOs with python version 2.4.2.. not sure if the python version is affecting my code. the RS-485 pinout only connects A and B pinout through twisted 28 gauge wires to the breakout boards A and B, i have no pull up or pull down resistors because the linux box supposedly have them, also do not have termination resistors because the RS-485 breakout board includes it i think. and then on the other side the pins are connected to 5V power, ground to ground, TX pin to Arduino's RXpin, and Rx pin to Arduino's TXpin, and then the RTS enable pin connected to Pin 2 on the arduino.

the weird thing is that using modpoll i'm getting like chesum errors when i try to read from arduino, and getting reply timeout when reading from another same Linux box using pymodbus. 
when i try to using Client_Read_holding_registers it is giving me none all the time. 

Thank you so much for helping me out.

Heming Liu

unread,
Sep 25, 2013, 7:44:30 PM9/25/13
to pymo...@googlegroups.com
Does anyone know how I how enable and disable RTS for the client and server?

like once the Server starts how do I enable or disable RTS
the RTS must be enabled to send, and disabled to receive

thanks
Reply all
Reply to author
Forward
0 new messages