Posted 21 January 2008 - 10:24 PM
To remove all flow controll, while most arguments are 0/false, fTXContinueOnXoff should be true;
Specifies No Flow Control.
For software flow control using Xon/Xoff characters,
You need to set XonLim and XoffLim values.
XonLim and XoffLim are used to prevent the input buffer from overflowing. I believe the help file is wrong here, I will ammend it... looking at the MSDN page, it contradicts itself, those were taken directly from one of it's pages, here are correct descriptions from another of its pages:
Specifies the maximum number of bytes allowed in the queue.
The XON character is sent if the number of bytes in the queue falls below this number."
Specifies the maximum number of bytes accepted in the input buffer before the XOFF character is sent.
The maximum number of bytes accepted is calculated by subtracting this value from the size, in bytes, of the input buffer." This one should be non-zero.
XoffLim specifies how full you want to let the input buffer get before requesting that the periphrial stop transmitting. So if our input buffer can handle 500bytes maximum, and I want to leave 100bytes in it just in case it needs to send a few extra bytes of data when I ask it to stop, I set XoffLim to 100. Setting it to 0 would resault in a buffer overflow if it got filled and the device decided to send an extra byte allong.
How much room you want to leave really depends on the application and device.
XonLim is similar, except you specify how empty you want the buffer to get before you start transmitting again.
Assuming the input buffer is 500bytes, Xofflim is 100, and XonLim is 10:
Device transmits untill the input buffer has 400bytes (500-(XoffLim=100) =400) when it's told to stop, but maby it needs to send 5 extra bytes to finish up the data its transmiting.
Input buffer contains 405bytes, now your application begins reading data from the buffer, and brings it down to 20bytes still left in the buffer, then has to process the data. The XonLim has not been reached so the device still is holding back transmiting data. The application collects more information from the buffer and brings it down to 9bytes before deciding to process the data. Since XonLim is 10, and 9 is less than 10, the device is told it can start transmitting again.
Repeat ad nauseum.
With that example, the flow control function call would look like this:
To use the RTS/CTS flow control only (which is 1-way; it assumes the computer is always ready to recieve input)
Set fOutxCtsFlow to true, and fRtsControl to non-zero (1 will mean the line is always high, 3 means it's high while there is data to be sent, and 2 is a handshaking methode. 3 is probably preffered.)
I'm Not sure if the XonLim and XoffLim actualy need values for this; I can't see why they would be relevent, but you can test.
The RTS line will let your device know when theres data ready to be sent, and the CTS line will tell the computer whether it should send or not.
RS232_SetFlowControl(1,0,0,1,0,0,0,3,0,0,0,0,1) //Assuming the XonLim and XoffLim is irrelevent
Finaly, I'l look into a function to check which ports are available.