LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Using RS232 on W2K

Hello:
 
I'm trying to send one byte over RS232. To do this, I just put a button (called TXA). It's callback function is:
 
int CVICALLBACK TXA (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 
 switch (event)
  {
  case EVENT_COMMIT:

   OpenComConfig (1, "", 9600, 0, 8, 1, 0, 0);
   ComWrtByte (1, 'J');
   CloseCom (1);
   
   break;
   
   
  }
 return 0;
}
 
The trouble is that I don't send nothinhg. Why? What's wrong in the code?
 
Thanks
0 Kudos
Message 1 of 3
(3,161 Views)

You might be closing the COM functions before the actual data has had time to be sent. In which case you should use GetOutQLen () to check that the data has gone before you close the port.

It is possible that the PC platform you are using does not have a COM1 port: on laptops with USB RS232 adaptors they are often numbered COM3 or COM4.

If you check the return codes for the functions you are using (or run the program in Debug mode) you might receive some unexpected information back from the library calls which could point you in the right direction.

JR

0 Kudos
Message 2 of 3
(3,163 Views)
You could also try to exclude output buffer and write directly to the port: to do so, simply pass -1 as Output queue size parameter (see function help for documentation).
Excluding the output buffer can avoid that the operating system introduces some lag between your command and actual output to the port (remember you have a CloseCom immediately after ComWtr),

Test your software not closing the port after writing: if you succeed in communicating, you should consider either to introduce a fixed pause after writing to the port or to move CloseCom in a separate function (end of program?) executed not immediately after ComWrt.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(3,152 Views)