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  <20222023  2024  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  <20222023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Issue with Asyn+StreamDevice on a Raspi CM4
From: Kuldeep Joshi via Tech-talk <tech-talk at aps.anl.gov>
To: tech-talk at aps.anl.gov
Date: Tue, 12 Jul 2022 14:51:53 +0000
>> /dev/ttyAMA0
Are you are using the mini UART port of PI
I had tried using the monitor port with PI4 for programming a bricked switch, but I noticed that the received data was corrupted.
I aborted the attempt and used a USB to serial device instead.
From that I inferred that the mini UART tty port has limited drive/sense and baud rate capabilities.
It is intended for console applications.
The link provided by Mark discusses it in detail

You can try modifying the device tree to use the other hard UART ports available.
(i do not know if the latest OS supports an easier changeover).
you can check here

Ideally the limitation of the UART buffer size are to be taken care by OS.

Kuldeep


Date: Tue, 12 Jul 2022 12:44:40 +0000
From: Mark Rivers <rivers at cars.uchicago.edu>
To: "florian at ep1.ruhr-uni-bochum.de" <florian at ep1.ruhr-uni-bochum.de>,
        "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>, "Zimoch Dirk (PSI)"
        <dirk.zimoch at psi.ch>
Subject: Re: Issue with Asyn+StreamDevice on a Raspi CM4
Message-ID:
        <DM5PR11MB20126372E680B9B9CD67DE3099869 at DM5PR11MB2012.namprd11.prod.outlook.com>

Content-Type: text/plain; charset="iso-8859-1"

Florian,

I would be really surprised if the Raspberry PI cannot send strings longer than 16 characters without breaking them into chunks because of some buffer limitation.  I would think Google would be full of comments about that, but I can't find any.  I did find a comment saying that on some models the baud rate is tied to the system clock which can vary the speed under high load, and how to fix that. https://di-marco.net/blog/it/2020-06-06-raspberry_pi_3_4_and_0_w_serial_port_usage/

I also found an article saying the hardware receive buffer is only 16 bytes, but that it only becomes an issue at Mbit baud rates when the ISR cannot keep up. https://stackoverflow.com/questions/27322048/serial-uart-buffer-overflow-at-high-speed#:~:text=As%20far%20as%20I%20know,software%20buffer%20on%20main%20memory.

Dirk wrote:
> I have extended an existing interpose driver which should fulfill your needs.

Should I update asyn to that modified version?

Maren wrote:
> And for the reads read in 16 byte chunks until you get a 0d.

That will happen automatically as long as Florian has not set the noProcessEos flag when creating the rs485 port.

Mark


________________________________
From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Zimoch Dirk (PSI) via Tech-talk <tech-talk at aps.anl.gov>
Sent: Tuesday, July 12, 2022 5:27 AM
To: florian at ep1.ruhr-uni-bochum.de <florian at ep1.ruhr-uni-bochum.de>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: Re: Issue with Asyn+StreamDevice on a Raspi CM4

On Tue, 2022-07-12 at 09:24 +0000, Zimoch Dirk (PSI) via Tech-talk wrote:
> You could write an asynInterpose driver that chops the output into 16 bytes chunks. (And maybe delays in between if
> necessary.)

I have extended an existing interpose driver which should fulfill your needs.
https://github.com/paulscherrerinstitute/asynInterposeDelay

(The repo does not have a standard EPICS configure directory and uses a PSI specific GNUmakefile. Feel free to adapt it
to the standard EPICS or any other your build system or simply add it to asyn.)

I wrote this interpose driver to chop output into single bytes with delay. Now  you can tell it to use any chunk size
(with 0 delay or longer, as you need).

Dirk

