Experimental Physics and
| |||||||||||||||
|
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)
| ||||||||||||||
ANJ, 21 Jan 2019 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |