德语说明书CRC代码转换成VB6 [英] German instruction manual CRC code into VB6

查看:92
本文介绍了德语说明书CRC代码转换成VB6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




对不起真的很远,但我有一本德语手册令我困惑!它显示了如何为我试图在VB6中编写代码的串行设备计算CRC值。我不仅不懂德语,而且这个例子不是我所认识的语言(落入每一个障碍!)。最终我需要将显示的内容转换为VB6代码,但即使知道该示例的语言也会对我的Google搜索有所帮助。



这里来了....



4.6 Berechnung des CRC-Zeichens

FolgenderProgrammabschnitirklärtdieBerechnung des CRC-Zeichens。 Der Type U8 ist eine 8bit-Variable ohne Vorzeichen(0 bis 255)

Die Funktion put_tx1_buffer(U8 c)sendet einZeichenüberdieserielle Schnittstelle。





 #define POLYNOM 0xB1 // 28 + 27 + 25 + 24 + 20 + 1 
#define INIT_TX_CRC {tx_crc = 0xA5;} U8 tx_crc;
void build_tx_crc8(U8 a)
{
U8 i = 8;
do
{
if((a& 0x01)!=(tx_crc& 0x01))
{
tx_crc>> = 1;
tx_crc ^ = POLYNOM;
}
其他
{
tx_crc>> = 1;
}
a>> = 1;
}
while( - i!= 0);
}

void set_lamp(U8 keyboardnumber,U8 lampnumber,U8命令)
{
INIT_TX_CRC;
put_tx1_buffer(STX + 0x80); build_tx_crc8(STX + 0x80); put_tx1_buffer(command); build_tx_crc8(命令); put_tx1_buffer(keyboardnumber); build_tx_crc8(keyboardnumber); put_tx1_buffer(lampnumber); build_tx_crc8(lampnumber); put_tx1_buffer(ETX + 0x80); build_tx_crc8(ETX + 0x80); put_tx1_buffer(tx_crc);
}





我的尝试:



谷歌翻译,C#但似乎不是那样。

解决方案

看起来像C代码但不完整。缺少部分代码。

正确缩进的代码更容易阅读。

 # define POLYNOM 0xB1 // 28 + 27 + 25 + 24 + 20 + 1 
#define INIT_TX_CRC {tx_crc = 0xA5;} U8 tx_crc;
void build_tx_crc8(U8 a)
{
U8 i = 8 ;
执行
{
if ((a& 0x01) !=(tx_crc& 0x01))
{
tx_crc>> = 1 ;
tx_crc ^ = POLYNOM;
}
其他
{
tx_crc>> = 1 ;
}
a>> = 1 ;
}
while ( - i!= 0 );
}

void set_lamp(U8 keyboardnumber,U8 lampnumber,U8命令)
{
INIT_TX_CRC;
put_tx1_buffer(STX + 0x80);
build_tx_crc8(STX + 0x80);
put_tx1_buffer(command);
build_tx_crc8(命令);
put_tx1_buffer(keyboardnumber);
build_tx_crc8(keyboardnumber);
put_tx1_buffer(lampnumber);
build_tx_crc8(lampnumber);
put_tx1_buffer(ETX + 0x80);
build_tx_crc8(ETX + 0x80);
put_tx1_buffer(tx_crc);
}



看起来像8位CRC计算。

循环冗余校验 - 维基百科 [ ^ ]


这是一个可能为某种微控制器编写的CRC计算的C实现。



即使你会知道C并理解算法将它转换为VB6没有多大意义(尽管可能)。您可能想要计算字符串或二进制数据序列的CRC。您应该能够在网上找到示例。



如果要为C代码编写相同设备的代码,则使用相同的起始值(十六进制A5)和相同的多项式(十六进制B1)。如果没有,这些必须在串行设备的文档中指定。



然后使用网络中的示例在VB中实现CRC算法。



或者自己动手。这很简单:


  • 您正在使用字节值(也可能是单个字符)

  • 创建一个用于保存CRC并使用起始值初始化它的变量

  • 在处理8位的循环中对输入的每个字节/字符应用CRC:
    • 如果输入字节的LSB(最低位)和CRC相同,则向右移动一次

    • 否则也将右移一次并将CRC值与XOR进行异或运算多项式
  • CRC变量现在包含计算出的CRC


< blockquote>您不需要翻译德语。但是你需要理解 C VB6 编程语言。您还可以使用 C 源构建 DLL 并在 VB6中使用它申请。


