Solved

The read fonction in Borland C++ Builder

Posted on 1998-07-29
7
204 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now