EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  2025  <2026 Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  2025  <2026
<== Date ==> <== Thread ==>

Subject: Re: MODBUS User-Defined Function Codes
From: Mark Rivers via Tech-talk <tech-talk at aps.anl.gov>
To: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>, William Jamieson <wjamieso at pppl.gov>
Date: Tue, 3 Feb 2026 00:10:20 +0000
Hi William,

Modbus transactions are always write/read.  As long as the write/read is atomic (done with a mutex held) then there should be no conflict between running StreamDevice and the asyn Modbus driver on the same asyn serial port driver.

All Modbus I/O with the asyn Modbus driver is done in this one line:

It uses writeRead, so it is atomic.

My impression was that StreamDevice also holds a lock between write and read requests so that they are atomic.

What do you see when Modbus and StreamDevice share the same underlying asyn port?

Mark



From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of William Jamieson via Tech-talk <tech-talk at aps.anl.gov>
Sent: Monday, February 2, 2026 11:54 AM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: MODBUS User-Defined Function Codes
 
Does anyone have experience using user-defined function codes alongside the standard function codes that can be handled by the asyn MODBUS driver? I am currently using the MODBUS driver for the standard 03 "READ HOLDING REGISTERS" function while simultaneously using streamDevice driver for executing user-defined functions. This is resulting in conflicts between the MODBUS and streamDevice driver. I have tried setting up two virtual ports pointing to the same serial port:
drvAsynSerialPortConfigure("rs485_modbus", "/dev/ttyUSB0", 0, 1, 0)
drvAsynSerialPortConfigure("rs485_stream", "/dev/ttyUSB0", 0, 1, 0)

Then using a SEQ record that disables the rs485_modbus port then enables the rs485_stream port before processing the stream record. after processing, it disables the rs485_stream port and re-enables the rs485_modbus port.

I disable and enable ports by writing a 0 (disable) or 1 (enable) to the CNCT field of an ASYN record for each port. Example record:
record (asyn, "modbusPort_ASYN")
{
    field (PORT, "rs485_modbus")
}

Not only does this switchover create a lot of I/O Error messages in the IOC shell, but this still results in a garbled data readback from the stream record.

Does anyone have a successful method of making these two methods work in parallel? (or some other tools that make it work) Or should I just give up and use deviceStream reads/writes instead of just the custom ones. I prefer to use the MODBUS driver if possible for the standard MODBUS function codes.

Thanks for any help!

William Jamieson
PPPL I&C Engineer



References:
MODBUS User-Defined Function Codes William Jamieson via Tech-talk

Navigate by Date:
Prev: Re: udpiiu messages Hill, Jeff via Tech-talk
Next: Re: MODBUS User-Defined Function Codes Torsten Bögershausen via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  2025  <2026
Navigate by Thread:
Prev: MODBUS User-Defined Function Codes William Jamieson via Tech-talk
Next: Re: MODBUS User-Defined Function Codes Torsten Bögershausen via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  2025  <2026
ANJ, 19 Mar 2026 · Home · News · About · Talk · Base · Modules · Extensions ·
· Distributions · Download · Documents · Links · Licensing ·