Hello,
I want to read device data through modbus (TTL-RS485 module) communication using raspberry pi for this I write this python code.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import pymodbus
import serial
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(15, GPIO.OUT)
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
client = ModbusClient(method='rtu', port='/dev/ttyAMA0', timeout=1, stopbits = 1, bytesize = 8, parity='N', baudrate= 38400)
client.connect()
while True:
temp = client.read_holding_registers(address=1, count=1, unit=1);
print temp.registers[0] / 100;
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When i run this code i getting error..
True
Traceback (most recent call last):
File "pro.py", line 14, in
temp = client.read_input_registers(address=1009, count=2, unit=0x01);
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
return self.execute(request)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 108, in execute
return self.transaction.execute(request)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 140, in execute
full=full
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 207, in _transact
size = self._send(packet)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 224, in _send
return self.client.framer.sendPacket(packet)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/framer/rtu_framer.py", line 276, in sendPacket
size = self.client.send(message)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 77, in send
return self._send(request)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 512, in _send
waitingbytes = self._in_waiting()
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 494, in _in_waiting
waitingbytes = getattr(self.socket, in_waiting)()
File "/home/pi/.local/lib/python2.7/site-packages/serial/serialutil.py", line 590, in inWaiting
return self.in_waiting
File "/home/pi/.local/lib/python2.7/site-packages/serial/serialposix.py", line 467, in in_waiting
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
IOError: [Errno 25] Inappropriate ioctl for device
Hello, I want to read device data through modbus (TTL-RS485 module) communication using raspberry pi for this I write this python code. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' import pymodbus import serial import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(15, GPIO.OUT) from pymodbus.client.sync import ModbusSerialClient as ModbusClient client = ModbusClient(method='rtu', port='/dev/ttyAMA0', timeout=1, stopbits = 1, bytesize = 8, parity='N', baudrate= 38400) client.connect() while True: temp = client.read_holding_registers(address=1, count=1, unit=1); print temp.registers[0] / 100; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' When i run this code i getting error.. True Traceback (most recent call last): File "pro.py", line 14, in
temp = client.read_input_registers(address=1009, count=2, unit=0x01);
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
return self.execute(request)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 108, in execute
return self.transaction.execute(request)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 140, in execute
full=full
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 207, in _transact
size = self._send(packet)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 224, in _send
return self.client.framer.sendPacket(packet)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/framer/rtu_framer.py", line 276, in sendPacket
size = self.client.send(message)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 77, in send
return self._send(request)
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 512, in _send
waitingbytes = self._in_waiting()
File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 494, in _in_waiting
waitingbytes = getattr(self.socket, in_waiting)()
File "/home/pi/.local/lib/python2.7/site-packages/serial/serialutil.py", line 590, in inWaiting
return self.in_waiting
File "/home/pi/.local/lib/python2.7/site-packages/serial/serialposix.py", line 467, in in_waiting
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
IOError: [Errno 25] Inappropriate ioctl for device