2016-06-06 5 views
1

Ich versuche, Bilddaten (JPEG) von FTDI FT2232-Gerät in Windows-Form mit Visual C++ CLR zu erhalten. Der gesamte Vorgang findet bei Klick auf die Schaltfläche statt. Ich schreibe die empfangenen Daten in. Bin-Datei in der Leseoperation selbst. Die Anzahl der Bytes I erhalten sind um 19k und die Datei hat 57k ByteDatei hat mehr Bytes als erwartet ... Daten aus FTDI gelesen und in .bin-Datei geschrieben

darf ich nicht um Bilder hochzuladen, damit ich den Code teilen bin und wringen die Ausgabe erhalte ich

FT_HANDLE ftHandle; 

    FT_STATUS ftStatus; 
    DWORD BytesWritten;  //DWORD is 32 bit unsigned 
    DWORD RxQueueBytes=0; 
    DWORD TxQueueBytes; 
    DWORD buff = 0; 
    char TxBuffer[10];  // Contains data to write to device 
    char RxBuffer[16000]; // Contains data recieved from the FTDI devide 
    DWORD BytesReceived; 
    DWORD RxBytes = 0; 
    DWORD TxBytes = 0; 
    DWORD EventDWord; 


    ftStatus = FT_Open(0, &ftHandle); 
    if (ftStatus != FT_OK) { 
     // FT_Open failed 

     return; 
    } 
    TxBuffer[TxBytes++] = 0x30; 
    TxBuffer[TxBytes++] = 0x2; 
    TxBuffer[TxBytes++] = 0x0; 
    TxBuffer[TxBytes++] = 0x42; 
    TxBuffer[TxBytes++] = 0x01; 

    ftStatus = FT_Write(ftHandle, TxBuffer, TxBytes, &TxBytes); // Data send command 
      if (ftStatus == FT_OK) 
      { 
       printf(" FT_Write is Ok \n"); 
       Sleep(5000); 
      } 


    FT_GetQueueStatus(ftHandle, &RxQueueBytes);   // Read queue 
       if (ftStatus == FT_OK) 
       { 
        printf(" (after wtite)Rx_queue_Bytes = %i\n", RxQueueBytes); 
       } 

    FT_GetStatus(ftHandle, &RxQueueBytes, &TxQueueBytes, &EventDWord); // Read queue 
      if (ftStatus == FT_OK) 
      { 
       printf(" (after wtite)Rx_queue_Bytes = %i\n", RxQueueBytes); 
       printf(" (after wtite)TxQueueBytes = %i\n", TxQueueBytes); 
       printf(" (after wtite)EventDWord = %i\n\n\n\n", EventDWord); 
      } 




    ftStatus = FT_Read(ftHandle, RxBuffer, RxQueueBytes, &RxBytes); 
    if (ftStatus == FT_OK) 
    { 



     printf(" FT_Read Ok\n"); 
     printf(" Recieved Byte = %c %c %c %c\n", RxBuffer); 
     ofstream fout("ImageData.bin"); //writing ti file 
       if (fout.is_open()) 
       { 
        //file opened successfully so we are here 
        printf("File Opened successfully!!\n"); 

        for (int i = 0; i != RxQueueBytes; i++) 
        { 
         //if (RxBuffer[i]==31) 
         fout << RxBuffer[i] << endl; //writing ith character of array in the file 
        } 
        printf("Array data successfully saved into the file ImageData"); 
       } 
       else //file could not be opened 
       { 
        printf("File could not be opened."); 
       } 

    } 
    else 
    { 
     printf(" FT_Read Failed"); 
    } 

    getchar(); 

    FT_Close(ftHandle); 

    return; 

die Ausgabe sagt

Rx_queue_Bytes = 19283 

die Eigenschaften von ImageData.bin sagt es 57892 Bytes hat Bitte erläutern

Antwort

0

Öffnen der Datei im Binärmodus und Entfernen von Endl in Fout-Befehlszeile löste das Problem.

ofstream fout("ImageData.dat", ios::out| ios::binary); 
     if (fout.is_open()) 
     { 
      //file opened successfully so we are here 
      printf("File Opened successfully!!\n"); 

      for (int i = 0; i < Img_Read_index; i++) 
      { 

       fout << point[i] ; //writing ith character of array in the file 
      } 
      printf("Array data successfully saved into the file ImageData"); 
      fout.close(); 
     } 
     else //file could not be opened 
     { 
      printf("File could not be opened."); 
     } 
Verwandte Themen