Thread View: comp.sources.mac
1 messages
1 total messages
Started by Eric H. Romo
Wed, 25 May 1988 06:05
HyperTerm XCMD sources
Author: Eric H. Romo
Date: Wed, 25 May 1988 06:05
Date: Wed, 25 May 1988 06:05
1007 lines
32074 bytes
32074 bytes
[HyperTerm XCMD sources]
[Moderator's Note: This posting contains the source files for the
xcmds in the HyperTerm stack posted in comp.binaries.mac.]
---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# breakSPort.p
# bufferSPort.p
# openPort.p
# portHasChar.p
# recvPort.p
# recvString.p
# recvUpTo.p
# resetPort.p
# sendPort.p
# This archive created: Tue May 24 08:36:57 1988
# By: Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'breakSPort.p'" '(1932 characters)'
if test -f 'breakSPort.p'
then
echo shar: will not over-write existing file "'breakSPort.p'"
else
sed 's/^X//' << \SHAR_EOF > 'breakSPort.p'
X{$R-}
X
X(*
X breakSPort(port number, trueOrFalse) -- Send or clear a break on the serial port.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w resetPort.p
X link -m ENTRYPOINT -o HyperCommands -rt XCMD=1 -sn Main=breakSPort breakSPort.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S breakSPort } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xtype
X
XStr31 = String[31];
X
Xprocedure breakSPort(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X breakSPort(paramPtr);
X end;
X
Xprocedure breakSPort(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X setting: integer;
X outPort: integer;
X str: Str255;
X doBreak: boolean;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(breakSPort);
X end;
X
X begin
X if paramPtr^.paramCount <> 2 then Fail('parameter count is not 2');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X ZeroToPas(paramPtr^.params[2]^,str); { Second parameter is setting. }
X doBreak := false;
X if length(str) > 0 then
X if (str[1] = 't') or (str[1] = 'T') then doBreak := true;
X
X if portNumber = 1 then outPort := -7
X else outPort := -9;
X if doBreak then
X begin
X if SerSetBrk(outPort) <> noErr then Fail('SerSetBrk failed');
X end
X else
X begin
X if SerClrBrk(outPort) <> noErr then Fail('SerClrBrk failed');
X end;
X end;
X
Xend.
SHAR_EOF
if test 1932 -ne "`wc -c < 'breakSPort.p'`"
then
echo shar: error transmitting "'breakSPort.p'" '(should have been 1932 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'bufferSPort.p'" '(2504 characters)'
if test -f 'bufferSPort.p'
then
echo shar: will not over-write existing file "'bufferSPort.p'"
else
sed 's/^X//' << \SHAR_EOF > 'bufferSPort.p'
X{$R-}
X
X(*
X bufferSPort(port number, oldBuffer,sizeOfBuffer) -- Free the old buffer at the address specified by
X oldBuffer (if non-zero), and allocate a new buffer of sizeOfBuffer (or revert to default buffer if
X zero). Return the address of the allocated buffer or zero if sizeOfBuffer is zero.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w bufferSPort.p
X link -m ENTRYPOINT -o HyperCommands -rt XFCN=3 -sn Main=bufferSPort bufferSPort.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S bufferSPort } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xconst
X
Xreturn = chr(13);
Xlinefeed = chr(10);
Xbs = chr(8);
X
Xtype
X
XStr31 = String[31];
X
Xprocedure bufferSPort(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X bufferSPort(paramPtr);
X end;
X
Xprocedure bufferSPort(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X oldBufferPtr: Ptr;
X newBufferPtr: Ptr;
X newBufferSize: longInt;
X inPort, outPort: integer;
X str: Str255;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(bufferSPort);
X end;
X
X begin
X if paramPtr^.paramCount <> 3 then Fail('parameter count is not 3');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X ZeroToPas(paramPtr^.params[2]^,str); { Second parameter is old buffer address. }
X oldBufferPtr := Ptr(StrToNum(str));
X ZeroToPas(paramPtr^.params[3]^,str); { Third parameter is new buffer size. }
X newBufferSize := StrToNum(str);
X
X if portNumber = 1 then inPort := -6
X else inPort := -8;
X
X if newBufferSize = 0 then newBufferPtr := nil
X else newBufferPtr := NewPtr(newBufferSize);
X if SerSetBuf(inPort,newBufferPtr,newBufferSize) <> noErr then
X begin
X DisposPtr(newBufferPtr);
X Fail('SetSetBuf failed');
X end;
X if oldBufferPtr <> NIL then DisposPtr(oldBufferPtr);
X str := LongToStr(ord4(newBufferPtr));
X paramPtr^.returnValue := PasToZero(str);
X end;
Xend.
SHAR_EOF
if test 2504 -ne "`wc -c < 'bufferSPort.p'`"
then
echo shar: error transmitting "'bufferSPort.p'" '(should have been 2504 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'openPort.p'" '(2102 characters)'
if test -f 'openPort.p'
then
echo shar: will not over-write existing file "'openPort.p'"
else
sed 's/^X//' << \SHAR_EOF > 'openPort.p'
X{$R-}
X
X(*
X openSPort portNumber -- Open the serial port driver.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w openPort.p
X link -m ENTRYPOINT -o HyperCommands -rt XCMD=0 -sn Main=openSPort openPort.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S openSPort } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xtype
X
XStr31 = String[31];
X
Xprocedure openSPort(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X openSPort(paramPtr);
X end;
X
Xprocedure openSPort(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X inPort, outPort: integer;
X actualIn, actualOut: integer;
X i: integer;
X str: Str255;
X shakes: SerShk;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(openSPort);
X end;
X
X begin
X if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X
X if portNumber = 1 then
X begin
X inPort := -6; outPort := -7;
X end
X else
X begin
X inPort := -8; outPort := -9;
X end;
X if (OpenDriver('.AOut',actualOut) <> noErr) or (OpenDriver('.AIn',actualIn) <> noErr) then
X Fail('OpenDriver failed');
X if (actualOut <> outPort) or (actualIn <> inPort) then Fail('openDriver failed');
X with shakes do
X begin
X fXOn := 0; fCTS := 0; errs := 0; evts := 0; fInX := 0;
X end;
X if SerHShake(inPort,shakes) <> noErr then Fail('SerHShake failed');
X if SerHShake(outPort,shakes) <> noErr then Fail('SerHShake failed');
X end;
X
Xend.
SHAR_EOF
if test 2102 -ne "`wc -c < 'openPort.p'`"
then
echo shar: error transmitting "'openPort.p'" '(should have been 2102 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'portHasChar.p'" '(1638 characters)'
if test -f 'portHasChar.p'
then
echo shar: will not over-write existing file "'portHasChar.p'"
else
sed 's/^X//' << \SHAR_EOF > 'portHasChar.p'
X{$R-}
X
X(*
X SPortHasChar(port number) -- Return "true" if the serial port has data; "false" otherwise.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w portHasChar.p
X link -m ENTRYPOINT -o HyperCommands -rt XFCN=0 -sn Main=SPortHasChar portHasChar.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S SPortHasChar } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xtype
X
XStr31 = String[31];
X
Xprocedure SPortHasChar(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X SPortHasChar(paramPtr);
X end;
X
Xprocedure SPortHasChar(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X inPort: integer;
X str: Str255;
X l: longInt;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(SPortHasChar);
X end;
X
X begin
X if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X
X if portNumber = 1 then inPort := -6
X else inPort := -8;
X if SerGetBuf(inPort,l) <> noErr then Fail('SerGetBuf failed');
X if l = 0 then paramPtr^.returnValue := PasToZero('false')
X else paramPtr^.returnValue := PasToZero('true');
X end;
X
Xend.
SHAR_EOF
if test 1638 -ne "`wc -c < 'portHasChar.p'`"
then
echo shar: error transmitting "'portHasChar.p'" '(should have been 1638 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'recvPort.p'" '(1614 characters)'
if test -f 'recvPort.p'
then
echo shar: will not over-write existing file "'recvPort.p'"
else
sed 's/^X//' << \SHAR_EOF > 'recvPort.p'
X{$R-}
X
X(*
X recvSPort(port number) -- Return a character from the serial port.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w recvPort.p
X link -m ENTRYPOINT -o HyperCommands -rt XFCN=1 -sn Main=recvSPort recvPort.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S recvSPort } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xtype
X
XStr31 = String[31];
X
Xprocedure recvSPort(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X recvSPort(paramPtr);
X end;
X
Xprocedure recvSPort(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X inPort: integer;
X str: Str255;
X l: longInt;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(recvSPort);
X end;
X
X begin
X if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X
X if portNumber = 1 then inPort := -6
X else inPort := -8;
X l := 1;
X str[0] := chr(1);
X if FSRead(inPort,l,Ptr(ord4(@str)+1)) <> noErr then Fail('FSRead failed');
X if l <> 1 then str[0] := chr(0);
X paramPtr^.returnValue := PasToZero(str);
X end;
X
Xend.
SHAR_EOF
if test 1614 -ne "`wc -c < 'recvPort.p'`"
then
echo shar: error transmitting "'recvPort.p'" '(should have been 1614 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'recvString.p'" '(6707 characters)'
if test -f 'recvString.p'
then
echo shar: will not over-write existing file "'recvString.p'"
else
sed 's/^X//' << \SHAR_EOF > 'recvString.p'
X{$R-}
X
X(*
X recvString(port number, termination character, waitTime, echo, edit,oldString) -- Return a string from the
X serial port; return everything available, up to the termination character (if any). Pass an empty
X termination character to receive everything available. WaitTime is the amount of time to wait
X for the input, in ticks (60ths of a second). Echo is true to enable echoing. Edit is true to enable edit
X characters (i.e., backspace). oldString is what was read the last call (presumably terminated
X due to a time-out).
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w recvString.p
X link -m ENTRYPOINT -o HyperCommands -rt XFCN=0 -sn Main=recvUpTo recvString.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S recvString } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xconst
X
Xreturn = chr(13);
Xlinefeed = chr(10);
Xbs = chr(8);
X
Xtype
X
XStr31 = String[31];
X
Xprocedure recvString(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X recvString(paramPtr);
X end;
X
Xprocedure recvString(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X inPort, outPort: integer;
X str: Str255;
X l: longInt;
X waitForChars: longInt;
X lookForTerm: boolean;
X termChar: char;
X echoOn: boolean;
X editOn: boolean;
X linefeedStr: string[1];
X bsStr: string[3];
X resultHand: Handle;
X resultSize: longInt;
X theChar: char;
X p: Ptr;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(recvString);
X end;
X
X begin
X if paramPtr^.paramCount <> 6 then Fail('parameter count is not 6');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X ZeroToPas(paramPtr^.params[2]^,str); { Second parameter is termination character. }
X if length(str) = 0 then lookForTerm := false
X else
X begin
X lookForTerm := true;
X termChar := str[1];
X end;
X ZeroToPas(paramPtr^.params[3]^,str); { Third parameter is whether to wait. }
X waitForChars := StrToNum(str);
X ZeroToPas(paramPtr^.params[4]^,str); { Fourth parameter is whether to echo. }
X echoOn := false;
X if length(str) > 0 then
X if (str[1] = 't') or (str[1] = 'T') then echoOn := true;
X ZeroToPas(paramPtr^.params[5]^,str); { Fifth parameter is whether to edit. }
X editOn := false;
X if length(str) > 0 then
X if (str[1] = 't') or (str[1] = 'T') then editOn := true;
X resultHand := paramPtr^.params[6]; { Sixth parameter is the old string. }
X if resultHand = NIL then Fail('NIL resultHandle!');
X l := GetHandleSize(resultHand);
X p := resultHand^;
X resultSize := 1;
X while resultSize < l do
X begin
X if p^ = 0 then leave;
X p := Ptr(ord4(p)+1);
X resultSize := resultSize + 1;
X end;
X if resultSize < 1 then Fail('Input string size too small!');
X if HandToHand(resultHand) <> noErr then Fail('HandToHand failed!');
X resultSize := resultSize-1;
X SetHandleSize(resultHand,resultSize);
X
X if portNumber = 1 then
X begin
X inPort := -6;
X outPort := -7;
X end
X else
X begin
X inPort := -8;
X outPort := -9;
X end;
X linefeedStr[0] := chr(1); linefeedStr[1] := linefeed;
X bsStr := ' '; bsStr[1] := bs; bsStr[3] := bs;
X waitForChars := waitForChars + TickCount;
X while TickCount <= waitForChars do
X begin
X if SerGetBuf(inPort,l) <> noErr then
X begin
X DisposHandle(resultHand);
X Fail('SerGetBuf failed');
X end;
X if l = 0 then cycle;
X l := 1;
X resultSize := resultSize+1;
X SetHandleSize(resultHand,resultSize);
X if MemError <> noErr then
X begin
X DisposHandle(resultHand);
X Fail('SetHandleSize failed!');
X end;
X HLock(resultHand);
X if FSRead(inPort,l,Ptr(ord4(resultHand^)+resultSize-1)) <> noErr then
X begin
X DisposHandle(resultHand);
X Fail('FSRead failed');
X end;
X HUnlock(resultHand);
X p := Ptr(ord4(resultHand^)+resultSize-1);
X p^ := BAND(p^,$7F);
X theChar := chr(p^);
X if echoOn then
X begin
X l := 1;
X if FSWrite(outPort,l,Ptr(ord4(resultHand^)+resultSize-1)) <> noErr then
X Fail('FSWriter failed');
X if theChar = return then
X begin
X l := length(linefeedStr);
X if FSWrite(outPort,l,Ptr(ord4(@linefeedStr)+1)) <> noErr then Fail('FSWrite failed');
X end;
X if editOn and (theChar = bs) then
X begin
X l := length(bsStr);
X if FSWrite(outPort,l,Ptr(ord4(@bsStr)+1)) <> noErr then Fail('FSWrite failed');
X end;
X end;
X if editOn then
X begin
X if theChar = bs then
X begin
X resultSize := resultSize-2;
X if resultSize < 0 then resultSize := 0;
X SetHandleSize(resultHand,resultSize);
X end;
X end;
X if lookForTerm then
X if theChar = termChar then leave;
X if resultSize > 30000 then leave;
X end;
X SetHandleSize(resultHand,resultSize+1);
X p := ptr(ord4(resultHand^)+resultSize);
X p^ := 0;
X paramPtr^.returnValue := resultHand;
X end;
X
Xend.
SHAR_EOF
if test 6707 -ne "`wc -c < 'recvString.p'`"
then
echo shar: error transmitting "'recvString.p'" '(should have been 6707 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'recvUpTo.p'" '(4983 characters)'
if test -f 'recvUpTo.p'
then
echo shar: will not over-write existing file "'recvUpTo.p'"
else
sed 's/^X//' << \SHAR_EOF > 'recvUpTo.p'
X{$R-}
X
X(*
X recvUpTo(port number, termination character, waitTime, echo, edit) -- Return a string from the
X serial port; return everything available, up to the termination character (if any). Pass an empty
X termination character to receive everything available. WaitTime is the amount of time to wait
X for the input, in ticks (60ths of a second). Echo is true to enable echoing. Edit is
X true to enable edit characters (i.e., backspace).
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w recvUpTo.p
X link -m ENTRYPOINT -o HyperCommands -rt XFCN=0 -sn Main=recvUpTo recvUpTo.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S recvUpTo } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xconst
X
Xreturn = chr(13);
Xlinefeed = chr(10);
Xbs = chr(8);
X
Xtype
X
XStr31 = String[31];
X
Xprocedure recvUpTo(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X recvUpTo(paramPtr);
X end;
X
Xprocedure recvUpTo(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X inPort, outPort: integer;
X str: Str255;
X l: longInt;
X waitForChars: longInt;
X lookForTerm: boolean;
X termChar: char;
X echoOn: boolean;
X editOn: boolean;
X linefeedStr: string[1];
X bsStr: string[3];
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(recvUpTo);
X end;
X
X begin
X if paramPtr^.paramCount <> 5 then Fail('parameter count is not 5');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X ZeroToPas(paramPtr^.params[2]^,str); { Second parameter is termination character. }
X if length(str) = 0 then lookForTerm := false
X else
X begin
X lookForTerm := true;
X termChar := str[1];
X end;
X ZeroToPas(paramPtr^.params[3]^,str); { Third parameter is whether to wait. }
X waitForChars := StrToNum(str);
X ZeroToPas(paramPtr^.params[4]^,str); { Fourth parameter is whether to echo. }
X echoOn := false;
X if length(str) > 0 then
X if (str[1] = 't') or (str[1] = 'T') then echoOn := true;
X ZeroToPas(paramPtr^.params[5]^,str); { Fifth parameter is whether to edit. }
X editOn := false;
X if length(str) > 0 then
X if (str[1] = 't') or (str[1] = 'T') then editOn := true;
X
X if portNumber = 1 then
X begin
X inPort := -6;
X outPort := -7;
X end
X else
X begin
X inPort := -8;
X outPort := -9;
X end;
X linefeedStr[0] := chr(1); linefeedStr[1] := linefeed;
X bsStr := ' '; bsStr[1] := bs; bsStr[3] := bs;
X str := '';
X waitForChars := waitForChars + TickCount;
X while TickCount <= waitForChars do
X begin
X if SerGetBuf(inPort,l) <> noErr then Fail('SerGetBuf failed');
X if l = 0 then cycle;
X str[0] := chr(integer(str[0])+1);
X l := 1;
X if FSRead(inPort,l,Ptr(ord4(@str)+ord(str[0]))) <> noErr then Fail('FSRead failed');
X if echoOn then
X begin
X l := 1;
X if FSWrite(outPort,l,Ptr(ord4(@str)+ord(str[0]))) <> noErr then Fail('FSWriter failed');
X if str[length(str)] = return then
X begin
X l := length(linefeedStr);
X if FSWrite(outPort,l,Ptr(ord4(@linefeedStr)+1)) <> noErr then Fail('FSWrite failed');
X end;
X if editOn and (str[length(str)] = bs) then
X begin
X l := length(bsStr);
X if FSWrite(outPort,l,Ptr(ord4(@bsStr)+1)) <> noErr then Fail('FSWrite failed');
X end;
X end;
X if editOn then
X begin
X if str[length(str)] = bs then
X begin
X str[0] := chr(length(str)-1);
X if length(str) > 0 then str[0] := chr(length(str)-1);
X end;
X end;
X if lookForTerm then
X if str[length(str)] = termChar then leave;
X if length(str) = 255 then leave;
X end;
X paramPtr^.returnValue := PasToZero(str);
X end;
X
Xend.
SHAR_EOF
if test 4983 -ne "`wc -c < 'recvUpTo.p'`"
then
echo shar: error transmitting "'recvUpTo.p'" '(should have been 4983 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'resetPort.p'" '(1800 characters)'
if test -f 'resetPort.p'
then
echo shar: will not over-write existing file "'resetPort.p'"
else
sed 's/^X//' << \SHAR_EOF > 'resetPort.p'
X{$R-}
X
X(*
X resetSPort(port number, setting) -- Reset the serial port driver.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w resetPort.p
X link -m ENTRYPOINT -o HyperCommands -rt XCMD=1 -sn Main=resetSPort resetPort.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S resetSPort } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xtype
X
XStr31 = String[31];
X
Xprocedure resetSPort(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X resetSPort(paramPtr);
X end;
X
Xprocedure resetSPort(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X setting: integer;
X inPort, outPort: integer;
X str: Str255;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(resetSPort);
X end;
X
X begin
X if paramPtr^.paramCount <> 2 then Fail('parameter count is not 2');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X ZeroToPas(paramPtr^.params[2]^,str); { Second parameter is setting. }
X setting := StrToNum(str);
X
X if portNumber = 1 then
X begin
X inPort := -6; outPort := -7;
X end
X else
X begin
X inPort := -8; outPort := -9;
X end;
X if (SerReset(inPort,setting) <> noErr) or (SerReset(outPort,setting) <> noErr) then
X Fail('SerReset failed');
X end;
X
Xend.
SHAR_EOF
if test 1800 -ne "`wc -c < 'resetPort.p'`"
then
echo shar: error transmitting "'resetPort.p'" '(should have been 1800 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'sendPort.p'" '(2502 characters)'
if test -f 'sendPort.p'
then
echo shar: will not over-write existing file "'sendPort.p'"
else
sed 's/^X//' << \SHAR_EOF > 'sendPort.p'
X{$R-}
X
X(*
X sendSPort portNumber, addLFs, string -- Send a string to the serial port driver.
X
X To compile and link this file using Macintosh Programmer's Workshop,
X
X pascal -w sendPort.p
X link -m ENTRYPOINT -o HyperCommands -rt XCMD=2 -sn Main=sendSPort sendPort.p.o "{MPW}"Libraries:interface.o
X
X*)
X
X{$S sendSPort } { Segment name must be the same as the command name. }
X
Xunit DummyUnit;
X
Xinterface
X
Xuses MemTypes, QuickDraw, OSIntf, HyperXCmd;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
Ximplementation
X
Xconst
X
Xreturn = 13;
Xlinefeed = 10;
X
Xtype
X
XStr31 = String[31];
X
Xprocedure sendSPort(paramPtr: XCmdPtr); forward;
X
Xprocedure EntryPoint(paramPtr: XCmdPtr);
X
X begin
X sendSPort(paramPtr);
X end;
X
Xprocedure sendSPort(paramPtr: XCmdPtr);
X
X var portNumber: integer;
X outPort: integer;
X sendLFs: boolean;
X str: Str255;
X p: Ptr;
X l: longInt;
X linefeedByte: SignedByte;
X
X {$I XCmdGlue.inc}
X
X procedure Fail(errMsg: Str255); { set theResult and quit }
X begin
X paramPtr^.returnValue := PasToZero(errMsg);
X exit(sendSPort);
X end;
X
X begin
X if paramPtr^.paramCount <> 3 then Fail('parameter count is not 3');
X
X ZeroToPas(paramPtr^.params[1]^,str); { First parameter is port number. }
X portNumber := StrToNum(str);
X if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
X ZeroToPas(paramPtr^.params[2]^,str); { Third parameter is whether to wait. }
X sendLFs := false;
X if length(str) > 0 then
X if (str[1] = 't') or (str[1] = 'T') then sendLFs := true;
X HLock(paramPtr^.params[3]);
X p := paramPtr^.params[3]^; { Second parameter is string to send. }
X
X if portNumber = 1 then outPort := -7
X else outPort := -9;
X linefeedByte := linefeed;
X while p^ <> 0 do
X begin
X l := 1;
X if FSWrite(outPort,l,p) <> noErr then Fail('FSWrite failed');
X if l <> 1 then Fail('not all characters sent');
X if sendLFs and (p^ = return) then
X begin
X l := 1;
X if FSWrite(outPort,l,@linefeedByte) <> noErr then Fail('FSWrite failed');
X if l <> 1 then Fail('not all characters sent');
X end;
X p := ptr(ord4(p)+1);
X end;
X HUnlock(paramPtr^.params[3]);
X end;
X
Xend.
SHAR_EOF
if test 2502 -ne "`wc -c < 'sendPort.p'`"
then
echo shar: error transmitting "'sendPort.p'" '(should have been 2502 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0
---
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads