Einzelnen Beitrag anzeigen

Benutzerbild von XXcD
XXcD

Registriert seit: 19. Sep 2006
581 Beiträge
 
Delphi 2007 Professional
 
#5

AW: Chromoflex mit Delphi ansteuern

  Alt 18. Aug 2010, 13:58
Ok das nimmt der an jetzt sind nur 2 neue Probleme aufgetaucht.

Buffer[1]:=address / (256 * 256); Da sagt der mir Byte und Extended sind Inkompatible Typen.

Das müsste ich noch umwandeln. Gibt es ne FUnktion in etwa inttobyte oder so?


Und mit dem CRC16 Check, weiß ich nicht ob das die richtige funktion ist.

Delphi-Quellcode:
procedure ByteCrc(data:byte;var crc:word);
VAR i:BYTE;
BEGIN
 FOR i:=0 TO 7 DO
  BEGIN
   IF ((data and $01)XOR(crc AND $0001)<>0) THEN
    BEGIN
     crc:=crc shr 1;
     crc:= crc XOR $A001;
    END
   ELSE crc:=crc shr 1;
   data:=data shr 1; // this line is not ELSE and executed anyway.
  END;
END;

In Basic sieht die so aus:

Code:
private void CalculateCrc16(byte[] buffer, int index)
        {
            UInt16 crc = 0xFFFF;

            for (int i = 0; i < index; i++)
            {
                crc ^= buffer[i];
                for (int j = 0; j < 8; j++)
                {
                    // process each bit
                    if ((crc & 1) == 1)
                    {
                        crc >>= 1;
                        crc ^= 0xA001;
                    }
                    else
                    {
                        crc >>= 1;
                    }
                }
            }

            // write crc in buffer

            buffer[index] = (byte)(crc / 256);
            buffer[index + 1] = (byte)(crc % 256);

        }
PS: Stimmt habe gerade gesehen, das ist C#.
  Mit Zitat antworten Zitat