您尚未登录。

楼主 #1 2017-09-07 13:57:16

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

离线

#2 2017-09-07 14:01:51

Linux初学者
会员
注册时间: 2017-09-07
已发帖子: 66
积分: 66

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

CRC ?

离线

楼主 #3 2017-09-07 14:02:04

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

一定要用标准的CRC吗?

离线

#4 2017-09-07 14:03:13

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

两byte校验码和CRC





离线

#5 2017-09-07 14:03:26

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

或者校验和





离线

楼主 #6 2017-09-07 14:04:01

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

谢谢楼上大神们,我通常按字节异或取反算了。

离线

#7 2017-09-07 14:04:38

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

确定要格式化吗 说:

一定要用标准的CRC吗?

是的, 标准的。





离线

楼主 #8 2017-09-07 14:05:12

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

我现在想用所有字节累加成个 32位数就行了。

离线

#9 2017-09-07 14:05:54

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

做通用系统,
非标就自己弄一个算法,
我也用过校验和, 8位的





离线

#10 2017-09-07 14:09:59

路人甲
会员
注册时间: 2017-09-07
已发帖子: 202
积分: 199.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

晕哥 说:

做通用系统,
非标就自己弄一个算法,
我也用过校验和, 8位的

那计算量不是更多?

离线

#11 2017-09-07 14:11:07

路人甲
会员
注册时间: 2017-09-07
已发帖子: 202
积分: 199.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

确定要格式化吗 说:

我现在想用所有字节累加成个 32位数就行了。

累加对连续的位翻转无能为力.

离线

#12 2017-09-07 14:12:28

路人甲
会员
注册时间: 2017-09-07
已发帖子: 202
积分: 199.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

不用怀疑, CRC是综合下来最好的了。

离线

楼主 #13 2017-09-07 14:13:32

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

我觉得按字节累加还好一些。
因为同时两个字节互换错误的概率不大呀。

离线

#14 2017-09-07 14:14:24

路人甲
会员
注册时间: 2017-09-07
已发帖子: 202
积分: 199.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

标准CRC有很多MCU有硬件支持的。
用软件速度也很快, 查表法, 哈哈哈

离线

楼主 #15 2017-09-07 14:14:49

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

确定要格式化吗 说:

我觉得按字节累加还好一些。
因为同时两个字节互换错误的概率不大呀。

查表后还不是得异或?

离线

#16 2017-09-07 14:15:48

路人甲
会员
注册时间: 2017-09-07
已发帖子: 202
积分: 199.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

确定要格式化吗 说:
确定要格式化吗 说:

我觉得按字节累加还好一些。
因为同时两个字节互换错误的概率不大呀。

查表后还不是得异或?

他那个异或XOR不是一两句话可以说清楚的,相信这些酒精考验的标准库....

离线

#17 2017-09-07 14:17:26

失败人士
会员
注册时间: 2017-09-07
已发帖子: 4
积分: 4

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

也有一种不查表一次计算8位的,
时间空间各有优势。

离线

楼主 #18 2017-09-07 14:17:46

确定要格式化吗
会员
注册时间: 2017-09-07
已发帖子: 17
积分: 17

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

失败人士 说:

也有一种不查表一次计算8位的,
时间空间各有优势。

不查表计算8位怎么弄?

离线

#19 2017-09-07 14:19:30

失败人士
会员
注册时间: 2017-09-07
已发帖子: 4
积分: 4

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

确定要格式化吗 说:
失败人士 说:

也有一种不查表一次计算8位的,
时间空间各有优势。

不查表计算8位怎么弄?


维基百科
https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks

Computation of a cyclic redundancy check is derived from the mathematics of polynomial division, modulo two. In practice, it resembles long division of the binary message string, with a fixed number of zeroes appended, by the "generator polynomial" string except that exclusive OR operations replace subtractions. Division of this type is efficiently realised in hardware by a modified shift register,[1] and in software by a series of equivalent algorithms, starting with simple code close to the mathematics and becoming faster (and arguably more obfuscated[2]) through byte-wise parallelism and space-time tradeoffs.


Example of generating an 8-bit CRC. The generator is a Galois type shift register with xor gates placed according to powers (white numbers) of x in the generator polynomial. The message stream may be any length. After it has been shifted through the register, followed by 8 zeroes, the result in the register is the checksum.

Checking received data with checksum. The received message is shifted through the same register as used in the generator, but the received checksum is attached to it instead of zeroes. Correct data yields the all-zeroes result; a corrupted bit in either the message or checksum would give a different result, warning that an error has occurred.
Various CRC standards extend the polynomial division algorithm by specifying an initial shift register value, a final exclusive OR step and, most critically, a bit ordering (endianness). As a result, the code seen in practice deviates confusingly from "pure" division,[2] and the register may shift left or right.

离线

#20 2017-09-07 14:27:09

强哥
会员
注册时间: 2017-09-06
已发帖子: 3
积分: 3

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

失败人士 说:
确定要格式化吗 说:
失败人士 说:

也有一种不查表一次计算8位的,
时间空间各有优势。

不查表计算8位怎么弄?


维基百科
https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks

