Skip to content

Instantly share code, notes, and snippets.

@jfach
Created August 24, 2017 02:18
Show Gist options
  • Save jfach/97620f1a28bf830b6c49b1ccb4f33497 to your computer and use it in GitHub Desktop.
Save jfach/97620f1a28bf830b6c49b1ccb4f33497 to your computer and use it in GitHub Desktop.
import minimalmodbus
import sys
SERIAL_PORT = '/'
DEVICE_ADDRESS = 1
DECIMAL_COUNT = 1
def modbus_RTU():
try:
device = minimalmodbus.Instrument(SERIAL_PORT, DEVICE_ADDRESS)
r1_value = device.read_register(1, DECIMAL_COUNT)
r3_value = device.read_register(3, DECIMAL_COUNT)
print r1_value
print r3_value
except IOError:
print "communication error with device"
sys.exit(1)
if __name__ == "__main__":
modbus_RTU()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment