| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Comm Routines |
> I'm having a little trouble with the writing of the Door routines themselves.
> The low-level ASYNC stuff is already done, and I have a test program written
> that works (apparently) flawlessly. Specifically, I am stumped on how I shou
> go about writing to the local screen and the comm port simultaneously, and ho
> to get input from remote. Any help would be appreciated.
Here's some Borland Pascal code I've written. It may be helpful to you:
program dt2;
uses
dosprocs, os2subs;
Const
ExtKeyChar : Char = #0;
Function KeyPressed : Boolean;
Var
KeyInfo : TKbdKeyInfo;
Begin
KbdPeek(KeyInfo,0);
KeyPressed:= (ExtKeyChar #0) or ((KeyInfo.fbStatus And $40) 0);
End;
Function ReadKey : Char;
Var
KeyInfo : TKbdKeyInfo;
Begin
If ExtKeyChar #0 then
Begin
ReadKey:= ExtKeyChar;
ExtKeyChar:= #0
End
else
Begin
KbdCharIn(KeyInfo,0,0);
If KeyInfo.chChar = #0 then
ExtKeyChar:= KeyInfo.chScan;
ReadKey:= KeyInfo.chChar;
End;
End;
type
mdmlinerec = record
databits : byte;
parity : byte;
stopbits : byte;
end;
mdmctlrec = record
onmask : byte;
offmask : byte;
end;
mdmdcbrec = record
wtime : word;
rtime : word;
flags1 : byte;
flags2 : byte;
flags3 : byte;
errchar : byte;
brkchar : byte;
xonchar : byte;
xoffchar : byte;
end;
siodterec = record
dte : longint;
fraction : byte;
end;
bufstatrec = record
bufused : word;
bufsize : word;
end;
dtestatrec = record
dterate : longint;
dtefract : byte;
mindte : longint;
minfract : byte;
maxdte : longint;
maxfract : byte;
end;
var
comh : word;
mdmline : mdmlinerec; mdmctl : mdmctlrec; mdmdcb : mdmdcbrec;
siodte : siodterec; bufstat : bufstatrec; dtestat : dtestatrec;
function si(s : string) : longint;
var
i : longint; c : word;
begin
si := 0;
val(s, i, c);
if c = 0 then
si := i;
end;
procedure sendport(s : string);
var
i, written : word;
begin
for i := 1 to length(s) do
doswrite(comh, s[i], 1, written);
end;
procedure funcall(s : string; w : word);
begin { shows what DLL call generates error if any }
if w > 0 then begin
writeln('Error ['+s+']; result code: ', w);
halt;
end;
end;
function carrier : boolean;
var
mdminsig : byte;
begin
funcall('Check DCD', dosdevioctl({at}mdminsig, nil, 103, 1, comh));
if (mdminsig and 128) = 128 then
carrier := true
else
carrier := false;
end;
function getdte : longint;
var
baud : word;
begin
funcall('SIO.SYS Grab DTE', dosdevioctl({at}dtestat, nil, 99, 1, comh));
{ funcall('COM.SYS Get DTE', dosdevioctl({at}baud, nil, $61, 1, comh)); }
getdte := dtestat.dterate;
end;
function rcvbufused : word;
begin
funcall('Check Rcv Buff', dosdevioctl({at}bufstat, nil, 104, 1, comh));
rcvbufused := bufstat.bufused;
end;
procedure initcomm(cport : byte; dte : longint);
var
action, comerr : word;
comstr : string[6];
portz : array[1..5] of char;
begin
{ This routine is based off of OS2COMM.C's INITCOMM function done in
1988 by Jim Gilliland }
comerr := 0;
comstr := 'COM'+chr(48+cport)+#0;
move(comstr[1], portz, 5);
funcall('Open Port', dosopen({at}portz, comh, action, 0, 0, 1, 66, 0));
{ note: 66 means "deny none" access to com port }
writeln('Initial DTE [', getdte, ']');
if dte > 57600 then begin { for speeds > 57600, use SIO function 43h }
siodte.dte := dte; { I hope you are using SIO }
siodte.fraction := 0;
funcall('Set SIO DTE', dosdevioctl(nil, {at}siodte, 67, 1, comh));
end else
funcall('Set DTE Rate', dosdevioctl(nil, {at}dte, 65, 1, comh));
mdmline.databits := 8;
mdmline.parity := 0; { N-parity }
mdmline.stopbits := 0; { 1-stop bit }
funcall('Set N81', dosdevioctl(nil, {at}mdmline, 66, 1, comh));
mdmctl.onmask := 3; { DTR/RTS on }
mdmctl.offmask := 255; { nothing off }
funcall('Set DTR/RTS', dosdevioctl({at}comerr, {at}mdmctl, 70, 1, comh));
mdmdcb.wtime := 10;
mdmdcb.rtime := 10;
mdmdcb.flags1 := 1;
mdmdcb.flags2 := 64;
mdmdcb.flags3 := 4;
mdmdcb.errchar := 0;
mdmdcb.brkchar := 0;
mdmdcb.xonchar := 17;
mdmdcb.xoffchar := 19;
funcall('Set DCB', dosdevioctl(nil, {at}mdmdcb, 83, 1, comh));
end;
procedure dumbterm;
var
i, w : word;
ch : char;
incom : array[1..512] of char;
begin
writeln;
writeln('[VERY DUMB TERMINAL/2 0.1] **** USE CTRL-Z TO EXIT THE PROGRAM ****');
sendport('ATZ'+#13); { example initialization string }
repeat
if keypressed then begin
ch := readkey;
doswrite(comh, ch, 1, w);
end else begin
if dosread(comh, incom, 512, w) = 0 then begin
for i := 1 to w do
write(incom[i]);
end;
end;
until(ch = #26);
end;
var
dte : longint;
cport : byte;
version : word;
begin
if paramcount < 2 then begin
writeln(' Syntax: DT port dte');
writeln('Example: DT 3 115200');
halt;
end;
cport := si(paramstr(1));
dte := si(paramstr(2));
dosgetversion(version);
writeln('Program written by B.J. Guillot [BGFAX author] Nov 1994');
writeln('Fido 1:106/400 Internet email: bjg90783{at}jetson.uh.edu');
writeln('Program written for German 16-bit OS/2 patch for BP 7.0');
writeln;
writeln('Port [', cport, '] DTE [', dte, ']');
initcomm(cport, dte); { initialies the port and grabs com handle }
dumbterm;
writeln('Closing port...');
writeln(dosclose(comh));
end.
--- GTMail 1.20b
* Origin: Tranquility Base - 713-893-9124 - Houston, TX (1:106/400.0)SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413 SEEN-BY: 711/430 807 808 809 934 942 949 712/353 623 713/888 800/1 @PATH: 106/400 2001 2000 449 116 170/400 280/1 396/1 3615/50 @PATH: 229/2 12/2442 711/409 54/54 711/808 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™.