Hi David,
At the moment, StreamDevice cannot calculate the checksum of something
that is not in the current I/O line.
In your case I see three possibilities. But before I show them, one
correction seems to be necessary. According to the "MeCom Protocol
Specification" document
(https://www.meerstetter.ch/de/category/19-mecom-communication-protocol-specifications),
"The Frame Checksum is represented by four HEX digits." Your example
uses binary format (2 bytes). You need the 0 flag: "%0<xmodem>". Now
that all bytes are ASCII, I would put the "\r" in the Terminator. This
saves you from relying on timeout to detect the end of the input line.
Now the three possibilities:
a. Pre-calculate your checksum. As the output line is constant (does not
contain any formats), the checksum is constant as well.
IN "#0115AA?IF257D";
b. Ignore the input checksum. The sequence "\?" stands for "any byte".
IN "#0115AA%\?\?\?\?";
c. Post-process the string. First use the string to calculate the
checksum, then after the checksum modify the string with regsub:
IN "#0115AA?IF%0<xmodem>%#/?IF//\r"
However, according to the "MeCom Protocol Specification", this is not
what you need. In the example on page 13 it says that the reply checksum
is 342D, not 257D. Thus I guess the checksum is indeed calculated from
the current input (which is unfortunately incomplete in the example, so
that I cannot confirm this). Also the reply in the example starts with
"!", not with "#".
I guess what you really need is this:
Terminator = "\r";
OUT "#0115AA?IF%0<xmodem>";
IN "!0115AA%20c%0<xmodem>";
If you see something starting with "#", can it be that the device echos
the request before sending the reply? In that case you would need:
Terminator = "\r";
OUT "#0115AA?IF%0<xmodem>";
IN "#0115AA?IF%0<xmodem>";
IN "!0115AA%20c%0<xmodem>";
Also the document recommends to use a changing "sequence number". You
can use a calc record (e.g. with the name "SEQ") to count the sequence
(FLNK to it from any I/O record) and reference it using redirection:
Terminator = "\r";
OUT "#01%(SEQ)04X?IF%0<xmodem>";
IN "!01%(SEQ)=04X%20c%0<xmodem>";
The "=" in "%(SEQ)=04X" means that the value of record "SEQ" should be
formatted and compared to the input rather than parsing the input and
storing the value in the record.
Here is the counting calc record:
record(calc, "SEQ")
{
field(VAL, "0x15AA")
field(INPA, "SEQ")
field(CALC, "(A+1)&0xffff")
}
Or with recent EPICS versions:
record(calc, "SEQ")
{
field(VAL, "0x15AA")
field(CALC, "(VAL+1)&0xffff")
}
Best regards,
Dirk
On 03.08.2018 02:44, David Vine wrote:
Hi all,
i'm writing device support for the MeCom protocol for a TEC driver from
Meerstetter Engineering.
In order to parse the response correctly I need to calculate a checksum
thats not included in the response. This is because the response
includes the checksum of the command and not the response.
For example:
Command format:
# address sequence_number command CRC16 terminator
# 01 15AA ?IF 257D \r
Response is:
# address sequence_number CRC16 terminator
# 01 15AA 257D \r
So to parse the response I need to calculate a CRC that's not included
in the response. For example:
OUT "#0115AA?IF%<xmodem>\r"
IN "#0115AA%<xmodem>\r" but the CRC is for the OUT not the IN.
Any ideas would be much appreciated.
Thanks,
David
--
Best regards,
David Vine
(925) 326 7503
[email protected] <mailto:[email protected]>
5750 Imhoff Drive, Suite I | Concord, CA 94520 | USA
<https://maps.google.com/?q=5750+Imhoff+Drive,+Suite+I%C2%A0+%7C%C2%A0+Concord,+CA+94520%C2%A0+%7C%C2%A0+USA&entry=gmail&source=g>
http://www.Sigray.com <http://www.sigray.com/>
This e-mail and any attachments are provided for the sole use of the
intended recipient(s), and may contain information that is confidential,
privileged, proprietary or otherwise protected by law. If you are not
the intended recipient of this message, you are not authorized to read,
print, retain, copy, forward or otherwise disseminate this message or
any part of it. If you have received this e-mail in error, please notify
the sender immediately by reply e-mail and delete the original message
from your mail system. Thank you.
- References:
- Stream Device: Parse response that includes checksum of command string David Vine
- Navigate by Date:
- Prev:
Re: dbGetPdbAddrFromLink dropped from 3.15 again Michael Davidsaver
- Next:
RE: Stream Device: Parse response that includes checksum of command string [email protected]
- 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
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: Stream Device: Parse response that includes checksum of command string [email protected]
- Next:
DBE_PROPERTY and Gateway Dominic Oram - UKRI STFC
- 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
2020
2021
2022
2023
2024
|