Zero_73
Zero_73

Reputation: 183

Qbasic reading comport reply without newline

I'm working on reading device reply using QBasic. The problem is the qbasic wait for the newline or CHR$(13) before outputting the data but my device reply don't have CHR$(13) (example: "OK") so qbasic hang waiting for newline.

How can i get the reply or read comport even without newline? is this possible?

[EDIT]

    CLS
     OPEN "com2:9600,n,8,1,BIN,cs,ds,rs" FOR RANDOM AS #1
    param$ ="Some data"
     PRINT #1, param$
      DO WHILE b$ <> "*CLOSE*"
       INPUT #1, b$
       PRINT b$
     LOOP

That is my code but in that code it can't read *CLOSE* because no newline after *CLOSE*.

And another thing the device delay 5 sec before replying.

Upvotes: 1

Views: 167

Answers (2)

eoredson
eoredson

Reputation: 1165

This code sample demonstrates accessing modem in Basic.

REM Reset modem source:
CLS
OPEN "COM2:9600,N,8,1,BIN,CS,DS,RS" FOR RANDOM AS #1
Reset$ = "ATZ" + CHR$(13) + CHR$(10)
PRINT #1, Reset$;
Inp$ = ""
DO
    IF LOC(1) THEN
        Inp$ = Inp$ + INPUT$(1, 1)
        IF INSTR(Inp$, "OK") THEN
            PRINT "Modem reset."
            EXIT DO
        END IF
    END IF
LOOP
END

Upvotes: 0

BdR
BdR

Reputation: 3048

Could you give an example of your code? I suspect you are using INPUT#n , but maybe instead you should use INPUT$(x). I found an example here, see code below

a$ = ""
DO
IF LOC(1) THEN a$ = a$ + INPUT$(1, 1)
LOOP UNTIL INSTR(a$, "OK")

Upvotes: 1

Related Questions