Solved

The read fonction in Borland C++ Builder

Posted on 1998-07-29
7
215 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
[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
  • 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
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!

 
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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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