>
> On Tue, 2022-07-12 at 07:56 +0000, Zimoch Dirk (PSI) via Tech-talk wrote:
> > Hi Florian,
> >
> > If the output buffer is not able to accept all bytes at once, then the write() function should have returned 16
> > instead
> > of 17 and drvAsynSerialPort writeIt() would try again with the remaining bytes, waiting for writeTimeout and failing
> > with asynTimeout if it cannot send.
> >
> > But if the kernel driver implements write() in a way that discards bytes, then all hope is lost.
> >
> > Try with some other program, for example from the command line:
> > echo "this is a string longer than 16 chars" > /dev/ttyAMA0
> >
> > Dirk
> >
> > On Tue, 2022-07-12 at 09:44 +0200, Florian Feldbauer via Tech-talk wrote:
> > > Hey all,
> > >
> > > we have a small vacuum chamber to test our sensor modules after production.
> > > The 2 Pumps and 2 valves are controlled via a Raspberry Pi CM4 running
> > > linux-aarch64.
> > >
> > > The Turbo pump and digital gauge are from Pfeiffer Vacuum and controlled
> > > via RS485.
> > >
> > > I noticed some strange issue. I was able to read all parameters from
> > > those devices, but changing them fails.
> > >
> > > To further investigate I attached a 2nd PC to the RS485 bus just
> > > listening and found the following:
> > >
> > > > epics> asynSetTraceIOMask rs485, 0, ASYN_TRACEIO_ESCAPE
> > > > epics> asynSetTraceMask rs485, 0, ASYN_TRACEIO_DRIVER
> > > > epics> dbpf SCATTERCHAMBER:VACUUM:TP:CtrlViaInt RS485
> > > > DBF_STRING:         "RS485"
> > > > 2022/07/12 09:25:52.084 /dev/ttyAMA0 write 17
> > > > 0011006003002125\r
> > > > 2022/07/12 09:25:52.721930 rs485 SCATTERCHAMBER:VACUUM:TP:CtrlViaInt:
> > > > No reply within 500 ms to "0011006003002125<0d>"
> > > > 2022/07/12 09:25:52.722 /dev/ttyAMA0 write 16
> > > > 0010006002=?101\r
> > > > 2022/07/12 09:25:52.762 /dev/ttyAMA0 read 16
> > > > 0011006003002125
> > > > 2022/07/12 09:25:52.766 /dev/ttyAMA0 read 1
> > > > \r
> > > >
> > > > epics>
> > >
> > > The 2nd PC received this:
> > >
> > > > Got 16 bytes:
> > > > 0011006003002125      [30 30 31 31 30 30 36 30 30 33 30 30 32 31 32 35]
> > > > Got 16 bytes:
> > > > 0010006002=?101\r     [30 30 31 30 30 30 36 30 30 32 3d 3f 31 30 31 0d]
> > > > Got 17 bytes:
> > > > 0011006003002125\r    [30 30 31 31 30 30 36 30 30 33 30 30 32 31 32 35 0d]
> > >
> > > As you can see, on the first message which was send from the IOC, the CR
> > > is missing.
> > >
> > > I guess the issue is, that asyn tries to write all 17 bytes at once, but
> > > the tx buffer on the Raspberry Pi can only hold 16 byte, so the CR gets
> > > lost.
> > >
> > > Is there a way to limit the number of bytes written in a single write
> > > call with asyn?
> > >
> > > Luckily in this case the length of the telegrams is well known and I
> > > could simply use 2 OUT statements in my protocol file to work around
> > > this problem, but what if I want to control a device where the length
> > > depends on the payload data?
> > >
> > > Cheers,
> > > Florian
> > >
> > >

Replies:
Re: Issue with Asyn+StreamDevice on a Raspi CM4 Florian Feldbauer via Tech-talk

Navigate by Date:
Prev: Re: Teledyne Dalsa Areadetector Driver (David Vine) David Vine via Tech-talk
Next: Re: EPICS compilation errors Andrew Johnson 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  <20222023  2024 
Navigate by Thread:
Prev: Re: Issue with Asyn+StreamDevice on a Raspi CM4 Mark Rivers via Tech-talk
Next: Re: Issue with Asyn+StreamDevice on a Raspi CM4 Florian Feldbauer 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  <20222023  2024 
ANJ, 14 Sep 2022 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·