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

Subject: Problem in Stream Out of two 8 bit data
From: Ashish Sharma via Tech-talk <tech-talk@aps.anl.gov>
To: tech-talk@aps.anl.gov
Date: Tue, 15 Jan 2019 18:56:23 +0530 (IST)
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 Iain Marcuson via Tech-talk

Navigate by Date:
Prev: 回覆: How to limit the range of setting value for longout record(DTYP asynInt32) in asynMotor? Chiang, Liang-Chih [江良志] via Tech-talk
Next: Re: Getting data from a shell script into an ioc Kasemir, Kay 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
Navigate by Thread:
Prev: 回覆: How to limit the range of setting value for longout record(DTYP asynInt32) in asynMotor? Chiang, Liang-Chih [江良志] via Tech-talk
Next: RE: Problem in Stream Out of two 8 bit data 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  <2019
ANJ, 21 Jan 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·