Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeonghunLee/296262b5792d242f10197f001023626b to your computer and use it in GitHub Desktop.
Save JeonghunLee/296262b5792d242f10197f001023626b to your computer and use it in GitHub Desktop.
modbus_rtu_example
#
# refer to
# https://pymodbus.readthedocs.io/en/latest/source/example/synchronous_client.html
# https://pymodbus.readthedocs.io/en/latest/source/example/synchronous_client_ext.html
#
# pip install pymodbus (not update this into requirement.txt)
#
# this program is only test for Modbus RTU
# this is working as a Modbus RTU Master and then everytime write/read holdregs in a Slave
# check the status of slave device
from pymodbus.client.sync import ModbusSerialClient
from pymodbus.constants import Endian # Endian and World
from pymodbus.payload import BinaryPayloadDecoder # decode binaries when read datas from Modbus-RTU
from threading import Timer
import time
import logging
import sys
from optparse import OptionParser
#from enum import IntEnum
from pymodbus.payload import BinaryPayloadBuilder # encode binaries when write datas into Modbus-RTU
from os import path, stat, SEEK_END
from struct import pack
import struct
# for checking speed
## only option (no need)
#from tqdm import tqdm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment