-> Hier kostenlos registrieren
Hallo zusammne,
ich muss unten aufgeführet Code in S7 Programmieren. Ich bin auf die Hilfe angewiesen.
public static class Crc16
{
const ushort polynomial = 0xA001;
static readonly ushort[] table = new ushort[256];
public static ushort ComputeChecksum(byte[] bytes)
{
ushort crc = 0;
for (int i = 0; i < bytes.Length; ++i)
{
byte index = (byte)(crc ^ bytes);
crc = (ushort)((crc >> 8) ^ table[index]);
}
return crc;
}
public static ushort getTableVal(int i){
return table;
}
static Crc16()
{
ushort value;
ushort temp;
for (ushort i = 0; i < table.Length; ++i)
{
value = 0;
temp = i;
for (byte j = 0; j < 8; ++j)
{
if (((value ^ temp) & 0x0001) != 0)
{
value = (ushort)((value >> 1) ^ polynomial);
}
else
{
value >>= 1;
}
temp >>= 1;
}
table = value;
}
}
}
Vielen Dank im Voraus
Gruß an alle
ich muss unten aufgeführet Code in S7 Programmieren. Ich bin auf die Hilfe angewiesen.
public static class Crc16
{
const ushort polynomial = 0xA001;
static readonly ushort[] table = new ushort[256];
public static ushort ComputeChecksum(byte[] bytes)
{
ushort crc = 0;
for (int i = 0; i < bytes.Length; ++i)
{
byte index = (byte)(crc ^ bytes);
crc = (ushort)((crc >> 8) ^ table[index]);
}
return crc;
}
public static ushort getTableVal(int i){
return table;
}
static Crc16()
{
ushort value;
ushort temp;
for (ushort i = 0; i < table.Length; ++i)
{
value = 0;
temp = i;
for (byte j = 0; j < 8; ++j)
{
if (((value ^ temp) & 0x0001) != 0)
{
value = (ushort)((value >> 1) ^ polynomial);
}
else
{
value >>= 1;
}
temp >>= 1;
}
table = value;
}
}
}
Vielen Dank im Voraus
Gruß an alle