Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


The read fonction in Borland C++ Builder

Posted on 1998-07-29
Medium Priority
Last Modified: 2010-04-02
        I have to read on the serial port in Hyper-console mode.  I use the read fonction:
read(IDcom2,&szCommandString,1);  where IDcom2 is the handle, obtain with the open fonction, szCommandString is my buffer and i have just 1 charactere on my serial port. szCommandString is a char [256].  The Compilation is OK, but when I execute my program, the program stopped at the read fonction?? and I don't no why?

Can you help me?
Question by:Seb
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
  • 4
  • 3
LVL 22

Expert Comment

ID: 1168984
It probably depends on how the serial port "file" has been set.  If it is set to do blocking I/O, the read() function will wait until enough bytes have come into the serial port to fill the request.  If that is the case and if no bytes come in, read() won't return.
LVL 22

Expert Comment

ID: 1168985
You might want to try using the windows API procedures to read from the serial port.  You can set the serial port "file" to have specific desired wait options.  I can elaborate if you are interested in that route.

Author Comment

ID: 1168986
OK thanks,

   If you can elaborate about API procedures, I'll be very happy...because I not really know this windows applications.

Thank you in advance!
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 22

Accepted Solution

nietod earned 300 total points
ID: 1168987
Let me start by giving you the names of 4 or 5 functions that you will need and a brief explantion of them.  look them up in the docs and do your best to understand them, then ask me if you have questions.  

1.  You will open the file with CreateFile().  You will specify a name like "COM1" for the file name.  This returns a handle to the file that you will use in the remaining procedures.
2.  You will use SetCommTimeouts() to set the time limit for which reads and write operations to the handle should wait.
3.   You will use ReadFile() to read data from the file (serial port.)
4.  When done you will use CloseHandle() to close the file.

Since these functions have pretty lengthy documentation, read about these functions and then ask me questions if you have any.

Author Comment

ID: 1168988
Ok thank you very much for your answer, I'll tchek that and ask you again if i have another questions...

Bye  Seb

LVL 22

Expert Comment

ID: 1168989
In the future always make sure an answer works and you have all the necessary information before accepting an answer.  That way if a problem comes up you can reject the answer and get more help from other experts.  I don't think there will be a problem here, but you never know.

Author Comment

ID: 1168990

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

636 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