Cita:
Empezado por duilioisola
Podría tratarse también de un check de paridad como explican aquí: https://en.wikipedia.org/wiki/Longit...dundancy_check
Ten en cuenta que parece que al ser dos bytes de paridad deberías trabajar con WORDs y si el último byte del mensaje queda sin su par para generar un word habrá que resolverlo agregándole otro (por delante o por detrás) con valor 0.
Código:
Pseudocodigo byte
Set LRC = 0
For each byte b in the buffer
do
Set LRC = (LRC + b) AND 0xFF
end do
Set LRC = (((LRC XOR 0xFF) + 1) AND 0xFF)
Pseudocodigo word
Set LRC = 0
For each word b in the buffer
do
Set LRC = (LRC + b) AND 0xFFFF
end do
Set LRC = (((LRC XOR 0xFFFF) + 1) AND 0xFFFF)
|
Hola de nuevo
Muchisimas gracias, ya te has ganado unas
el ultimo byte es LRC
Ya tenemos la mitad resuelta, ya solo falta la otra mitad, el byte anterior.
Pongo este código (por si lo quereis copiar) que incluye la función LRC en Delphi
Código Delphi
[-]
procedure TPCVP.Button1Click(Sender: TObject);
var
s: ansistring;
function CalculaLRC(cadena: ansistring): word;
var
i: word;
begin
Result := 0;
for i := 1 to Length(cadena) do
Result := (Result + Ord(cadena[i])) and 255;
Result := ((Result xor 255) + 1) and 255;
end;
begin
s := #144#130#0#1#58#49#144#3; showmessage(IntToStr(CalculaLRC(s))); s := #144#130#0#0#144#3; showmessage(IntToStr(CalculaLRC(s))); s := #144#130#2#6#144#3; showmessage(IntToStr(CalculaLRC(s))); s := #144#130#0#1#58#50#144#3; showmessage(IntToStr(CalculaLRC(s))); s := #144#130#0#255#6#144#3; showmessage(IntToStr(CalculaLRC(s))); s := #144#130#1#5 +
'45 ' + #0#0#0#0 +
'COP ' + #0#0#0#11 +
'COPY ' + #0#0#4#176 +
'JON ' + #0#0#0#0 +
'ORIGTP10' + #0#0#0#0 +
'TALATP10' + #0#0#3#252 +
' ' + #9#107#4#0 +
#144#3; showmessage(IntToStr(CalculaLRC(s))); s := #144#130#1#5 +
'[**********PUNTA********' + #13#10 +
'N1[ Pro/TOOLMAKER v9.0.030 ]' + #13#10 +
'N2[ lunes, 31 de marzo de 2014 20:41:15 ]' + #13#10 +
'N3[ V:\266\266ma01p.pun ]' + #13#10 +
'N4[ Z:\08266\200\08266A_2002_P200_MACHO_1.dca ]' + #13#10 +
'N5[ Eduardo Gutierrez ]' + #13#10 +
'N6[ Trayectoria de herramienta sobre plano' +
#144#3; showmessage(IntToStr(Length(s) - 6) + ' ' + IntToStr(CalculaLRC(s))); s := #144#130#2#5 +
' de corte en Z 2 [35x6, 0.5] ]' + #13#10 +
'N7[ Trayectoria de herramienta sobre plano de corte en Z ]' + #13#10 +
'N8[ Thickness in XY is: 0.500 ]' + #13#10 +
'N9[ Thickness in Z is: 0.500 ]' + #13#10 +
'N10[ Cutter: 35.000x6.000 ]' + #13#10 +
'N11[ Note: Cutter tip output ]' + #13#10 +
'N12[ WARNING: Feedrate c' +
#144#3; showmessage(IntToStr(Length(s) - 6) + ' ' + IntToStr(CalculaLRC(s))); s := #144#130#3#5 +
'ontrol cannot be used with Override Standard Feedrates - feedrate control disabled. ]' + #13#10 +
'N13F P1' + #13#10 +
'N14G0Z166.000' + #13#10 +
'N15G0X308.605Y-103.414' + #13#10 +
'N16G1Z144.827' + #13#10 +
'N17F P2' + #13#10 +
'N18X308.615Y-103.375Z144.430' + #13#10 +
'N19X308.643Y-103.261Z144.050' + #13#10 +
'N20X308.688Y-103.076Z14' +
#144#3; showmessage(IntToStr(Length(s) - 6) + ' ' + IntToStr(CalculaLRC(s))); s := #144#130#4#5 +
'3.700' + #13#10 +
'N21X308.749Y-102.827Z143.395' + #13#10 +
'N22X308.823Y-102.525Z143.146' + #13#10 +
'N23X308.907Y-102.181Z142.965' + #13#10 +
'N24X308.998Y-101.808Z142.857' + #13#10 +
'N25X309.178Y-100.910Z142.695' + #13#10 +
'N26X309.283Y-100.000Z142.534' + #13#10 +
'N27X309.310Y-99.085Z142.372' + #13#10 +
'N28X309.261Y-98.170Z142.21' +
#144#3; showmessage(IntToStr(Length(s) - 6) + ' ' + IntToStr(CalculaLRC(s))); end;
Lo único que no son 2 bytes, así que con un byte es suficiente.