[futurebasic] Re: [FB] Modem/OPEN "C"

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2001 : Group Archive : Group : All Groups

From: "Terrald J. Smith" <terrald@...>
Date: Wed, 29 Aug 2001 19:39:34 -0500
> Terrald,
> 
> Post the code.
> 
> Ken
Ok...a repeat for Kem....two small simple codes the first one is to try to
send data to the second phone modem...it does ring and waits for the second
one to respond.

DIM gA$,gAZ$,gEMCPH$,I&,ILD&,DONE,termwhen,gFinished
END GLOBALS

WINDOW 1,"Sending readings",(10,50)-(400,400),_dialogMovable

LOCAL MODE
DIM PortStatus
LOCAL FN oldTermGetStatus(WhichPort)              'Is the Port in use?
  SELECT CASE WhichPort
    CASE _modemPort   : PortStatus = PEEK(_portAUse)
    CASE _printerPort : PortStatus = PEEK(_portBUse)
    CASE ELSE         : PortStatus = 3            'Bad Port specified...
  END SELECT
  '
  PortStatus = PortStatus AND &F                  'Ignore upper 4 bits
  '
  SELECT CASE PortStatus
    CASE 0,15 : PortStatus = 0                    'Available for program
use.
    CASE 1                                        'Open for Appletalk use.
    CASE 2                                        'Open for serial I/O by
someone.
    CASE ELSE : PortStatus = 3                    'Unknown port status
  END SELECT
  '
END FN = PortStatus

CLEAR LOCAL
DIM Rcvd$,Tmp$;2
DIM StopTime&,TheChar%
LOCAL FN WaitModemMsg$(PortID%, WaitTicks&)
  StopTime& = WaitTicks& + FN TICKCOUNT
  DO
    READ #PortID%, Tmp$;0
    TheChar% = ASC(Tmp$) AND 127
    SELECT CASE TheChar%
      CASE 0,10                                   'Ignore Line feeds...
      CASE 13     : Rcvd$ = Rcvd$ + "<cr>"        'Show Carriage returns...
        IF INSTR(1,gA$,"ATDT")>0 THEN gA$=""
      CASE < _" " : Rcvd$ = Rcvd$ + "<&"+RIGHT$(HEX$(TheChar%),2)+">"'Show
Control characters...
      CASE ELSE  : Rcvd$ = Rcvd$ + CHR$(TheChar%)'Add to returned string...
        gA$=gA$+Tmp$
    END SELECT
  UNTIL TheChar% = 13 OR FN TICKCOUNT > StopTime&
END FN = Rcvd$


LOCAL
DIM modemStr$,rsp$
DIM Rcvd$,StartTicks&,EndTicks&,LineRecieved%
LOCAL FN TermOptions(item)
  modemStr$ = ""
  SELECT item
    CASE 1                                        'dial
      rsp$ =gEMCPH$
      LONG IF LEN(rsp$)
        modemStr$ = "ATDT " + rsp$
      END IF
    CASE 2                                        'answer
      modemStr$ = "AT A"
    CASE 3                                        'hang up
      modemStr$ = "AT H"
    CASE 4                                        'pickup
      modemStr$ = "AT H1"
    CASE 5                                        'divider
    CASE 6                                        'echo on
      modemStr$ = "AT E1"
    CASE 7                                        'echo off
      modemStr$ = "AT E"
    CASE 8                                        'divider line
    CASE 9                                        'escape
      PRINT #_modemPort,"+++";
  END SELECT
  LONG IF LEN(modemStr$)
    modemStr$ = modemStr$ + CHR$(13)
    PRINT #_modemPort,modemStr$;
    LineRecieved% = _False
    LONG IF INSTR(1,modemStr$,"ATDT")>0
      REM DELAY 10000
      DO
        StartTicks& = FN TICKCOUNT
        Rcvd$ = FN WaitModemMsg$ (_modemPort, 30)'15)
        EndTicks& = FN TICKCOUNT
        LONG IF LEN(Rcvd$)
          LineRecieved% = _zTrue
        END IF
      UNTIL Rcvd$ = ""
    END IF
  END IF
  IF INSTR(1,gA$,"NO DIALTONE")>0 THEN gA$="NO COMM"
  IF INSTR(1,gA$,"BUSY")>0 THEN gA$="NO COMM"
  IF INSTR(1,gA$,"NO CARRIER")>0 THEN gA$="NO COMM"
END FN

gEMCPH$="4529392"
gAZ$="This is the first sent"
LONG IF FN oldTermGetStatus(_modemPort)=0
  OPEN "C", _modemPort, 57600, _noParity, _oneStopBit, _eightBits, 32767
  HANDSHAKE #_modemPort, _none
  gA$=""
  FN TermOptions(1)
  LONG IF INSTR(1,gA$,"NO COMM")=0
    LONG IF FN oldTermGetStatus(_modemPort) =2
      FOR I&=1 TO ILD&
        LONG IF FN oldTermGetStatus(_modemPort) <> _False
          PRINT #_modemPort, gAZ$
        XELSE
          I&=ILD&:termwhen=_True:DONE=0
        END IF
      NEXT
    END IF
    FN TermOptions(3)
  END IF
END IF
INPUT"";gA$
CLOSE:END

This second one does respond and send something to the first modem (I can
here it)....but I cannot detect that it is getting any data from the first
modem....

WINDOW 1,"Receive readings",(10,50)-(400,400),_dialogMovable

LOCAL FN checkPort
  READ #_modemPort,a$;0                           'grab one byte
  SELECT a$
    CASE ":"                                      'start of record
      PRINT ": start of record";
    CASE ELSE
      READ #_modemPort,b$;0                       'grab second byte
      d$ = a$ + b$
      LONG IF d$ <> ""
        PRINT d$;" ";
      END IF
      SELECT d$
        CASE "00"                                 'nothing
        CASE "0D"                                 'return
        CASE "80"                                 'text field
        CASE "0A"                                 'line feed
          PRINT #_modemPort,"#";
          c$ = ""
        CASE "FC"                                 'ASC(252)
        CASE "FF"                                 'end of record
          PRINT #_modemPort,"#";
        CASE ELSE
          b$ = "&H" + a$ + b$
          test = VAL(b$)
          c$ = c$ + CHR$(test)
      END SELECT
  END SELECT
END FN

OPEN "C",_modemPort,57600,_noParity,_oneStopBit,_sevenBits,256
HANDSHAKE #_modemPort,_none
PRINT # _modemPort,"AT S0=1"
DO
  HANDLEEVENTS
  FN checkPort
UNTIL gFinished

When/if I can get this to work and import into the real program I have some
other issues.

1) the original sender will need to know if the its modem is working and if
the other modem is responding.  Then it will need to send data...and
hopefully will know that it is doing so and sending all the data
2) after it sends data, the other modem will send it some data to confirm
that it got something....

this stuff is very complicated and I have not investigated everything until
I know how to do the transfer stuff at all.  And it has to be VERY
private...no way it could/should be sent per the internet.... legally this
would be a problem but I may even have a stronger opinion than the legal
guys.

Oh yeah....an early mention about     LineRecieved....I did not write this
code but I do know about the spelling.....but, I am the dummy.

The Dummy,

Terrald J. Smith