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

Add before_transfer callback #70

Closed
wants to merge 1 commit into from
Closed

Add before_transfer callback #70

wants to merge 1 commit into from

Conversation

zyura
Copy link

@zyura zyura commented Jul 19, 2021

It allows to switch a physical transmitter chip to read or write mode.

Useful in half duplex operation when a transmitter direction is
controlled with a GPIO pin.

Example usage:

def switch(instrument, is_write):
    instrument.serial.flush()
    
    # pin_de is a GPIO class instance
    pin_de.set_value(is_write)

instrument = Instrument('/dev/ttyS1', 1, before_transfer=switch)  # port name, slave address (in decimal)

It allows to switch a physical transmitter chip to read or write mode.

Useful in halfduplex operation when a transmitter direction is
controlled with a GPIO pin.
@zyura zyura changed the title Add before_transmit callback Add before_transfer callback Jul 19, 2021
@pyhys
Copy link
Owner

pyhys commented Aug 8, 2021

Hi! This is interesting, and I will mention your pull request in the official documentation. However I do not think it is suitable for inclusion in mainline, simply because it will only work for really low speeds. See my measurements: https://minimalmodbus.readthedocs.io/en/stable/serialcommunication.html

I will give at attribution to you in the AUTHORS file.

@pyhys pyhys closed this Aug 8, 2021
@zyura
Copy link
Author

zyura commented Aug 8, 2021

Ok, thanks.

It works for us on 500 MHz embedded CPU running OpenWRT with 9600 bps Modbus speed. I hope it will be useful for others.

@j123b567
Copy link
Collaborator

j123b567 commented Aug 9, 2021

Just to note, there is already similat functionality in pyserial

https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.rs485.RS485

We are using custom serial class very similar to this RS485 which toggles GPIO instead of RTS. So much better solution woul be to allow custom serial class factory instead of reimplementing this in minimalmodbus.

We are now accessing _ members of minimalmodbus to initialize serial port before Instrument, which is little bit tricky.

kubeqz added a commit to kubeqz/minimalmodbus that referenced this pull request Nov 3, 2021
@CrabbyPete
Copy link

Has this commit been merged?

@j123b567
Copy link
Collaborator

Has this commit been merged?

No, it has trivial solution without poluting the minimalmodbus codebase. See e.g. #137 (comment)

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

Successfully merging this pull request may close these issues.

4 participants