Solved

Reading from serial port

Posted on 1999-01-21
10
568 Views
Last Modified: 2012-08-14
I have to process and store data that comes from a measuring instrument via serial interface (4800 baud, 8Bit, 1 Stopbit, no parity). The instrument sends the date correct, I can test this with a terminal program, the only problem is to recieve the data it sends.
Simply listening on the port only produces garbage (as expected), and I don't know how to initialize the COM port to read from it. The most specific help I have found about that topic in programming guides was "there are standard libraries for that problemn with most compilers", but neither which library nor which routines or how to use them.

The program hast to run under DOS, as we can't know which computer we will take out. For compilation I use Turbo Pascal 7.0, but there are also a Turbo-C and a Delphi compilers available. If you can help me, please send a short description of the routines, where to find them and how to use them. If all other fails, and you have some Low-Level routines, I can test them too.
Thanks in Advance
0
Comment
Question by:mdietz
[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
  • 5
  • 4
10 Comments
 

Expert Comment

by:rosch
ID: 1217504
You have that to place a program in pascal resident in memory. That he will be activated by arrived of data in the serial input that to choose. for this you needs to use the table of interrupt sees a book that describes which is the arrived interruption of  data in the serial gate. Thus that to arrive data in the serial gate its program will be activated, ok.

0
 
LVL 3

Expert Comment

by:vikiing
ID: 1217505
I've developed an application like yours, a simple running program, and not a TSR.

Unfortunately, Pascal has nothing to deal adequately with serial ports; thus, I had to make all the job "manually", this is, I had to work with the PIC (Programmed Interrupt Controller), with serial ports registers and all that stuff.

With that, my application reads up to 9600 baud with no problem. Send me a mail if you want relevant code, 'cause it's to big to paste it here.
0
 
LVL 2

Author Comment

by:mdietz
ID: 1217506
rosch:I was looking for the unit and the routines and something that described how. If you think I have to write a driver for the use of the serial port you have to be more specific than that.

vikiing: I've got some description of the port and the corresponding interrupt 14 from friends, I will test if that's enough, else I'll leave a note here or contact you.
0
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
LVL 3

Expert Comment

by:vikiing
ID: 1217507
Int 14 serves only to initialize serial port, but not for I/O transfer itself, which must be accomplished by an interrupt routine and another stuff.

0
 
LVL 2

Author Comment

by:mdietz
ID: 1217508
After initializing the the serial port for the correct transfer protocol (baud, parity and so on) the com status register can be asked and a transfer based on this info is easily programmed (without writing own interrupt routines). It seems the only problem was to initialize the com port at the start, that the Status register and serial port showed such strange values...

Thanks anyway to all who helped me, I'll delete this question in a few days
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1217509
>>(without writing own interrupt routines).

That's true if you handle com port under a "programmed I/O" scheme. With that, you read data at the moment you need it (and when you know it's present at port).

But if your instrument generates data which arrive to port while YOU'RE NOT waiting for them, then you must write an interrupt routine in order to not loose the unsolicited input.

0
 
LVL 2

Author Comment

by:mdietz
ID: 1217510
I programmed a blind sending/dumb listening (the receiver waits until a defined "start" character is transferred and then stores the input to disk until the sender sends a defined "stop" character. This should have be working, as I can tell the instrument when to send, but it seems that somewhere in the transfer some bytes disappeared and the remaining data was useless after the byte positions were mixed up.
If you can send your routines to handle that problem to martin@rbg.informatik.tu-darmstadt.de I will test them, and if they can solve the problem
you get the points.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1217511
>>it seems that somewhere in the transfer some bytes disappeared

I supose it occurs because the instrument is sending data at a moment in which you're not listening to the port. That's why you need an interrupt procedure which catches all coming bytes, no matter what the rest of the program is doing. I'll prepare the things to mail you.
0
 
LVL 3

Accepted Solution

by:
vikiing earned 50 total points
ID: 1217512
I have sent a mail to Mdietz with the routines, and he found them useful for his job.

I anybody wants them, just only put a mail.

0
 
LVL 2

Author Comment

by:mdietz
ID: 1217513
Thanks
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses

632 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