将CRC32合并到我的C ++项目中 [英] incorporate CRC32 in my C++ project

查看:102
本文介绍了将CRC32合并到我的C ++项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c ++编程语言的新手,我被分配了一个项目,该语言是可视c ++.
该项目是关于编写程序以将数据从计算机(USB端口)传输到FT232R芯片的.我提供了ftd2xx驱动程序,其中包括一些非常简单的函数,即FT_Open(),FT_Write(),FT_Close(),并且代码可以正确编译.我的第一个问题是我怎么知道此代码功能?请提供一些简单可行的方法.
我的演讲要求我将CRC32集成到此功能中,据我所知,CRC是一种防止错误的算法.我假设我需要在发送器端对数据进行编码,并在接收器端对其进行检查.这意味着我必须对双方都进行编程吗?这是真的吗?有什么好书或网络吗?

包含FT_Open代码.这是正确的吗?我的意思是它可以在实际的沟通过程中工作.谢谢大家.

Hi,i am new to c++ programming language and i was assigned a project,the language is visual c++.
The project is about writing a program to transfer data from a computer(USB port) to a FT232R chip. I was provided with ftd2xx driver, i include some really simple functions,namely FT_Open(),FT_Write(),FT_Close() and the code can compile without error. My first problem is how do I know this code functions? please provide some easy and feasible ways.
My lecture asked me to incorporate a CRC32 to this function, as far as I know, CRC is a error-preventing algorithm. I would assume that I need to encode the data at transmitter side and check it at receiver end. That means i have to program both side?is this true? is there any good books or web ?

FT_Open code is included for you. Is this correct,i mean does it work on real communication process. Thank you guys in advance.

private: System::Void btnSend_Click(System::Object^  sender, System::EventArgs^  e) {
    DWORD BytesWritten;
    char * TxBuffer;
    TxBuffer=GetCString(rtxData->Text);
    ftStatus=FT_Write(ftHandle,TxBuffer,sizeof(TxBuffer),&BytesWritten);
        if(ftStatus==FT_OK)
        {
            MessageBox::Show("Transmission successful");
        }
        else
        {
            MessageBox::Show("Transmission failed");
        }
         }

推荐答案

CRC32是一种错误检查算法,它不能防止错误.您必须在发送方生成CRC32,并将其与数据一起打包在标头中,而在接收方,必须再次在给定的数据上生成并与标头进行比较.

crc32源
CRC32 is a error checking algorithm, it does not prevent errors. You have to generate a CRC32 on your sender side and pack it in a header with your data, and on the receiving side you have to generate again on the data given and compare with the header.

crc32 source


CRC是错误检测(不是预防")机制,请参见维基百科的CRC" ["C语言中的CRC实现代码" [ ^ ]有趣( ''指向免费提供的CRC32源代码的链接).

关于您的函数,(至少)有一个错误:sizeof(TxBuffer)总是返回字符点的大小(例如,在32位计算机上的4),而不是数据缓冲区的实际大小.
CRC is a error detecting (not ''preventing'') mechanism, please see "CRC at Wikipedia"[^]. You may find: "CRC Implementation Code in C"[^] interesting (there''s a link to freely available CRC32 source code).

As about your function, there is (at least) one mistake: sizeof(TxBuffer) always returns the size of a character point (e.g. 4 on a 32 bit machine) and not the actual size of the data buffer.


谢谢大家.
通过使用sizeof(TxBuffer),我想获取要写入设备的字节数,而不是缓冲区的大小.
Thanks to you all.
By using sizeof(TxBuffer) , I want to get the number of bytes to write into the device,not the size of the buffer.


这篇关于将CRC32合并到我的C ++项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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