Think this might go here!

paradox6996

Registered
I need to change a script from Windows to be able to work on all recent MacOS operating systems. All I need it to do is to be able to run from a terminal. If anyone can help me with this, I would be most appreciated.

Thank You, Paradox(>")>

Code:
'==============================================================================
'
'  DigiSnap_Terminal.Bas
'  PC Serial Terminal Emulator, set up for the DigiSnap
'  Copyright 2003 Harbortronics LLC
'
'==============================================================================

#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG

    LOCAL nComm   AS LONG    ' file number of open comm port.
    LOCAL ncbData AS LONG    ' bytes of data waiting
    LOCAL sData   AS STRING  ' data received or to send
    LOCAL Param AS STRING
    LOCAL ComPort AS STRING
    LOCAL k AS STRING
    LOCAL n AS INTEGER
    LOCAL OK AS INTEGER

    STDOUT "DigiSnap_Terminal   V1.2"
    STDOUT "Copyright Harbortronics Inc, July 2008"
    STDOUT "www.Harbortronics.com"
    STDOUT ""
    ERRCLEAR

    CONSOLE NAME "DigiSnap_Terminal       www.Harbortronics.com"


    n = 1
    OK = 0
    DO
         ComPort = "COM" & TRIM$(STR$(n))

          ' Open the comm port. Exit if it can't be opened.
          nComm = FREEFILE
          COMM OPEN ComPort AS #nComm
          IF ERR THEN
            '    STDERR "Can't open comm port " & ComPort
                ERRCLEAR
             ELSE
                OK=n
                STDOUT "Port " & ComPort & " is available"
          END IF
          n = n + 1
          SLEEP 50
          COMM CLOSE #nComm
          SLEEP 50
    LOOP UNTIL n > 16

    IF OK = 0 THEN
          STDOUT "Cannot open any COMM ports... check your hardware"
          WAITKEY$

        ELSE
           STDOUT "Which COM port do you wish to use? (1..16)"
           STDOUT "Enter the number, or just hit the <Enter> key to use COM" & TRIM$(STR$(OK))
           INPUT k
          ' STDOUT "You Entered" & k
           k = TRIM$(k)
           IF k = "" THEN
                   ComPort = TRIM$(STR$(OK))
               ELSE
                   IF LEN(k)=5 THEN k = RIGHT$(k,2)
                   IF LEN(k)=4 THEN k = RIGHT$(k,1)

                   SELECT CASE VAL(k)
                       CASE 1 TO 16
                           ComPort = k
                       CASE ELSE
                           ComPort = "1"
                   END SELECT
           END IF

           ComPort = "COM" & ComPort

           ' Open the comm port. Exit if it can't be opened.
           nComm = FREEFILE
           COMM OPEN ComPort AS #nComm
           IF ERR THEN
               STDERR "Can't open comm port " & ComPort
               WAITKEY$
               EXIT FUNCTION
           END IF

           STDOUT "Connect the DigiSnap to " & ComPort & " using the supplied (null modem) cable."
           STDOUT "Press any button on the DigiSnap to start."
           STDOUT

           COMM SET #nComm, BAUD   = 19200  '19200 baud
           COMM SET #nComm, BYTE   = 8     ' 8 bits
           COMM SET #nComm, PARITY = 0     ' No parity
           COMM SET #nComm, STOP   = 0     ' 1 stop bit

           DO
               ' Handle data from the serial port.
               ncbData = COMM(#nComm, RXQUE)
               IF ncbData THEN
                   COMM RECV #nComm, ncbData, sData
                   STDOUT sData;
               END IF

               ' Handle data from the keyboard.
               IF INSTAT THEN
                   sData = INKEY$
                   IF sData = $ESC THEN
                           STDOUT "Press <ESC> again to exit, any other key to continue"
                           sData = WAITKEY$
                           IF sData = $ESC THEN EXIT DO
                       ELSE
                           COMM SEND #nComm, sData
                   END IF
               END IF

               ' Give other processes a chance to run.
               SLEEP 0
           LOOP

           ' Close the comm port.
           COMM CLOSE #nComm

    END IF


END FUNCTION
 
Back
Top