CheckSum如何处理,求助求助!!标题一定要长啊啊啊啊啊啊啊!!!
最近在做端口通讯的解析,串口穿过来的数据里面有CheckSum,实在搞不明白这个东西是什么,上网查了一堆资料也没太搞明白,所以来求助希望大神帮帮忙。下面是关于checksum的文档:
格式:<STX> FN Text <ETB> C1 C2 <CR> <LF>
C1:Most significant character of checksum (belonging to {0-9, A-F}) – See details in section Checksum
C2:Least significant character of checksum (belonging to {0-9, A-F}) – See details in section Checksum
Frame Number
The frame number (FN) permits the receiver to distinguish between new and retransmitted frames.
The frame number begins at 1 with the first frame of the Transfer phase. The frame number is incremented
by one for every new frame transmitted. After 7, the frame number rolls over to 0, and continues in this fash-
ion.
Checksum
The checksum permits the receiver to detect a defective frame. The checksum is encoded as two charac-
ters.
The checksum is computed by adding the binary values of the characters, and keeping the least significant
eight bits of the result. It is an addition module 256.
The checksum is initialized to zero with the <STX> character. The checksum computation uses the FN, all
characters belonging to Text and <ETB> or <ETX>. The computation for the checksum does not include
<STX>, the checksum characters, or the trailing <CR> and <LF>.
The checksum is an integer of eight bits, and can be considered as two groups of four bits. Both groups of
four bits are converted to the ASCII characters of the hexadecimal representation, and transmitted as the
message checksum.
Example: A checksum of 89 can be represented as 01011011 in binary or 5B in hexadecimal. The
checksum is transmitted as the ASCII character 5 followed by the ASCII character B.
示例(红色字体就是checksum):
1H|@^\|C88AEFFC-0903-478A-BC1B-46FC5D82BA6A||Alba00000481|||||LIS_001||P|1394-97|20170825103928Q|1|^Z1708220726||||||||||O@NL|1|N2D
1H|@^\|UDC038||Alba00000481|||||LIS_001||P|1394-97|20170825104029Q|1|||||||||||AC|1|I|timeout^last request has been cancelled|PL|1|N2F
我的代码:
根本就不对,一点摸不着头脑。。。第一次接触这个希望大神别见笑。
格式:<STX> FN Text <ETB> C1 C2 <CR> <LF>
C1:Most significant character of checksum (belonging to {0-9, A-F}) – See details in section Checksum
C2:Least significant character of checksum (belonging to {0-9, A-F}) – See details in section Checksum
Frame Number
The frame number (FN) permits the receiver to distinguish between new and retransmitted frames.
The frame number begins at 1 with the first frame of the Transfer phase. The frame number is incremented
by one for every new frame transmitted. After 7, the frame number rolls over to 0, and continues in this fash-
ion.
Checksum
The checksum permits the receiver to detect a defective frame. The checksum is encoded as two charac-
ters.
The checksum is computed by adding the binary values of the characters, and keeping the least significant
eight bits of the result. It is an addition module 256.
The checksum is initialized to zero with the <STX> character. The checksum computation uses the FN, all
characters belonging to Text and <ETB> or <ETX>. The computation for the checksum does not include
<STX>, the checksum characters, or the trailing <CR> and <LF>.
The checksum is an integer of eight bits, and can be considered as two groups of four bits. Both groups of
four bits are converted to the ASCII characters of the hexadecimal representation, and transmitted as the
message checksum.
Example: A checksum of 89 can be represented as 01011011 in binary or 5B in hexadecimal. The
checksum is transmitted as the ASCII character 5 followed by the ASCII character B.
示例(红色字体就是checksum):
1H|@^\|C88AEFFC-0903-478A-BC1B-46FC5D82BA6A||Alba00000481|||||LIS_001||P|1394-97|20170825103928Q|1|^Z1708220726||||||||||O@NL|1|N2D
1H|@^\|UDC038||Alba00000481|||||LIS_001||P|1394-97|20170825104029Q|1|||||||||||AC|1|I|timeout^last request has been cancelled|PL|1|N2F
我的代码:
Byte[] bys = Encoding.Default.GetBytes(str);
int i = 0;
foreach (byte b in bys)
{
i += b;
}
int checknum = i % 256;根本就不对,一点摸不着头脑。。。第一次接触这个希望大神别见笑。
...全文
相关推荐
checksum校验和计算工具
checksum校验和计算工具,16进制校验和计算工具,简单实用。
CheckSum 校验和工具
本程序实用,小巧,用于对文件做校验和并保留记录,方便将来文件版本检查。
checksum工具
checksum工具软件,对每个文件checksum有一个四位的十六进制代码,防止文件重复,便于区分
CheckSum_checksum_报文头checksum_计算机网络_windows中checksum_
windows中checksum校验算法:求解网络报文中的checksum
IP/TCP/UDP checksum计算c代码
IP TCP UDP checksum计算c代码,包含checdsum原理说明,以及实现c代码,用于验证网络平时收发包checksum问题


