Hi Kevin,
I think this format is your problem:
in "\x5A\xA5\x03\x06%(A)2x%(B)2x"
The device is sending you binary data, not ASCII encoded data. %2x is the format you would use if the device were sending the data as ASCII characters for a hex number.
I think you need to change the format to:
in "\x5A\xA5\x03\x06%(A)01r%(B)01r"
The "r" format is for "raw" data.
Mark
From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of cxy via Tech-talk <tech-talk at aps.anl.gov>
Sent: Thursday, June 19, 2025 6:44 AM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: Question about getting hexadecimal data with StreamDevice
Hello, everyone:
I have a current-readout device, communicate with RS232, baud rate 115200, 8 bits data, 1 bit stop, no parity.
When send "\x5A\xA5\x55\x00", it should return data as "5A A5 XX YY ZZ ZZ", such as"\x5a\xa5\x03\x06\x7f\xe8", and we can get current data from "ZZ ZZ".
The Device provids these simple information above. With a serial port assistent on Windows, we can get all the data correctly.
For example, send "5A A5 55 00" as hexadecimal data, get "5a a5 03 06 7f 07", also as hexadecimal data.
Now I use EPICS StreamDevice to connect the device, communication is correct, I want to save return dada to a record A and another record B. But I can not get right return data.
Here attached the details. Does anyone know why? What's the problem here? How can I get all the returned data "ZZ ZZ" to two PVs such as A and B?
Hope for your advice, thank you very much.
1. Use the ai record (A,B,C,D) to receive returned data, with record and proto file like this:
record(ai, "data")
{
field(DTYP, "stream")
field(INP, "@wcm.proto readdata wcm")
field(SCAN, "1 second")
}
wcm.proto:
OutTerminator=CR LF;
InTerminator=CR LF;
readdata{
out "\x5A\xA5\x55\x00"; #it shows wrong if ther is a space " " between 5A and A5.
in "\x5A\xA5\x03\x06%(A)2x%(B)2x"
}
I think I should get A=7f, B=07.
But, the executing result:

Then I try to use string type to get all the turned back data, it seems I can not do that.
2. Use string record (A, B,C,D)to receive returned data:
record(stringin, "data")
{
field(DTYP, "stream")
field(INP, "@wcm.proto readdata wcm")
field(SCAN, "1 second")
}
wcm.proto:
OutTerminator=CR LF;
InTerminator=CR LF;
readdata{
out "\x5A\xA5\x55\x00";
in "\x5A\xA5%(A)28c"
}
Executing result:

3. Use string record (A, B,C,D)to receive returned data:
record(stringin, "data")
{
field(DTYP, "stream")
field(INP, "@wcm.proto readdata wcm")
field(SCAN, "1 second")
}
wcm.proto:
OutTerminator=CR LF;
InTerminator=CR LF;
readdata{
out "\x5A\xA5\x55\x00";
in "%s"
}
Executing result (The same as last one):

Look forward to your advice. Thank you again.
Best wishes,
Kevin
6/19/2025
|