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  <20192020  2021  2022  2023  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  <20192020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Problem in Stream Out of two 8 bit data
From: Iain Marcuson via Tech-talk <[email protected]>
To: Ashish Sharma <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Mon, 21 Jan 2019 18:28:13 +0000

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: [email protected] <[email protected]> On Behalf Of Ashish Sharma via Tech-talk
Sent: Tuesday, January 15, 2019 8:26 AM
To: [email protected]
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[1]) << 8) # HIGH byte is comming First, Next -> LOW Byte
    return data

 

def write_knob(kn,data):
     if (data > 65535):        
        data = "">
    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)


Replies:
Re: Problem in Stream Out of two 8 bit data Dirk Zimoch via Tech-talk
References:
Problem in Stream Out of two 8 bit data Ashish Sharma via Tech-talk

Navigate by Date:
Prev: RE: AreaDetector Code Not Updating Mark Rivers via Tech-talk
Next: RE: AreaDetector Code Not Updating Iain Marcuson 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  2021  2022  2023  2024 
Navigate by Thread:
Prev: Problem in Stream Out of two 8 bit data Ashish Sharma via Tech-talk
Next: Re: Problem in Stream Out of two 8 bit data Dirk Zimoch 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  2021  2022  2023  2024 
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 ·