Hi
Sorry really long shot but I have a manual in German which is baffling me! It shows how to calculate a CRC value for a serial device I'm trying to write code in VB6 for. Not only do I not understand the German but the example isn't in a language I recognize (falling at every hurdle!). Ultimately I need to turn whatever this reveals into VB6 code but even knowing what language the example is would help in my Google searches.

Here it comes....

4.6 Berechnung des CRC-Zeichens
Folgender Programmabschnitt erklärt die Berechnung des CRC-Zeichens. Der Type U8 ist eine 8bit-Variable ohne Vorzeichen (0 bis 255)
Die Funktion put_tx1_buffer( U8 c ) sendet ein Zeichen über die serielle Schnittstelle.


#define POLYNOM 0xB1  // 28+27+25+24+20+1
#define INIT_TX_CRC {tx_crc=0xA5;} U8 tx_crc ;
void build_tx_crc8( U8 a )
{
U8 i=8 ;
do
{
if (( a & 0x01 ) != ( tx_crc & 0x01 ))
{
tx_crc >>= 1 ;
tx_crc ^= POLYNOM ;
}
else
{
tx_crc >>= 1 ;
}
a >>= 1 ;
}
while  (--i!=0) ;
}

void set_lamp( U8 keyboardnumber, U8 lampnumber, U8 command )
{
INIT_TX_CRC ;
put_tx1_buffer( STX+0x80               ) ; build_tx_crc8( STX+0x80             ) ; put_tx1_buffer( command                  ) ; build_tx_crc8( command                  ) ; put_tx1_buffer( keyboardnumber      ) ; build_tx_crc8( keyboardnumber       ) ; put_tx1_buffer( lampnumber             ) ; build_tx_crc8( lampnumber              ) ; put_tx1_buffer( ETX+0x80               ) ; build_tx_crc8( ETX+0x80               ) ; put_tx1_buffer( tx_crc                       ) ;
}



What I have tried:

Google translate, C# but didn't seem to be that.

解决方案

Looks like C code but not complete. Part of the code is missing.
Correctly indented code is easier to read.

#define POLYNOM 0xB1  // 28+27+25+24+20+1
#define INIT_TX_CRC {tx_crc=0xA5;} U8 tx_crc ;
void build_tx_crc8( U8 a )
{
    U8 i=8 ;
    do
    {
        if (( a & 0x01 ) != ( tx_crc & 0x01 ))
        {
            tx_crc >>= 1 ;
            tx_crc ^= POLYNOM ;
        }
        else
        {
            tx_crc >>= 1 ;
        }
        a >>= 1 ;
    }
    while  (--i!=0) ;
}

void set_lamp( U8 keyboardnumber, U8 lampnumber, U8 command )
{
    INIT_TX_CRC ;
    put_tx1_buffer( STX+0x80               ) ;
    build_tx_crc8( STX+0x80             ) ;
    put_tx1_buffer( command                  ) ;
    build_tx_crc8( command                  ) ;
    put_tx1_buffer( keyboardnumber      ) ;
    build_tx_crc8( keyboardnumber       ) ;
    put_tx1_buffer( lampnumber             ) ;
    build_tx_crc8( lampnumber              ) ;
    put_tx1_buffer( ETX+0x80               ) ;
    build_tx_crc8( ETX+0x80               ) ;
    put_tx1_buffer( tx_crc                       ) ;
}


It looks like some 8 bits CRC calculation.
Cyclic redundancy check - Wikipedia[^]


It is a C implementation of a CRC calculation written probably for some kind of microcontroller.

Even if you would know C and understand the algorithm it would not make much sense to convert that to VB6 (while possible). You probably want to calculate the CRC for a string or a sequence of binary data. You should be able to find examples in the net.

If you are going to write code for the same device as the C code, you have use the same start value (hex A5) and the same polynomial (hex B1). If not, these must be specified in the documentation for your serial device.

Then implement the CRC algorithm in VB using examples from the net.

Or do it yourself. It is quite simple:

  • You are working with byte values (which may be also single characters)
  • Create a variable to hold the CRC and initialse it with the start value
  • Apply the CRC for each byte / character of the input within a loop handling the 8 bits:
    • If the LSB (the lowest bit) of input byte and CRC are identical shift both right by one
    • Otherwise shift also both right by one and XOR the CRC value with the polynomial
  • The CRC variable contains now the calculated CRC


You don't need to translate from German. But you do need to understand both C and VB6 programming languages. You might also build a DLL using the C source and consume it in your VB6 application.


这篇关于德语说明书CRC代码转换成VB6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