Solved

Blocking WriteFile to COM port

Posted on 2002-07-15
6
2,292 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
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 167
Delphi Form ownership 4 125
how to send memory stream from ics Client To ics server ? 11 174
Typecasting TBytes to Integer in Delphi XE8 2 33
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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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