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[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)