Headeruart And Traileruart Definitions; Cyclic Redundancy Checks; Compute; Sample In C - envea CAIRSENS PM Série Notice Technique

Table des Matières

Publicité

Les langues disponibles

Les langues disponibles

0x12
0x1C
5

HeaderUart and TrailerUart definitions

In the following section of this document, the series of bytes representing SYNC STX LG and a part of
CMD will be referred to as HeaderUart and will be defined by:
· HeaderUart = SYNC, STX, LG, 0x30, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
In the same idea, the series of bytes representing END will be referred to as TrailerUart and will be
defined by:
· TrailerUart = END CRC ETX
6

Cyclic redundancy checks

6.1

Compute

The CRC code is calculated by dividing the binary sequence representing the frame by the following
polynomial:
16
12
X
+ X
+ X
6.2

Sample in c

#include
<stdio.h>
unsigned int
{
unsigned int
unsigned int
unsigned char
Crc=0;
for
(j=0;j<lg; j++) {
Crc = Crc ^ Frame[j];
for
( i_bits = 0; i_bits < 8; i_bits++ ) {
carry = Crc & 1;
Crc = Crc/2;
if(carry) {
Crc = Crc ^ Poly;
}
}
}
return
Crc;
}
int main(int
{
unsigned int
unsigned char
0x02,// Start Frame
0x13,// Length of Data
0x30,0x01,0x02,0x03,0x04,0x05,0x06,
© 2016 Cairpol
Get the last minute average data ( 1 data returned )
Get stored average data ( multiple data returned )
5
+ 1
FCRC(
unsigned char Frame[],unsigned char
Poly = 0x8408;
Crc;
j,i_bits,carry;
argc, char* argv[])
i;
Frame[] = {0xFF,
// Synchro Word
Available commands
lg)
5

Publicité

Chapitres

Table des Matières
loading

Ce manuel est également adapté pour:

Cairsens pm1Cairsens pm2.5Cairsens pm10

Table des Matières