The problem here is with the client code, not the protocol. Something like the following might work: fNAN = struct.unpack("<f", struct.pack("<L", 0xFFFFFFFF))[0] fArray = np.zeros(256, dtype=np.float) for i in range(2,256): fArray[i] = fNAN . . . send fArray . . .
import numpy as np
fArray = np.zeros(256, dtype=np.float) fArray[0] = 1.23 fArray[1] = 3.14 for i in range(2,256): fArray[i] = float(‘Nan’) since the 'unused’ bit pattern in this case is likely 0x7FC00000, not 0xFFFFFFFF.
However, if your device can actually use any ‘NAN’ value as an ‘unused’ indicator the latter example should work, too.
hi,
I want to use streamdevice to communicate
with a device. Each time send 256 floats (1024 bytes). The valid data part is changeable.
For the rest parts will be filled with 0xffffffff (4 bytes). So I defined a
waveform record like this: record(waveform, "data") {
field(DTYP, "stream")
field(SCAN, "Passive")
field(NELM, "256")
field(FTVL, "FLOAT")
field(INP, "@psc.proto set_array terminal") } The proto file as following: set_array {
MaxInput = 4;
out "%4R";
in "%(crc.VAL)4r" } Then use python to create a data list like
this as the count of 0xffffffff is different each time: [3.14,3.14, 0xffffffff,0xffffffff, 0xffffffff,0xffffffff,…],
cothread to caput the list to pv. But the 0xffffffff will be converted to float
4294967295 and send to device as 0x4F800000 by streamdevice.
How to write the protocol file? Thanks a
lot for your help.
Best wishes, Geyang 2016/07/27
|