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  <20192020  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  <20192020 
<== Date ==> <== Thread ==>

Subject: Re: Problem in Stream Out of two 8 bit data
From: Dirk Zimoch via Tech-talk <tech-talk@aps.anl.gov>
To: <tech-talk@aps.anl.gov>
Date: Wed, 6 Feb 2019 10:55:54 +0100
Ashish,

If your device does not really need the waits between characters, you may be able to send the value from an ao or longout record like this:

out 131 0 "%#.2r”;

And read like this:

out 41 0;
in "D%#02r";

(Note that you can simply write 131 for single byte values. You can also use variables for improved readability:

WRITE_KNOB=131;
out $WRITE_KNOB 0 "%#.2r”;

You may also set maxInput to avoid termination by readTimeout:
maxInput = 3; # for 'D' plus 2 bytes value

However if the device really needs a delay between the bytes you send, I have something better for you. With the asynInterposeDelay driver you can automatically fill in the delays without StreamDevice bothering.

https://github.com/paulscherrerinstitute/asynInterposeDelay

The GNUmakefile is not standard EPICS. Sorry about that. You need to create your own Makefile.

With that driver you simply write something like this in your startup script after creating the asyn port:

asynInterposeDelay asynPortName, address, 0.05

and each output byte will automatically get a 50 ms delay.

BTW: If your user values are something like 0.0-10.0 rather than 0-65535, you can use ai and ao records and let the record do the conversion for you.

Dirk


On 21.01.19 19:28, Iain Marcuson via Tech-talk wrote:
I think the approach would be to use a longout record and change the conversion.  You can use little-endian raw output with I believe

out “%#02.2r” to send the two least-significant bytes (2.2) as little-endian (#), treating the value as raw and unsigned (0).

*From:* tech-talk-bounces@aps.anl.gov <tech-talk-bounces@aps.anl.gov> *On Behalf Of *Ashish Sharma via Tech-talk
*Sent:* Tuesday, January 15, 2019 8:26 AM
*To:* tech-talk@aps.anl.gov
*Subject:* Problem in Stream Out of two 8 bit data

Hello,

I have a microcontroller based shaft encoder device with its firmware already written. I have its python equivalent on serial protocol to read and write to the device:

##************************************************************

/WRITE_KNOB = 121/
/READ_KNOB = 41/

/se = serial.Serial(port='/dev/ttyACM0', baudrate=38400, timeout = 0.3, parity=serial.PARITY_EVEN, stopbits=1)/

/def read_knob(kn):/
/    se.write(chr(READ_KNOB))/
/    time.sleep(0.01)/
/    se.write(chr(kn))            # Knob kn=0, 1, 2, 3 to be read/
/    time.sleep(0.01)/
/    res = se.read(1)/
/    if res != 'D':/
/        print 'READ_KNOB error ', res/
/        return /
/    res = se.read(2)/
/    data = ord(res[0]) | (ord(res[1]) << 8) # HIGH byte is comming First, Next -> LOW Byte/
/    return data/

/def write_knob(kn,data):/
/     if (data > 65535): /
/        data = 65535/
/    dlo = data & 0xff/
/    dhi = (data >> 8) & 0xff/
/    se.write(chr(WRITE_KNOB))/
/    time.sleep(0.01)/
/    se.write(chr(kn))/
/    time.sleep(0.01)/
/    se.write(chr(dlo))/
/    time.sleep(0.01)/
/    se.write(chr(dhi))/
/    time.sleep(0.01)/
/    res = se.read(1)/
/    print res /
/    if res != 'D':/
/        print 'WRITE_KNOB error ', res/
/        return/
/    return data/

/##*******************************************************/

My equivalent .proto file for */read/* is as follows and it is working fine:

/get_analog_ch0 {/
/    out ')';        # for chr(41)/
/    wait 50;/
/    out '\x00';   # for chr(0)/
/    wait 50;/
/    in "D%#02r";/
/    #ExtraInput = Ignore;/
/    ReadTimeout = 30;/

/    @mismatch {/
/    out ')';/
/    wait 50;/
/    out '\x00';/
/    wait 50;/
/         in "C%r";/
/   }/
/}/

*But I am unable to */*write */*the data to it. The routine that I am using is:*/**/

/*set_analog_ch0 {*/*/
/    out 'y';          # for chr(121)/
/    wait 50;/
/    out '\x00';     # for chr(0)/
/    wait 50;/
/    out "%2c";/
/    #ExtraInput = Ignore;/
/    #ReadTimeout = 30;/
/}//*

The .db file is as follows:

/record(ai, knob:get:ch_0) {/
/    field(DESC, "Knob 0 output")/
/    field(DTYP, "stream")/
/    field(INP, "@encoder.proto get_analog_ch0() $(PORT)")/
/    field(SCAN, ".05 second")/
/}/
/record(waveform, knob:set:ch_0) {/
/    field(DESC, "Knob 0 output")/
/    field(DTYP, "stream")/
/    field(INP, "@encoder.proto set_analog_ch0() $(PORT)")/
/    field (FTVL, "CHAR")/
/    field (NELM, "2")/
/}/

I am not sure whether /waveform /or which type of record will suffice here. While using /waveform /record, I am unable to write the 2 byte values to the record like the way it is being done in python serial interface code.

ps: I am an EPICS newbie. So, please bear with my limited experience.

--
Ashish Sharma
Engineer 'C'
Inter-University Accelerator Centre,
Aruna Asaf Ali Marg, New Delhi - 110067
Mob. : +91-9643031284, +91-7982808263
Off. : 011-24126024 (Ext : 124)


References:
Problem in Stream Out of two 8 bit data Ashish Sharma via Tech-talk
RE: Problem in Stream Out of two 8 bit data Iain Marcuson via Tech-talk

Navigate by Date:
Prev: Re: EPICS7.0.2 "make distclean" in a model deletes top level configure dir Ralph Lange via Tech-talk
Next: RE: Weird stream device behavior when using the IOC shell's exit function Abdalla Ahmad 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  <20192020 
Navigate by Thread:
Prev: RE: Problem in Stream Out of two 8 bit data Iain Marcuson via Tech-talk
Next: EPICS in Docker containers Gabriel de Souza Fedel 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  <20192020 
ANJ, 06 Feb 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·