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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Definition of XON/XOFF character for serial communication

I have to communicate to a serial devices which seems to use SW handshaking but it does not use the (standard) data bytes 0x11 and 0x13 as XON and XOFF chars but rather 0x08 and 0x10.
Is there any possibility within the RS232 Library to set the XON/XOFF characters to be used ?
Thanks for your help !!
Best regards
Torsten
 
0 Kudos
Message 1 of 3
(5,471 Views)
Torsten,

This is not directly supported by the RS-232 library, but you can probably get there by using the GetSystemComHandle function and calling Windows SDK functions yourself.  The library opens a Windows file handle for the port, which GetSystemComHandle retrieves for you.  Then you can use the SetCommState function in the Windows SDK to change the XON and XOFF characters.  It might go a little something like this:

HANDLE hFile;
DCB deviceControlBlock;

OpenCom(port, "");
...
GetSystemComHandle(port, &hFile);

// Call the following lines after OpenCom/Config, SetXMode, and SetCTSMode
GetCommState(hFile, &deviceControlBlock);
deviceControlBlock.XonChar = 0x08;
deviceControlBlock.XoffChar = 0x10;
SetCommState(hFile, &deviceControlBlock);


Note that the code first populates the structure with the current settings into the structure before making tweaks and applying the new settings. 

OpenCom/Config, SetXMode, and SetCTSMode all call SetCommState internally, with the XON and XOFF characters hardcoded to the standard values, so you'll have to reset your custom XON/XOFF characters after each time you call these functions.  XModemSend and XModemReceive also set the XON/XOFF characters, but you'll have no chance to change them to your custom values before the functions execute the transfer.

Mert A.
National Instruments
0 Kudos
Message 2 of 3
(5,469 Views)
Dear Mert,
 
thanks for your reply.
I tried it and it works perfectly the way you proposed.
Thanks again for your help !
Best regards
           Torsten
 
0 Kudos
Message 3 of 3
(5,446 Views)