Solved

The read fonction in Borland C++ Builder

Posted on 1998-07-29
7
214 Views
Last Modified: 2010-04-02
Hi!,
        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?
0
Comment
Question by:Seb
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 22

Expert Comment

by:nietod
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.
0
 

Author Comment

by:Seb
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!
0
Independent Software Vendors: 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!

 
LVL 22

Accepted Solution

by:
nietod earned 100 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.
0
 

Author Comment

by:Seb
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

0
 
LVL 22

Expert Comment

by:nietod
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.
0
 

Author Comment

by:Seb
ID: 1168990
Ok
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

756 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