Разработка, производство и продажа радиоэлектронной аппаратуры
|
Требуется программист в Зеленограде - обработка данных с датчиков; ColdFire; 40 тыс.
e-mail: jobsmp@pochta.ru
|
вот код (+), пишу по даташите FTDI- не работает. вопрос- почему? устройство определяется, но данные не принимаются
Отправлено
Метценгерштейн (213.33.244.142) 04 мая 2010, г. 18:18
В ответ на:
по ссылкам тут не ходят. запости здесь. отправлено
fanta 04 мая 2010, г. 18:09
вот код.
// 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-й виртуальный ком- порт в устройстве- на него данные шлю.
Кто подскажет в чем дело? Вроде как все по даташиту сделано.
Составить ответ | Вернуться на конференцию
Ответы