Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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");
        }
         }
Posted

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
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900