реклама на сайте
подробности

 
 
> пишу под винду обращение к FTDI, непонятно, почему не считываются данные, устройство видится нормально, а массив данных =0 ???
Метценгерштейн
сообщение May 4 2010, 11:58
Сообщение #1


Профессионал
*****

Группа: Свой
Сообщений: 1 357
Регистрация: 12-04-05
Из: Петербург
Пользователь №: 4 079



вот код.

Код
// Tst_FTDI.cpp : Defines the entry point for the console application.
//



#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "ftd2xx.h"
#include <stdint.h> //uint32_t
#include <iostream> // консольный ввод/вывод
using namespace std;




LONG lComPortNumber;
DWORD numDevs;

FT_HANDLE ftHandle; // handle of an open device
FT_STATUS ftStatus;
DWORD EventDWord;
DWORD RxBytes;
DWORD TxBytes;
DWORD BytesReceived;
char RxBuffer[256];
char data;




static char buf[50];
//memset(buf,0,50);


LONG COMPORT;

char COMx[5];
int n;
int dn;

DCB dcb;
HANDLE hCommPort;
BOOL fSuccess;    

//char *message;

int GetFromDevice (void){  //dsc ftdi behavior and read him status

    ftStatus = FT_ListDevices(&numDevs,NULL,FT_LIST_NUMBER_ONLY);
    if (ftStatus != FT_OK) {     // FT_ListDevices not OK, number of devices connected is in numDevs    
        //message = "[ERROR[LISTEN_DEVICE]]";
        return 0;
    }
    // FT_ListDevices OK, number of devices connected is in numDevs
    if (numDevs > 1)
    {
        dn = 1;
    }
    else
    {
        dn = 0;
    }


    // Open the device    
    ftStatus = FT_Open(dn, &ftHandle);

    if(ftStatus != FT_OK)
    {
        //message = "[ERROR[OPEN_DEVICE]]";
        return 0;
    }

    /********************************************************/
    // Configure the UART interface parameters
    /********************************************************/

    ftStatus = FT_GetComPortNumber(ftHandle,&lComPortNumber);
    if (ftStatus != FT_OK) { // COM port assigned with number held in lComPortNumber
        return 0;
    }

    if (lComPortNumber == -1) { // No COM port assigned
        return 0;
    }

    
    /*********************************************************/
    //  FT_SetBaudRate
    /*********************************************************/
    ftStatus = FT_SetBaudRate(ftHandle, 38400); // Set baud rate to 38400
    if (ftStatus != FT_OK) { // FT_SetBaudRate not OK
         return 0;
    }

    FT_Close(ftHandle);
    return 1; // if device is preset and correct
}
//*********************************************************

int read_ft (void) {//in case of preset device
    //read device

    FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord); //data will be in a massive RxBuffer

    if (RxBytes > 0) {
        ftStatus = FT_Read(ftHandle,RxBuffer,RxBytes,&BytesReceived);

        if (ftStatus == FT_OK) { // if FT_Read OK
            return 1;
        }

        else {
            //message = "[ERROR[data has been resived, but ftStatus != FT_OK]]";
            return 0; // FT_Read Failed
        }
    }

    //message = "[ERROR[try to rread device is doesn't success]]";

    FT_Close(ftHandle); //close device
    return 0;
}






int _tmain(int argc, _TCHAR* argv[]) {
    for (;;) {

        if ( !GetFromDevice () ) { //in case of none preset device
            cout << "error" <<endl;    
            //system("pause");
        }

        else {                        //in case of preset device
            if (read_ft()) {
                data =*RxBuffer; //get char data from RxBuffer[0]

                cout << data <<endl;    
                //system("pause");
            }
        }



    }//for
    return 0;
}


Все проходит нормально, но массив RxBuffer пустой.
Почему?
я использую 2-й виртуальный ком- порт в устройстве- на него данные шлю.

Кто подскажет в чем дело? Вроде как все по даташиту сделано.

Сообщение отредактировал rezident - May 4 2010, 14:19
Причина редактирования: Оформление цитаты исходника.
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 22nd July 2025 - 05:08
Рейтинг@Mail.ru


Страница сгенерированна за 0.01351 секунд с 7
ELECTRONIX ©2004-2016