Ver Mensaje Individual
  #5  
Antiguo 11-03-2009
espinete espinete is offline
Miembro
 
Registrado: mar 2009
Posts: 662
Reputación: 18
espinete Va camino a la fama
Aquí va el código que utilizo para calzular el checksum dichoso y enviar correctamente el resultado a la balanza.

En el ejemplo envío la siguiente cadena: 9 8 0 0 1 5 0 X Cr Lf

Código:
 
                  a:='30';
                  b:='30';
                  c:='31';
                  d:='35';
                  e:='30';
                  h:=inttohex(hextoint('39') xor hextoint('38'),1);
                  h:=inttohex(hextoint(h) xor hextoint(a),1);
                  h:=inttohex(hextoint(h) xor hextoint(b),1);
                  h:=inttohex(hextoint(h) xor hextoint(c),1);
                  h:=inttohex(hextoint(h) xor hextoint(d),1);
                  h:=inttohex(hextoint(h) xor hextoint(e),1);
 
                  //Cadena completa en HEX
                  edit21.text:='39'+'38'+a+b+c+d+e+h+'0D'+'0A';

                  //Cadena en ASCII (sin #13 ni #10)
                  edit19.text:=chr(hextoint('39'))+chr(hextoint('38'))+chr(hextoint(a))+chr(hextoint(b))+chr(hextoint(c))+chr(hextoint(d))+chr(hextoint(e))+chr(hextoint(h));

                  //Cadena ASCII completa (CON #13#10)
                  ApdComPort1.OutPut := edit19.text+#13+#10;
Responder Con Cita