Herunterladen Inhalt Inhalt Diese Seite drucken

küenle CM-232 Betriebsanleitung Seite 33

Inhaltsverzeichnis

Werbung

Beispiel: Programmfolge(C#)
private int Modbus_CRC(string
{
int
poly
= 0xA001;
int
CRC
= 0xFFFF;
for (int
i = 0; i < (int)(frame.Length); i++)
{
CRC ^= Convert.ToInt16(frame[i]);
for (int
j = 0; j < 8; j++)
{
if
((CRC & 0x01) == 0x01)
{
CRC >>= 1;
CRC ^= poly;
}
else
{
CRC >>= 1;
}
}
}
return
CRC;
}
Aufruf der Funktion für das Telegramm: „0x02 0x07"
string
temp_s = Convert.ToString((char)(0x2))+ Convert.ToString((char)(0x7));
Console.WriteLine(Modbus_CRC(temp_s));
Ergebnis:
CRC niederwertiges Byte (low byte)
CRC höherwertiges Byte (high byte)
Die Modbus CRC Abfolge ist:
• CRC
Low Byte / High Byte
KFU 2-/4-
frame)
// polynom
// start CRC
// für jedes Zeichen
// ExOR
// acht mal
// lsb == 1 ?
// schieben links
// ExOR
// schieben links
4673
32
= 0x1241
= 0x41
= 0x12
0x41
0x12

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für küenle CM-232

Diese Anleitung auch für:

Cm-485

Inhaltsverzeichnis