Created
October 6, 2016 07:57
-
-
Save taotao/0038b4b1f420954cd3d58d72115d8a2f to your computer and use it in GitHub Desktop.
Use pymodbus to access modbus rtu device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pymodbus.client.sync import ModbusSerialClient | |
import logging | |
logging.basicConfig() | |
log = logging.getLogger() | |
log.setLevel(logging.DEBUG) | |
client = ModbusSerialClient(method='rtu', port='/dev/ttyM0', baudrate=38400, parity='N', bytesize=8, stopbits=1, timeout=1) | |
client.connect() | |
rd = client.read_discrete_inputs(1, 1, unit=1) | |
print (repr(rd.bits)) | |
client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment