Hi everyone,
I have a problem with the CloseCom() function, which sometimes freezes my application when tries to close a COM port. All I can do is terminate the execution of the application through the STOP button, but this does not release the COM port, and the application window does not close. In turn, I am not able to use that serial port again without rebooting the machine.
I checked this in debug mode and the program flow gets stuck while executing the CloseCom() function, thus I don't know what is the real cause as I don't know how to check deeper. This happens in both debug and release configurations, for both 32 and 64 bits program versions. This happens only with FTDI cables, in particular we use the TTL-232R-5V-AJ ( http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm ) to communicate with external hardware. I can exclude it is a problem from a specific cable as I tried several ones, and all fail in the same way.
This is the code I use for closing the COM port:
int CVICALLBACK QuitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: if(n_com)
if (hw_type) ComWrtByte (n_com, 0x41); else { ComWrtByte (n_com, COD_SCHEDA); ComWrtByte (n_com, COD_COMMAND_STOP ); ComWrtByte (n_com, COD_SCHEDA); } CloseCom (n_com); QuitUserInterface (0);
} break; } return 0; }
By looking at the following post:
it seems it could be a General Protection Fault problem (even if I don't get any error, the program just freezes) as I send bytes just before closing the COM port. Thus I tried to modify the code as follows:
int CVICALLBACK QuitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: if(n_com) if (hw_type) ComWrtByte (n_com, 0x41); else { ComWrtByte (n_com, COD_SCHEDA); ComWrtByte (n_com, COD_COMMAND_STOP ); ComWrtByte (n_com, COD_SCHEDA); } FlushInQ(n_com); FlushOutQ(n_com); Delay(0.1); CloseCom (n_com); QuitUserInterface (0); } break; } return 0; } ----- OR ----- int CVICALLBACK QuitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: if(n_com) if (hw_type) ComWrtByte (n_com, 0x41); else { ComWrtByte (n_com, COD_SCHEDA); ComWrtByte (n_com, COD_COMMAND_STOP ); ComWrtByte (n_com, COD_SCHEDA); } while(GetOutQLen(n_com)>0){}; CloseCom (n_com); QuitUserInterface (0); } break; } return 0; }
with no success. As I said, the problem seems to show up only with that cable type (other devices attached through their own serial/USB cables never fail). However, the same cable does not fail when used in other environments, such as MATLAB.
I am using LabWindows/CVI 2010 version 10.0.1 (434). I would like to avoid to update the system as this usually is a time consuming operation.
Please let me know if you need any other information
Thank you in advance