Solved

Blocking WriteFile to COM port

Posted on 2002-07-15
6
2,273 Views
Last Modified: 2012-06-22
Hi there.  I'm using a TCommPortDriver component, but when I write to the COMPort (using SendString) without my RS485 device connected, the whole program freezes up.  It freezes only when I have hardware handshaking (RTS/CTS) enabled and it freezes on the "WriteFile" statement.  Is there any way to make it non-blocking?
0
Comment
Question by:PaulKorzycki
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:mullet_attack
ID: 7154708
you could check the handshaking status of your RS485 device , and if it's not on-line, then don't write to it
0
 

Author Comment

by:PaulKorzycki
ID: 7154715
how do you check the status?  What should I look for?  Why does WriteFile get stuck anyways, does it wait for CTS?
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 50 total points
ID: 7155756
i don't know the comm component your using, but i'll assume since it supports handshaking, it should have a CTS property or some sort of GetCTSStatus method.
if that's the case, determine the status of CTS when your RS485 device is not connected, and when it is connected.
if the status is the same, then we have a problem. if different then simply test for the appropriate status before you try writing to the port.

WriteFile can be used both blocking and non-blocking (overlapped i/o). I guess in your comm component it's used in blocking mode. try using a different comm component.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:PaulKorzycki
ID: 7159942
Thanks for all the help.  The component I'm using is v2.0 of TCommPortDriver by Marco Cocco.  It doesn't seem to have any way to check the CTS status, but I'm going to see if I can do it myself.  Any comments on how to do this via delphi?
0
 

Author Comment

by:PaulKorzycki
ID: 7160005
I figured it out.  The component sets the comm status using SetCommStatus.  One of the parameters it sets up in the dcb (device control block) is a flag that specifies options.  One of these options is "OutxCtsFlow" which makes the port wait for CTS to be high before sending any data!  I simply changed this flag to not include this option, and it works now.

The following site has great information regarding serial port functionality in Delphi:

http://www.geocities.com/macrotech_tr/hardware/tserialport.html

Thanks again!
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 7160048
looks like you just disabled the h/w handshaking.

here's the code from your component  :

case FComPortHwHandshaking of // Type of hw handshaking to use
    hhNONE:; // No hardware handshaking
    hhRTSCTS: // RTS/CTS (request-to-send/clear-to-send) hardware handshaking
      dcb.Flags := dcb.Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake;

You would have achieved the same result by setting hwflowcontrol property to "none" in the IDE

you could add an RTS_State property to the component, and get the value of RTS by using GetCommModemStatus. It will tell you what RTS is doing.

if that's of interest, I can help further, but not now. It's 2:45 AM, and I am a bit tired....
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question