Hi Nia,
> If I use SCAN=I/O Intr and the pollThread() example code below from a previous tech-talk thread will my record be triggered to > read every time there is new data?
There are a couple of ways you could do this, depending on whether other records/applications also need to use the serial port, and how you want to handle a "dead" device.
The simplest way to do it is to do an pasynOctetSyncIO->read() with a timeout that is less than 0.0. As explained in the asyn documentation, that means "wait forever". Thus your polling thread will simply wait until the device sends a message. When it does then you call setDoubleParam() and callParamCallbacks(). If your record has SCAN=I/O Intr then it will process each time the device sends data.
If you want to have allow other records/applications to access the serial port then you cannot do this, because your thread will completely lock the port against other access while the read is pending. In this case you should set a short timeout, so that if the device has not sent a message other records can access the port, before you call pasynOctetSyncIO->read() again. You don't really need to do the epicsThreadSleep(POLL_DELAY) any more. That was needed before asyn R4-14, because calls to pasynOctetSyncIO->read(), write(), or writeRead() were not queued. That meant that your thread would immediately lock up the port again when your read timed out, if you did not call epicsThreadSleep(POLL_DELAY). But beginning with R4-14 calls to the pasynOctetSyncIO functions are queued, so other threads can get access even if you don't call epicsThreadSleep(POLL_DELAY).
> Does this code mean my driver is constantly polling the serial port at a POLL_DELAY?
The time between polls will be WRITE_READ_TIMEOUT + POLL_DELAY.
> I only need to read, so can I call pasynOctetSyncIO->readIt() instead?
You can call pasynOctetSyncIO->read(), not pasynOctetSyncIO->readIt().
> How will I know that the serial device has finished pushing it's data for that trigger?
> Does asyn/pasynOctetSynIO->readIt() wait for the OutputEos in the serial buffer before
> returning the received message? Or is asyn waiting to read sizeof(receiveMessage) characters?
The read will return whenever 1 of the 3 following things happens:
- The timeout occurs
- The EOS is received, assuming the device sends an EOS and you have configured it
- The requested number of characters has been received
Mark
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Fong, Nia W.
Sent: Monday, April 02, 2012 2:17 PM
To: [email protected]
Subject: asyn w/serial device pushing data
Hi,
I'd like to use asynPortDriver to connect to a serial device that pushes data when triggered by a hardware pulse.
If I use SCAN=I/O Intr and the pollThread() example code below from a previous tech-talk thread will my record be triggered to read every time there is new data? Does this code mean my driver is constantly polling the serial port at a POLL_DELAY?
I only need to read, so can I call pasynOctetSyncIO->readIt() instead?
How will I know that the serial device has finished pushing it's data for that trigger? Does asyn/pasynOctetSynIO->readIt() wait for the OutputEos in the serial buffer before returning the received message? Or is asyn waiting to read sizeof(receiveMessage) characters?
> void myPortDriver::pollThread()
> {
> while(1) {
> status = pasynOctetSyncIO->writeRead(pasynUserHMS, sendMessage, numSend,
> receiveMessage, sizeof(receiveMessage),
> WRITE_READ_TIMEOUT, &numSent, responseLen, &eomReason);
> sscanf(receiveMessage, "TEMP=%f,CURRENT=%f", &temperature, ¤t);
> setDoubleParam(temperatureParam, temperature);
> setDoubleParam(currentParam, current);
> callParamCallbacks();
> epicsThreadSleep(POLL_DELAY);
> }
> }
>
Thank you in advance for any suggestions or comments.
Nia
- Replies:
- RE: asyn w/serial device pushing data Fong, Nia W.
- References:
- asyn w/serial device pushing data Fong, Nia W.
- Navigate by Date:
- Prev:
Re: asyn w/serial device pushing data Eric Norum
- Next:
EPICS support for Omega DP470 Hovanes Egiyan
- 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
- Navigate by Thread:
- Prev:
Re: asyn w/serial device pushing data Eric Norum
- Next:
RE: asyn w/serial device pushing data Fong, Nia W.
- 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
|