问题描述
我有一个简单的程序,尝试使用FTDI D2xx库通过串行端口写入数据。
程序仅打开端口,并尝试以一定速率写入数据。偶尔在示波器上我会看到一个1缺失的字样。我还只能通过调用SetBreakOn,然后再调用SetBreakOff来查看数据。如果不这样做,则看不到示波器上的任何数据。
我在这里做错了吗?在我的循环中,一旦发送了数据,是否会一直发送0直到我写回缓冲区?
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <ftd2xx.h>
#include <stdlib.h>
#include "string.h"
#include <unistd.h>
int main(int argc,char *argv[])
{
uint32_t numDevs;
FT_HANDLE FT_handle;
FT_STATUS FT_status; // status of the FT 232 chip
//Open Device
FT_STATUS ftStatus;
char * value = "FT4T6TXN";
ftStatus = FT_OpenEx(value,FT_OPEN_BY_SERIAL_NUMBER,&FT_handle);
if(ftStatus == FT_OK){
printf("successful open!\n");
}else{
printf("failure open! %d\n",ftStatus);
}
UCHAR Mask = 0xFF; //all output
UCHAR Mode = 0x04; //Selects the Synchronous Bit Bang Mode
ftStatus = FT_SetBitMode(FT_handle,Mask,Mode);
if (ftStatus == FT_OK) {
// synchronous Bit bang Mode enabled
printf("sync bit mode!\n");
}
else {
// FT_SetBitMode Failed!
printf("setBitModeFailed!\n");
return -1;
}
DWORD Baudrate;
Baudrate = 366;
FT_status = FT_SetBaudrate(FT_handle,Baudrate);
if(FT_status != FT_OK){
printf("BAUD RATE SET Failed! \n");
return -1;
}
uint32_t bytesWritten = 0;
UCHAR Buffer = 0x01; // data to be written to the port
//set flow control
FT_status = FT_SetFlowControl(FT_handle,FT_FLOW_RTS_CTS,NULL,NULL);
if(FT_status != FT_OK){
printf("flow not okay\n");
}
//Begin Looping Inf
while(true){
//I was unable to see Data without calling this?
FT_SetBreakOn(FT_handle);
FT_SetBreakOff(FT_handle);
//WRITE
FT_status = FT_Write( FT_handle,// handle to the chip
&Buffer,// address of the data
sizeof(Buffer),// Size of the Buffer
&BytesWritten // Number of bytes written
);
sleep(1);
if(FT_status != FT_OK){
printf("write not successful! %d \n",FT_status);
}
}
FT_Close(FT_handle); // Close the Serial port connection
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)