Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading Serial port in Pascal

346 views
Skip to first unread message

Steve Gilbert

unread,
Jun 7, 1993, 6:10:51 AM6/7/93
to
I have been trying to read from the serial port, but nothing seems to come
through.

The port is connected to another machine, which is sending a string of data
at 4800 baud, 8N1.

My program looks something like

ASSIGN(data, 'COM1');
RESET(data);
REPEAT
READ(data,string);
WRITELN(string);
UNTIL string='end';

and I have done a MODE com1 4800,N,8,1 before running the program. It runs ok
with no errors, but nothing comes through from the port.

What am I doing wrong?

I'm using turbo-pascal, MSDOS3.3 (I've tried it on DOS 5 also).


Thanks,

Steve.

--
___
(o o)
--------------------------------ooO(_)Ooo----------------------------------
Steve Gilbert, 38 Melrose Road, Gainsborough, Lincs. DN21 2SD
st...@donald.demon.co.uk sgil...@cix.clink.co.uk
---------------------------------------------------------------------------

Greg Foulds

unread,
Jun 7, 1993, 1:17:32 PM6/7/93
to

I'm not sure, but ASSIGN(data, 'COM1'); may be wrong. (Is COM1 supposed to be in
quotes?)

I think that may be your problem, it might think you are dealing with text file.

One big problem is this part:

REPEAT
READ(data,string);
WRITELN(string);
UNTIL string='end';


Actually, there are two problems, the first is that you are reading one letter
at a time, and WRITELN will put each letter on a new line. The second is that
since you are only reading one letter at a time, 'end' will never occur. A
quick-fix for this would be to have it quit when it found a certain character,
such as a ~. Oops, found another problem, you should write it so that it only
writeln's STRING when STRING is new. (Otherwise, you are going to have the last
letter repeating until another letter is sent)

If you look in the TP manual, there is a sample comm program, otherwise, I can
send you some code thru email.

-Greg

James Paul Henley

unread,
Jun 8, 1993, 1:17:20 PM6/8/93
to
In article <1993Jun7.1...@udel.edu> gfo...@bach.ee.udel.edu (Greg Foulds) writes:
>
>One big problem is this part:
>
>REPEAT
> READ(data,string);
> WRITELN(string);
> UNTIL string='end';
>

Yep, but for a _very_ subtle reason. Since he is using READ, it will not
be able to get past the end of the first line when reading strings! It seems
that he is assuming that TP reads one word at a time when reading strings.
Instead, TP reads whole lines at a time, unless the length of the string
is less than the length of the line. Try changing the READ to a READLN
and see if that will fix it.

0 new messages