• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

The read fonction in Borland C++ Builder

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
Seb
Asked:
Seb
  • 4
  • 3
1 Solution
 
nietodCommented:
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
 
nietodCommented:
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
 
SebAuthor Commented:
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
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.

 
nietodCommented:
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
 
SebAuthor Commented:
Ok thank you very much for your answer, I'll tchek that and ask you again if i have another questions...

Bye  Seb

0
 
nietodCommented:
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
 
SebAuthor Commented:
Ok
0

Featured Post

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!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now