bonjour
en fait lorsque j’exécute l'app sur Windows ça marche bien par contre sur mon smartphone je reçois pas bien la même trame surtout le crc
cordialement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 function CRC16(Data: string):word; var crc : word; i,j : Integer; begin crc := $FFFF; for i := 1 to Length(Data) do begin crc := Ord(Data[i]) xor crc; for j := 1 to 8 do begin if (CRC and $01) = 1 then CRC := (CRC shr 1) xor $A001 else CRC := CRC shr 1; end; end; Result := crc; end ;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 function Readcoils(address : byte; fct: byte; startadress: word; registers : longword ) : string; var CRC : word; frame : string; frameT : string; begin frame:=Chr(address)+Chr(fct)+ Chr(startadress shr 8) + Chr(startadress) + Chr(registers shr 8) + Chr( registers); CRC := CRC16(frame); //Calculate CRC frameT := Chr(address)+Chr(fct)+ Chr(startadress shr 8) + Chr(startadress) + Chr(registers shr 8) + Chr( registers)+ Chr(Lo(crc))+ Chr (Hi(crc)) ; result := frameT; end ;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 procedure TForm1.Button1Click(Sender: TObject); var address : byte; fct : byte; startadress : word; registers : longword; frameT : string; chaine : string; i:byte; begin address := $11; fct := $04; startadress := $0008; registers := $0001; frameT := Readcoils( address, fct, startadress, registers); Chaine:=''; For I := 1 To length(framet) Do Chaine:=Chaine+' '+ intToHex(Ord(frameT[I]),2); edit1.Text := Chaine+' '; end;
Partager