Solved

Blocking WriteFile to COM port

Posted on 2002-07-15
6
2,300 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 97
Open a URL with Internet Explorer in a new tab (not a new window) 1 186
Convert a string into a TDateTime 5 80
RESTRequest Parameter 4 79
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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