From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Communicate with a FT232R device on Windows 7

I connect a FT232R device controlled by a VMX controller(http://www.velmex.com/Products/controls/VXM_Controller.htmll). The device is connected to the COM9 port and I use the ftd2xx.lib library. Here is my code:

FT_STATUS ftStatus;FT_HANDLE ftHandle;
char Buf[64];

// the device found is **FT232R USB UART**ftStatus = FT_ListDevices(0, Buf, FT_LIST_BY_INDEX | FT_OPEN_BY_DESCRIPTION); 
ftHandle = FT_W32_CreateFile(Buf, GENERIC_READ | GENERIC_WRITE, 0, 0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FT_OPEN_BY_DESCRIPTION,
0);

if (ftHandle == INVALID_HANDLE_VALUE) {
   //error
}
const char* cmd = "command"
bool res = FT_W32_WriteFile(ftHandle, (LPVOID)cmd, strlen(cmd), &bytes_written, NULL);
if (bytes_written != strlen(cmd) || res == false) {
   //error
}FT_W32_CloseHandle(ftHandle);

On Mac I can connect to the serial port and send the "command" to the device and everything works fine.

On Windows I can connect to the device, there is no error in FT_W32_CreateFile or FT_W32_WriteFile, but when I send "command" nothing happens, the device doesn't react.

After a long search I think that maybe the problem is in the terminational character. I tried adding \r and/or \n at the end, beginning and both(end and beginning) but still not working.

I also don't specify to which serial port it should connect because I think that is enough to give the device(see Buf in the code).

Any ideas on what could be the problem ?

Thanks

0 Kudos
Message 1 of 4
(4,199 Views)

Hi sadara, 

I would recommend checking the serial settings on the port you are using if you have not already. The baud rate or number of stop bits could be incorrect for the device you are communicating with. The serial device manual should give you what these settings should be, along with any termination characters which are required. 

I would also suggest trying to manually send commands from a serial terminal, such as Putty, to confirm that you have everything configured correctly. It seems like the device works since it can be communicated with from a different PC, so you could also try finding examples for the device using that specific driver. Unfortunately, it doesn't appear that anything you are using is an NI Product so you might receive more direct help on forums related to the products you are using. 

Charlie J.
National Instruments
0 Kudos
Message 2 of 4
(4,174 Views)

Thanks for the answer. I tried using Putty, but I cannot really figure out how it works. I open a serial port and I put Local Echo on Force on so I can write in the terminal, but when I click enter nothing happens. Do you know how can I send a message to the device using putty ?

0 Kudos
Message 3 of 4
(4,170 Views)

Hi sadara, 

You should simply be able to configure Putty for the correct port and serial settings. Again, those would be dependant on the device in question. You would also need to send any necessary termination characters.

Charlie J.
National Instruments
0 Kudos
Message 4 of 4
(4,167 Views)