| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Serial I/O {9 of 10} |
Note, I have since improved on this "considerably". If you need a
tip or two
drop me a netmail (Fido preferred at 1:259/423.0, otherwise any way you can).
Program TestComm;
{ A test program to demonstrate the send/receive aspect of the
OS2_COMM Unit by the David Muir. This program is a basic TTY
terminal with absolutely no goodies. This example uses OS/2's
crt to provide 'limited' ANSI support. Otherwise, it quite
simply sends and receives characters. }
(*
July 20, 1995 - Original Release - David Muir
*)
USES CRT, OS2_COMM, OS2BASE;
CONST
Portname : Pchar = 'COM2';
VAR
DCB:DCBrec;
a,i,num_read:longint;
ownport,quit:boolean;
ch:char;
inbuf: array [1..4096] of char;
BEGIN
clrscr;
Textcolor(11);
Writeln(' TestComm Version 1.0 by David Muir');
Write (' A Communications test for the ');
writeln('OS2_COMM unit for Virtual Pascal (Tm).');
writeln;
Textcolor(10);
ownport:=(openport(Portname));
{If 'Portname' is successfully opened, then this program "owns"
the File Handle associated with the port. }
if ownport then writeln('',Portname,' opened.')
{ If we 'own' the port, declare it opened by name.' }
else BEGIN
{ If we don't 'own' the port, then attempt to access
a port passed by a parent process. }
if FindOpenPort(nil) then BEGIN
{ NOTE - 'nil' above could be replaced by an env variable passed
by a parent process which identifies the File Handle for the
desired comport if such a variable is available
An example of this would be...
ZOC 2.052 (Tm) provides the 'ZOCHFC' environment variable to
it's OS/2 child process for this purpose. If using this 'under'
ZOC you could use this code instead.
if FindOpenPort('ZOCHFC') then BEGIN
}
writeln('Open port found. Using File Handle ',fport,'.');
writeln('Using existing comport settings.');
{ If an open port is found, declare it to the user.}
end
else BEGIN
{ If no open port is found, declare this to the user and exit. }
writeln(error);
writeln(fport);
write('Failed to open ');
writeln(Portname);
halt;
end;
end;
if ownport then BEGIN
{ If we own the port, then set the port }
if Setline (8,0,0) then writeln('Settings - 8,N,1')
else BEGIN
{ If unable to set 8,N,1 then fail and exit. }
writeln('Failed to set 8N1');
if DosClose(Fport)=0 then writeln('closed');
halt;
end;
getdcb(dcb); { No reason, it just seemed like the thing to do }
a:=GetEbaud(3); { Find the highest supported baudrate }
if SetEBaud (a)=a then writeln('Speed - ',a,' BPS.')
{ Set the Baudrate to the maximum speed. It IS OS/2 after all!! }
else BEGIN
{ If unable to set Baud Rate then fail and exit }
writeln('Failed to set Baud');
if DosClose(Fport)=0 then writeln('',Portname,' closed.');
halt;
end;
end;
{ If we made it this far we have access to a port }
writeln('Press ''CTRL-X'' to eXit.');
textcolor(7);
assign(output,''); { These four lines are here "just" to allow }
assign(input,''); { OS/2 to provide the ANSI support }
reset(input); { In your programs I recommend including your own }
rewrite(output); { support for any terminal emulations you need }
repeat
if keypressed then BEGIN
localecho:=carrier;
{ turn off the local echo when no carrier is present }
ch:=readkey;
___ Blue Wave/QWK v2.12
--- Renegade v10-05 Exp
* Origin: Scrawled From the Tomb..(416-255-2164) (1:250/346)SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 515 628 704 713/888 800/1 7877/2809 @PATH: 250/346 426 702 3615/50 396/1 270/101 105/103 42 712/515 711/808 @PATH: 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.