I used QB to read data from 2 Mitutoyo indicators via serial ports. Recently I have to add one more indicator.
QB does not open COM3, so now I am moving to FreeBasic (under Windows'98). I found a strange thing. The COM1 port is working, while others do not.
Below is a part of code that works well with COM1, but does not if I change COM1 say to COM2 and i = 2. No data could be read.
Code: Select all
Option Explicit
DIM SHARED adro(1 TO 3) AS SHORT => {&H3F8, &H2F8, &H3E8}
DIM AS SHORT xc, m, i, ik, aa, a, sl
DIM as string f, Spec, yyyy, dddd, k, ast, ain, ss, s
DIM AS SINGLE T, T0, T1, r, tt, delay, timr
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
CLOSE
i = 1
OPEN COM "COM1:9600,n,8,1,ds" FOR BINARY AS #1
OUT(adro(i), 3) 'Reset the interface
SLEEP 10
OUT(adro(i), 13)
SLEEP 10
PRINT " RS232 opened "
OUT(adro(i), ASC("1")) 'Sending data request
OUT(adro(i), 13)
' Now waiting data ...
timr = TIMER: ain = ""
DO
IF LOC(1) >= 1 THEN
' LOC(...) gives the number of characters waiting:
ast = INPUT$(1, #1)
aa = ASC(ast)
ain = ain + ast
END IF
LOOP WHILE aa <> 13 AND TIMER - timr < 3
PRINT "ain", ain
a = INSTR(ain, "A")
CLOSE
SLEEP
END
Any suggestions?