Option Explicit 'default (OFF) - implicit variable definition not used '======================================================================================== 'Module Title: ComSupport_R4.Bas '======================================================================================== 'Author: Unknown - Communications routines modified by ZbasicAndy for "Super Comm Z" '======================================================================================== 'Date: 4-3-2006 '======================================================================================== 'Operating System: XP '======================================================================================== 'ZBasic IDE Version: 1.0.4 / ZBasic Compiler version 1-1-18 / ZX-40 Firmware 1.1.6 '======================================================================================== 'Target: ZX-40 '======================================================================================== 'Hardware: "Super Comm Z R1" ([4 software serial & 1 Hardware] RS232 ports with ZX-40 PCB) 'Main/Support Modules Needed: Super_Comm_Z_R1.bas - "Sub Main" basic module ' '======================================================================================== 'Comport(s) used: Comports 3,4,5 & 6 on ZX-40 for "Super Comm Z" '======================================================================================== 'Bugs fixes and updates: ' Version: 1.0.2b -> modified code that parameterizes the port number per Mikep & DKinzer ' ' ' ' ' ' ' ' '======================================================================================== ' Module Description: ' ' This module subroutines are used to transfer data to and from all serial ports. ' Note that the queue size must be 9 bytes larger than the largest data element to ' provide space for the queue pointers. ' ' It is necessary to call DefineCom_X prior to communicating with each serial device. ' Use OpenSerialPort_X to initially open a ComX port, and then use ReOpenSerialPort_X ' each time that port needs to be reopened. ' ' There are many useful "generic" communication routines. The main I/O and all serial ports ' setup is done in the main subroutine e.g. Super_Comm_Z_R1.bas. All other modules refer ' to this module for communications. ' ' For Serial port diagnostics there are 4 turnaround subroutines to completely check all the ' comports on the "Super Comm Z" provided that you install a RS232 turnaround connnector ' on each serial port and jumper pins 2-3 on it. Also, there is a HyperTerminal Turnaround test. ' ' Warning ... Max baudrate is 9600 for all comports! ' '========================================================================================== ' In your "Main Sub" Please Do The Following With The * below (In order): '========================================================================================== '*Call ComChannels(4, 9600) ' 9600 baud max for 4 channels! <- Make sure the count is right! '--------------------------------------------------------- 'Define "Super Comm Z" ZX-40 commuications I/O '--------------------------------------------- '*Call DefineCom(3, 39, 40, &H37) ' com 3 ,rec pin 39 tran pin 40 - 7,E,1 '*Call DefineCom(4, 37, 38, &H08) ' com 4 ,rec pin 37 tran pin 38 - 8,N,1 '*Call DefineCom(5, 17, 19, &H08) ' com 5 ,rec pin 17 tran pin 19 - 8,N,1 '*Call DefineCom(6, 16, 18, &H08) ' com 6 ,rec pin 16 tran pin 18 - 8,N,1 '--------------------------------------------------------------------------------------------- 'Software Serial ports "opened" '------------------------------ '*Call OpenSerialPort(3,9600) '*Call OpenSerialPort(4,9600) '*Call OpenSerialPort(5,9600) '*Call OpenSerialPort(6,4800) '========================================================================================= ' Please Use The Following Constants (below) or Port Value(s)(byte numbers 3 thru 6) ' to reference the port parameter) e.g. Port3 or 3, Port4 or 4 .... '========================================================================================= ' Please Use ONLY The Following In Reference To Each Queue Buffer: ' OR use the following functions below. ' ' Input Buffer Ref: "CByteArray(Inbuf(1, port).DataAddress)" value port = 3,4,5,6 or Port3,Port4,... ' Output Buffer Ref: "CByteArray(Outbuf(1, port).DataAddress)" ' ' Examples: CALL ClearQueue(CByteArray(Outbuf(1, port4 ).DataAddress)) ' clear port 4 out buffer ' CALL ClearQueue(CByteArray(Inbuf(1, port4 ).DataAddress)) ' clear port 4 in buffer ' CALL GetQueue(CByteArray(Inbuf(1, port4 ).DataAddress),Rx,Num_Char,TimeOutS,Success) ' '========================================================================================= 'Program Definitions: '========================================================================================= '========================================================================================= 'Constants '[Public | Private] Const As = (default private) '========================================================================================= private const InBufSize as INTEGER = 50 ' 41-byte buffer. private const OutBufSize as INTEGER = 50 ' 41-byte buffer. private const minLogicalPort as Byte = 3 private const maxLogicalPort as Byte = 6 '----------------------------- ' Port Constants for all ports '----------------------------- ' Do not modify! Private Const Port3 as byte = 3 'keep private Private Const Port4 as byte = 4 'keep private Private Const Port5 as byte = 5 'keep private Private Const Port6 as byte = 6 'keep private '----------------------------- ' '========================================================================================= 'Variables '{Public | Private | Dim} As (default private) '========================================================================================= public InBuf(1 To InBufSize, minLogicalPort to maxLogicalPort) as BYTE public OutBuf(1 To OutBufSize, minLogicalPort to maxLogicalPort) as BYTE '========================================================================================= 'Functions - Generic for all ZX-xx's '========================================================================================= Function SerialDataAvailable(ByVal port as Byte) as Boolean SerialDataAvailable = StatusQueue(CByteArray(Inbuf(1, port).DataAddress)) End Function '========================================================================================= 'Subroutines - Generic for all ZX-xx's '========================================================================================= public Sub ClearInputBuffer(ByVal port as Byte) CALL ClearQueue(CByteArray(Inbuf(1, port).DataAddress)) End Sub '========================================================================================= public Sub ClearOutputBuffer(ByVal port as Byte) CALL ClearQueue(CByteArray(Outbuf(1, port).DataAddress)) End Sub '========================================================================================= public Sub OpenSerialPort(ByVal port as Byte, ByVal BaudRate as Long) If ((port >= minLogicalPort) And (port <= maxLogicalPort)) Then ' Opens serial port n at the specified baud rate. Call OpenQueue(CByteArray(Inbuf(1, port).DataAddress), InBufSize) Call OpenQueue(CByteArray(Outbuf(1, port).DataAddress), OutBufSize) Call OpenCom(port, BaudRate, CByteArray(Inbuf(1, port).DataAddress), _ CByteArray(Outbuf(1, port).DataAddress)) End If End Sub '========================================================================================= public sub ReOpenSerialPort( ByVal port as Byte, _ ByVal BaudRate as LONG) ' Reopens serial port n at the specified baud rate. CALL OpenCom(port, BaudRate,CByteArray(Inbuf(1, port).DataAddress),CByteArray(Outbuf(1, port).DataAddress)) END sub '=============================================================================== public sub PutByte(ByVal port as Byte, ByVal Value as BYTE) ' Sends one byte of binary data to serial port n. The byte is sent ' directly without translating it to a STRING type. CALL PutQueueByte(CByteArray(Outbuf(1, port).DataAddress), Value) END sub '=============================================================================== public sub GetByte( ByVal port as Byte, _ ByRef Value as BYTE, _ ByRef Success as BOOLEAN) ' Inputs a byte from serial port n, if available. Returns regardless. The ' Success flag is set depending on whether a byte is available. ' ' The byte is in direct binary format -- it is not in string format. ' Find out if anything is in the queue. Success = StatusQueue(CByteArray(Inbuf(1, port).DataAddress)) ' If data is in the queue, extract it. IF (Success) THEN CALL GetQueue(CByteArray(Inbuf(1, port).DataAddress), Value,1) ELSE Value = 0 END IF end sub '=============================================================================== public sub NewLine(ByVal port as Byte) ' Outputs a to serial port n. CALL PutByte(port,&h0D) CALL delay(0.50) CALL PutByte(port,&h0A) end sub '=============================================================================== public sub PutLine(ByVal port as Byte,ByRef Tx as STRING) ' Outputs a STRING type, followed by . Output is to serial port n. CALL PutStr(port,Tx) CALL NewLine(port) end sub '=============================================================================== public sub PutStr(ByVal port as Byte, _ ByRef Tx as STRING) ' Outputs a STRING type to serial port n. dim Length as INTEGER dim Ch as STRING * 1 dim bCh as BYTE dim I as INTEGER Length = Len(Tx) For I = 1 To Length Ch = Mid(Tx, I, 1) bCh = Asc(Ch) CALL PutByte(port,bCh) NEXT end sub '=============================================================================== public sub PutB(ByVal port as Byte, _ ByVal Value as BYTE) ' Outputs a BYTE type to serial port n. dim L as LONG L = CLng(Value) CALL PutL(port,L) END sub '=============================================================================== public sub PutI(ByVal port as Byte, _ ByVal Value as INTEGER) ' Outputs an INTEGER type to serial port n. dim L as LONG L = CLng(Value) CALL PutL(port,L) END sub '=============================================================================== public sub PutUI(ByVal port as Byte, _ ByVal Value as UNSIGNEDINTEGER) ' Outputs an UNSIGNEDINTEGER type to serial port n. dim L as LONG dim V as NEW UNSIGNEDINTEGER V = Value ' Clear L. L = 0 ' Copy Value into the lower two bytes of L. CALL BlockMove(2, MemAddress(V), MemAddress(L)) CALL PutL(port,L) END sub '=============================================================================== public sub PutUL(ByVal port as Byte, _ ByVal Value as UNSIGNEDLONG) ' Outputs an UNSIGNEDLONG type to serial port n. dim UL as NEW UNSIGNEDLONG dim L as LONG dim Digit as NEW UNSIGNEDLONG dim I as INTEGER dim Temp as NEW UNSIGNEDLONG ' IF the top bit is clear, the number is ready to go. IF ((Value AND &H80000000) = 0) THEN CALL PutL(port,CLng(Value)) EXIT sub END IF ' Divide by 10 is done by a right shift followed by a divide by 5. ' First clear top bit so we can do a signed divide. UL = Value UL = UL AND &H7FFFFFFF ' Shift to the right 1 bit. L = CLng(UL) L = L \ 2 ' Put the top bit back, except shifted to the right 1 bit. UL = CuLng(L) UL = UL OR &H40000000 ' The number now fits in a signed long. L = CLng(UL) ' Divide by 5. L = L \ 5 CALL PutL(port,L) ' Multiply by 10. Since multiply doesn't work yet for UNSIGNEDLONG, we ' have to do the equivalent addition. Temp = CuLng(L) UL = 0 For I = 1 To 10 UL = UL + Temp NEXT ' Find the rightmost digit. Digit = Value - UL CALL PutL(port,CLng(Digit)) END sub '=============================================================================== public sub PutL(ByVal port as Byte, _ ByVal Operand as LONG) ' Outputs a LONG type to serial port n. const NegativeLimit as LONG = -2147483648 const Base as LONG = 10 ' Reserve space for "2147483648" dim Digit(1 To 10) as BYTE dim Tmp as LONG dim NDigits as INTEGER dim I as INTEGER ' Negative limit must be handled as a special case. IF (Operand = NegativeLimit) THEN Digit(10) = 2 + 48 Digit(9) = 1 + 48 Digit(8) = 4 + 48 Digit(7) = 7 + 48 Digit(6) = 4 + 48 Digit(5) = 8 + 48 Digit(4) = 3 + 48 Digit(3) = 6 + 48 Digit(2) = 4 + 48 Digit(1) = 8 + 48 NDigits = 10 ELSE NDigits = 0 Tmp = Abs(Operand) DO NDigits = NDigits + 1 Digit(NDigits) = CByte(Tmp mod Base) + 48 Tmp = Tmp \ Base IF Tmp = 0 THEN EXIT DO END IF LOOP END IF IF (Operand < 0) THEN CALL PutByte(port,45) ' "-" END IF ' Digits are stored in reverse order of display. For I = NDigits To 1 Step -1 CALL PutByte(port,Digit(I)) NEXT END sub '=============================================================================== public sub PutSci(ByVal port as Byte, _ ByVal Value as SINGLE) ' Outputs floating point number in scientific notation format. The output ' is to serial port n. dim Mantissa as SINGLE dim Exponent as INTEGER dim LMant as LONG dim D as INTEGER CALL SplitFloat(Value, Mantissa, Exponent) ' Sign. IF (Mantissa < 0!) THEN CALL PutByte(port,45) ' "-" END IF ' Convert mantissa to a 7-digit INTEGER. LMant = FixL((Abs(Mantissa) * 1000000!) + 0.5) ' Correct for roundoff error. Mantissa can't be > 9.999999 IF (LMant > 9999999) THEN LMant = 9999999 END IF ' First digit of mantissa. D = CInt(LMant \ 1000000) CALL PutByte(port,CByte(D + 48)) ' Decimal point. CALL PutByte(port,46) ' "." ' Remaining digits of mantissa. LMant = LMant mod 1000000 CALL PutL(port,LMant) ' Exponent. CALL PutByte(port,69) ' "E" IF (Exponent < 0) THEN CALL PutByte(port,45) ' "-" ELSE CALL PutByte(port,43) ' "+" END IF CALL PutI(port,Abs(Exponent)) END sub '=============================================================================== public sub PutS(ByVal port as Byte, _ ByVal Value as SINGLE) ' Outputs a floating point number to serial port n. If the number can be ' displayed without using scientific notation, it is. Otherwise scientific ' notation is used. dim X as SINGLE dim DecimalPlace as INTEGER dim Mantissa as SINGLE dim Exponent as INTEGER dim DigitPosition as INTEGER dim Factor as LONG dim D as INTEGER dim LMant as LONG dim DecimalHasDisplayed as BOOLEAN ' Special case for zero. IF (Value = 0!) THEN CALL PutByte(port,48) ' "0" CALL PutByte(port,46) ' "." CALL PutByte(port,48) ' "0" EXIT sub END IF X = Abs(Value) ' Use scientific notation for values too big or too small. IF (X < 0.1) OR (X > 999999.9) THEN CALL PutSci(port,Value) EXIT sub END IF ' What follows is non-exponent displays for 0.1000000 < Value < 999999.9 ' Sign. IF (Value < 0!) THEN CALL PutByte(port,45) ' "-" END IF IF (X < 1!) THEN CALL PutByte(port,48) ' "0" CALL PutByte(port,46) ' "." DecimalPlace = 0 ' Convert number to a 7-digit INTEGER. LMant = FixL((X * 10000000#) + 0.5) ELSE CALL SplitFloat(X, Mantissa, Exponent) DecimalPlace = Exponent + 2 ' Convert mantissa to a 7-digit INTEGER. LMant = FixL((Abs(Mantissa) * 1000000!) + 0.5) ' Correct for roundoff error. Mantissa can't be > 9.999999 IF (LMant > 9999999) THEN LMant = 9999999 END IF END IF DecimalHasDisplayed = False Factor = 1000000 For DigitPosition = 1 To 7 IF (DigitPosition = DecimalPlace) THEN CALL PutByte(port,46) ' "." DecimalHasDisplayed = True END IF D = CInt(LMant \ Factor) CALL PutByte(port,CByte(D + 48)) LMant = LMant mod Factor ' Stop trailing zeros, except for one immediately following the ' decimal place. IF (LMant = 0) THEN IF (DecimalHasDisplayed) THEN EXIT sub END IF END IF Factor = Factor \ 10 NEXT END sub '=============================================================================== private sub SplitFloat( _ ByVal Value as SINGLE, _ ByRef Mantissa as SINGLE, _ ByRef Exponent as INTEGER) ' Splits a floating point number into mantissa and exponent. The mantissa ' range is such that 1.0 <= Abs(Mantissa) < 10.0 for nonzero numbers, and ' zero otherwise. dim X as SINGLE dim Factor as SINGLE ' Zero is a special case. IF (Value = 0!) THEN Mantissa = 0! Exponent = 0 EXIT sub END IF X = Abs(Value) Exponent = 0 Factor = 1! ' Multiply or divide by ten to transform number to value between 1 and 10. DO IF (X >= 10!) THEN X = X / 10! Factor = Factor * 10! Exponent = Exponent + 1 ELSEIF (X < 1!) THEN X = X * 10! Factor = Factor * 10! Exponent = Exponent - 1 ELSE ' IF we reach this point, then 1.0 <= mantissa < 10.0. EXIT DO END IF LOOP ' Determine mantissa. IF (Exponent = 0) THEN Mantissa = Value ELSEIF (Exponent > 0) THEN Mantissa = Value / Factor ELSE Mantissa = Value * Factor END IF END sub '=============================================================================== ' Application Specific Subroutines - "Super Comm Z" ZX-40 (Diagnostics) '=============================================================================== 'Serial Comport Communication Turnaround Tests for comports 3-6. 'Includes baud rate cycling. 'This routine sends out one byte then waits for the byte to return. 'The bytes change every scan and after reaching 0 the buad rate changes. Public Sub Comport_TurnaroundTest(ByVal port as Byte, Byref OK as boolean) 'use for comports 3-6 'Jumper pins 2-3 (Tx & Rx) on J? RS232 connector for serial portx testing! 'add baud rate cycling to routines - needs testing Dim Success as Boolean static Tx3 as byte static Rx3 as byte static Tx4 as byte static Rx4 as byte static Tx5 as byte static Rx5 as byte static Tx6 as byte static Rx6 as byte static Baud_rate_selector3 as byte static Baud_rate_selector4 as byte static Baud_rate_selector5 as byte static Baud_rate_selector6 as byte Select Case port '-------------------------------------------------------- Case 3 '-------------------------------------------------------- Tx3 = Tx3 + 1 'inc from 0-255 Call PutByte(port,Tx3) Call delay(0.01) '10 ms works 'Debug.Print "Tx3 value is ";CStr(Tx3) CALL GetByte(port,Rx3,Success) 'CALL delay(0.50) 'Debug.Print "Rx3 value is ";CStr(Rx3) 'CALL delay(0.50) if (Rx3 = Tx3) then 'Debug.Print "Com3 Turnaround Test is OK! " 'Call POR_LEDS() OK = true else 'Debug.Print "Com3 Turnaround Test is NOT OK! " OK = false end if Rx3 = 0 'clear Rx3 variable If Tx3 = 0 Then Baud_rate_selector3 = Baud_rate_selector3 + 1 'debug.print "Baud Rate Selector = "; Cstr(Baud_rate_selector) End If Select case Baud_rate_selector3 case 0 '300 Call ReOpenSerialPort(3,300) 'debug.print "300 baud" case 1 '600 Call ReOpenSerialPort(3,600) 'debug.print "600 baud" case 2 '1200 Call ReOpenSerialPort(3,1200) 'debug.print "1200 baud" case 3 '4800 Call ReOpenSerialPort(3,4800) 'debug.print "4800 baud" case 4 '9600 - max - due to 2 or more software uarts Call ReOpenSerialPort(3,9600) 'debug.print "9600 baud" Case Else Call ReOpenSerialPort(3,9600) 'debug.print "300 baud - Default" End Select '------------------------------------------------------- Case 4 '------------------------------------------------------- Tx4 = Tx4 + 1 'inc from 0-255 Call PutByte(port,Tx4) Call delay(0.01) '10 ms works 'Debug.Print "Tx4 value is ";CStr(Tx4) CALL GetByte(port,Rx4,Success) 'CALL delay(0.50) 'Debug.Print "Rx4 value is ";CStr(Rx4) 'CALL delay(0.50) if (Rx4 = Tx4) then 'Debug.Print "Com4 Turnaround Test is OK! " 'Call POR_LEDS() OK = true else 'Debug.Print "Com4 Turnaround Test is NOT OK! " OK = false end if Rx4 = 0 'clear Rx4 variable If Tx4 = 0 Then Baud_rate_selector4 = Baud_rate_selector4 + 1 'debug.print "Baud Rate Selector = "; Cstr(Baud_rate_selector) End If Select case Baud_rate_selector4 case 0 '300 Call ReOpenSerialPort(4,300) 'debug.print "300 baud" case 1 '600 Call ReOpenSerialPort(4,600) 'debug.print "600 baud" case 2 '1200 Call ReOpenSerialPort(4,1200) 'debug.print "1200 baud" case 3 '4800 Call ReOpenSerialPort(4,4800) 'debug.print "4800 baud" case 4 '9600 - max - due to 2 or more software uarts Call ReOpenSerialPort(4,9600) 'debug.print "9600 baud" Case Else Call ReOpenSerialPort(4,9600) 'debug.print "300 baud - Default" End Select '--------------------------------------------------------- Case 5 '--------------------------------------------------------- Tx5 = Tx5 + 1 'inc from 0-255 Call PutByte(port,Tx5) Call delay(0.01) '10 ms works 'Debug.Print "Tx5 value is ";CStr(Tx5) CALL GetByte(port,Rx5,Success) 'CALL delay(0.50) 'Debug.Print "Rx5 value is ";CStr(Rx5) 'CALL delay(0.50) if (Rx5 = Tx5) then 'Debug.Print "Com5 Turnaround Test is OK! " 'Call POR_LEDS() OK = true else 'Debug.Print "Com5 Turnaround Test is NOT OK! " OK = false end if Rx5 = 0 'clear Rx5 variable If Tx5 = 0 Then Baud_rate_selector5 = Baud_rate_selector5 + 1 'debug.print "Baud Rate Selector = "; Cstr(Baud_rate_selector) End If Select case Baud_rate_selector5 case 0 '300 Call ReOpenSerialPort(5,300) 'debug.print "300 baud" case 1 '600 Call ReOpenSerialPort(5,600) 'debug.print "600 baud" case 2 '1200 Call ReOpenSerialPort(5,1200) 'debug.print "1200 baud" case 3 '4800 Call ReOpenSerialPort(5,4800) 'debug.print "4800 baud" case 4 '9600 - max - due to 2 or more software uarts Call ReOpenSerialPort(5,9600) 'debug.print "9600 baud" Case Else Call ReOpenSerialPort(5,9600) 'debug.print "300 baud - Default" End Select '--------------------------------------------------------- Case 6 '--------------------------------------------------------- Tx6 = Tx6 + 1 'inc from 0-255 Call PutByte(port,Tx6) Call delay(0.01) '10 ms works 'Debug.Print "Tx6 value is ";CStr(Tx6) CALL GetByte(port,Rx6,Success) 'CALL delay(0.50) 'Debug.Print "Rx6 value is ";CStr(Rx6) 'CALL delay(0.50) if (Rx6 = Tx6) then 'Debug.Print "Com6 Turnaround Test is OK! " 'Call POR_LEDS() OK = true else 'Debug.Print "Com6 Turnaround Test is NOT OK! " OK = false end if Rx6 = 0 'clear Rx6 variable If Tx6 = 0 Then Baud_rate_selector6 = Baud_rate_selector6 + 1 'debug.print "Baud Rate Selector = "; Cstr(Baud_rate_selector) End If Select case Baud_rate_selector6 case 0 '300 Call ReOpenSerialPort(6,300) 'debug.print "300 baud" case 1 '600 Call ReOpenSerialPort(6,600) 'debug.print "600 baud" case 2 '1200 Call ReOpenSerialPort(6,1200) 'debug.print "1200 baud" case 3 '4800 Call ReOpenSerialPort(6,4800) 'debug.print "4800 baud" case 4 '9600 - max - due to 2 or more software uarts Call ReOpenSerialPort(6,9600) 'debug.print "9600 baud" Case Else Call ReOpenSerialPort(6,9600) 'debug.print "300 baud - Default" End Select ' --------------------------------------------------------- ' --------------------------------------------------------- End Select End Sub '====================================================================================== 'Application Specific Communications Subroutines e.g. "Super Comm Z" Target ZX-40 Only! '====================================================================================== 'Cycle all on board LEDs on power up. For reset, powerup and LED test indication. ' Public Sub POR_LEDS() 'Cycle all "Super Comm Z" Leds on power-up or reset Const LED_Dly as single = 0.05 ' 50 ms Call PutPin(1, zxOutputHigh) 'Turn on GRN1 Rx CALL delay(LED_Dly) Call PutPin(1, zxOutputLow) 'Turn off GRN1 Rx Call PutPin(24, zxOutputHigh) 'Turn on RED1 Tx CALL delay(LED_Dly) Call PutPin(24, zxOutputLow) 'Turn off RED1 Tx Call PutPin(2, zxOutputHigh) 'Turn on GRN2 Rx CALL delay(LED_Dly) Call PutPin(2, zxOutputLow) 'Turn off GRN2 Rx Call PutPin(25, zxOutputHigh) 'Turn on RED2 Tx CALL delay(LED_Dly) Call PutPin(25, zxOutputLow) 'Turn off RED2 Tx Call PutPin(4, zxOutputHigh) 'Turn on GRN3 Rx CALL delay(LED_Dly) Call PutPin(4, zxOutputLow) 'Turn off GRN3 Rx Call PutPin(26, zxOutputHigh) 'Turn on RED3 Tx CALL delay(LED_Dly) Call PutPin(26, zxOutputLow) 'Turn off RED3 Tx Call PutPin(28, zxOutputHigh) 'Turn on GRN4 Rx CALL delay(LED_Dly) Call PutPin(28, zxOutputLow) 'Turn off GRN4 Rx Call PutPin(27, zxOutputHigh) 'Turn on RED4 Tx CALL delay(LED_Dly) Call PutPin(27, zxOutputLow) 'Turn off RED4 Tx Call PutPin(29, zxOutputHigh) 'Turn on AMB1 Zrun CALL delay(LED_Dly) Call PutPin(29, zxOutputLow) 'Turn off AMB1 Zrun End Sub '================================================================================ Public Sub Comm_Status_LEDs() 'displays the transmit and receive "status queue" on the on board LEDs. Dim status as boolean status = StatusQueue(CByteArray(Inbuf(1, Port3).DataAddress)) if (status)then Call PutPin(1, zxOutputHigh) 'Turn on GRN1 Rx ELSE Call PutPin(1, zxOutputLow) 'Turn off GRN1 Rx End if status = StatusQueue(CByteArray(Outbuf(1, port3).DataAddress)) if (status) then Call PutPin(24, zxOutputHigh) 'Turn on RED1 Tx ELSE Call PutPin(24, zxOutputLow) 'Turn off RED1 Tx End if '---------------------------------------------- status = StatusQueue(CByteArray(Inbuf(1, Port4).DataAddress)) if (status) then Call PutPin(2, zxOutputHigh) 'Turn on GRN2 Rx ELSE Call PutPin(2, zxOutputLow) 'Turn off GRN2 Rx End if status = StatusQueue(CByteArray(Outbuf(1, port4).DataAddress)) if (status) then Call PutPin(25, zxOutputHigh) 'Turn on RED2 Tx ELSE Call PutPin(25, zxOutputLow) 'Turn off RED2 Tx End if '---------------------------------------------- status = StatusQueue(CByteArray(Inbuf(1, Port5).DataAddress)) if (status) then Call PutPin(4, zxOutputHigh) 'Turn on GRN3 Rx ELSE Call PutPin(4, zxOutputLow) 'Turn off GRN3 Rx End if status = StatusQueue(CByteArray(Outbuf(1, port5).DataAddress)) if (status) then Call PutPin(26, zxOutputHigh) 'Turn on RED3 Tx ELSE Call PutPin(26, zxOutputLow) 'Turn off RED3 Tx End if '----------------------------------------------- status = StatusQueue(CByteArray(Inbuf(1, Port6).DataAddress)) if (status) then Call PutPin(28, zxOutputHigh) 'Turn on GRN4 Rx ELSE Call PutPin(28, zxOutputLow) 'Turn off GRN4 Rx End if status = StatusQueue(CByteArray(Outbuf(1, port6).DataAddress)) if (status) then Call PutPin(27, zxOutputHigh) 'Turn on RED4 Tx ELSE Call PutPin(27, zxOutputLow) 'Turn off RED4 Tx End if end sub '============================================================================== ' PC HyperTerminal Turn Around Test '============================================================================== Public Sub HT_TurnaroundTest(ByVal port as Byte) 'Echos chars sent from PC back to the PC static Rx as byte static Tx as byte Dim Success as boolean 'Make note of your com parameters e.g. baud rate & data width, parity, stop bits (8,N,1) 'Hookup a RS232 cross/over cable or null/modem cable between PC and port. 'Activate PC HyperTerminal - make sure flow control is none! & install matching com parameters. 'Put this routine in a do/loop CALL GetByte(Port,Rx,Success) If (Success) then Tx = RX Call PutByte(Port,Tx) End if End Sub '===============================================================================