Computation of a cyclic redundancy check is derived from the mathematics of polynomial division, modulo two. In practice, it resembles long division of the binary message string, with a fixed number of zeroes appended, by the "generator polynomial" string except that exclusive OR operations replace subtractions. Division of this type is efficiently realised in hardware by a modified shift register,[1] and in software by a series of equivalent algorithms, starting with simple code close to the mathematics and becoming faster (and arguably more obfuscated[2]) through byte-wise parallelism and space-time tradeoffs.


Example of generating an 8-bit CRC. The generator is a Galois type shift register with xor gates placed according to powers (white numbers) of x in the generator polynomial. The message stream may be any length. After it has been shifted through the register, followed by 8 zeroes, the result in the register is the checksum.

Checking received data with checksum. The received message is shifted through the same register as used in the generator, but the received checksum is attached to it instead of zeroes. Correct data yields the all-zeroes result; a corrupted bit in either the message or checksum would give a different result, warning that an error has occurred.
Various CRC standards extend the polynomial division algorithm by specifying an initial shift register value, a final exclusive OR step and, most critically, a bit ordering (endianness). As a result, the code seen in practice deviates confusingly from "pure" division,[2] and the register may shift left or right.

good

离线

#21 2018-06-28 14:54:54

xujun
会员
注册时间: 2018-03-21
已发帖子: 33
积分: 33

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

不加校验的也用过,嘿嘿

离线

#22 2018-06-28 15:11:20

xujun
会员
注册时间: 2018-03-21
已发帖子: 33
积分: 33

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

crc   和校验都可以

离线

#23 2018-06-28 15:13:23

xujun
会员
注册时间: 2018-03-21
已发帖子: 33
积分: 33

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

刷个分吧

离线

#24 2018-07-31 13:28:44

abc3240660
会员
注册时间: 2018-07-31
已发帖子: 100
积分: 100

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

crc

离线

#25 2018-09-28 14:19:38

行风
会员
注册时间: 2018-09-28
已发帖子: 6
积分: 6

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

16位校验和搞定

离线

#26 2018-10-24 13:14:06

apleilx
会员
注册时间: 2018-10-23
已发帖子: 36
积分: 35

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

一般用的modbus协议,自带crc校验

离线

#27 2019-01-28 11:36:21

xinyu_khan
会员
注册时间: 2019-01-15
已发帖子: 31
积分: 31

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

CRC

离线

#28 2019-03-09 18:48:06

tink
会员
注册时间: 2019-03-09
已发帖子: 32
积分: 32

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

推荐使用CRC

离线

#29 2019-11-07 13:34:05

silong1126
会员
注册时间: 2019-11-07
已发帖子: 32
积分: 32

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

简单点的累加和,或者靠谱点CRC校验。

离线

#30 2019-11-13 22:07:25

凿子树
会员
注册时间: 2017-10-17
已发帖子: 19
积分: 19

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

用CRC16,比简单的累加和可靠多了。

离线

#31 2020-01-02 10:48:55

szchen2006
会员
注册时间: 2019-10-09
已发帖子: 216
积分: 166.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

顶!学习了。

离线

#32 2020-01-03 17:41:53

joe_zm
会员
注册时间: 2019-12-31
已发帖子: 6
积分: 6

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

校验和

离线

#33 2020-04-27 17:24:10

JIMI_Lu
会员
注册时间: 2019-09-03
已发帖子: 3
积分: 3

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

我一般使用CRC

离线

#34 2020-04-28 11:42:02

sw773
会员
注册时间: 2020-04-26
已发帖子: 10
积分: 10

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

没特殊要求就检验和,数据可能全零就再加个取反。易受干扰的每byte再加奇偶检测

离线

#35 2020-05-03 14:51:19

致远
会员
注册时间: 2020-05-03
已发帖子: 7
积分: 7

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

一般的指令通信用校验和就好了,数据包较大的上百字节的会用上CRC,大文件10KB级别的上MD5

离线

#36 2022-11-23 10:08:17

zhongzhong17
会员
注册时间: 2022-11-22
已发帖子: 9
积分: 4

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

长度 + 关键字 +crc     按字节校验

离线

#37 2022-11-23 10:22:06

dykxjh
会员
注册时间: 2020-03-25
已发帖子: 148
积分: 178

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

通信从不校验的飘过。

离线

#38 2023-04-24 10:42:54

xd-1984
会员
注册时间: 2023-03-07
已发帖子: 6
积分: 1

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

crc16,查表法,快,代码简单

离线

#39 2023-04-24 11:14:14

Blueskull
会员
注册时间: 2020-02-20
已发帖子: 458
积分: 444.5

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

看你误码率。误码率低的话可以CRC,误码率高的话可能得考虑前向纠错,比如Hsiao算法。缺点嘛,就是数据必须成块,而且块越小,ECC校验位占的带宽越高。

离线

#40 2023-04-25 10:27:20

wyhreg
会员
注册时间: 2019-11-14
已发帖子: 20
积分: 0

Re: 弱弱地问一句,大家串口通信 习惯上用什么校验和的算法?有什么优劣?

数据量不大的情况可以参考modem通讯,包头+地址+数据(bas64转码)+crc,我们很多工业产品的串口通讯就是这样解决的。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn