?
Solved

Blocking WriteFile to COM port

Posted on 2002-07-15
6
Medium Priority
?
2,318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

743 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