Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RS485 Transceiver Chip #137

Open
CrabbyPete opened this issue Feb 26, 2025 · 2 comments
Open

RS485 Transceiver Chip #137

CrabbyPete opened this issue Feb 26, 2025 · 2 comments

Comments

@CrabbyPete
Copy link

CrabbyPete commented Feb 26, 2025

I am using minimalmodbus on a Raspberry Pi that has an add on board with a RS485 transceiver chip that required me to set the DE pin to control writing and reading from the chip. I can do it manually like this

def write_485():
    s=serial.rs485.RS485(port='/dev/serial0', baudrate=9600, parity=serial.PARITY_NONE)
    s.rs485_mode = serial.rs485.RS485Settings(False,True)
    s.write('ABC'.encode('utf-8'))
    s.flush()
    GPIO.output(TXDEN, GPIO.LOW)
    wait_for = 5
    while wait_for:
        if s.in_waiting > 0:
            data = s.read(s.in_waiting)
            print(f"Received: {data}")
            log.info(f"Recieved:{s.in_waiting}")
            wait_for -= 1

Is there a way to do it in the minimalmodbus module or do I need to re-write it?

@j123b567
Copy link
Collaborator

It is generally a bad idea to handle DE manually in Python, because it is slow and unreliable.
That said, what about this?

class MyRS485(serial.rs485.RS485):
    def setRTS(self, value):
        GPIO.output(TXDEN, GPIO.HIGH if value else GPIO.LOW)

ser  = MyRS485(port='/dev/serial0', baudrate=9600, parity=serial.PARITY_NONE)
ser.rs485_mode = serial.rs485.RS485Settings(False,True)
instrument = minimalmodbus.Instrument(ser, 1)

@CrabbyPete
Copy link
Author

Thanks, I 'll try it. I know its not ideal, but its a 9600 baud interface that is very simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants