
Accessing Comms Buffers in QuickBasic
Quote:
> I'm developing a Quick Basic program to set the parameters of the DDC
> controllers of a BMS system. These controllers are in a two wire bus
> and when they answer (at 9600 baud) you must be ready yo catch all the
> stuff they send or you loose it. There is no flow control at all.
> Moreover, they use CHR$(3) instead of the CR char to indicate end of
> line, so i can't use LINE INPUT # to read an entire line, i must
> gather the chars in a string and search it for CHR$(3) to separate the
> lines.
> My question is:
> Is there any way to find the Comms Buffer in the memory?
> I think this way i could examinate directly the Comms Buffer for
> Chr$(3) with PEEK and read complete lines from it with INPUT$
> By the way , i have no assembler.
> Does anyone have better ideas?
> Best regards
> Antoni
Peeking &poking are not really necessary....
The following is a non-interrupt-driven routine that I wrote for a Diabetes
BG Meter.
As in your situation, as soon as the merter is turned on it begins
transmitting data.
It may start with a BEEP code, but always sends header data which must be
captured.
Data length and terminators vary depending on type of data.
I open my com file with and then enter a timed loop waiting for inirial
data. If it times out, I close the com port and notify the user to check
connections and start again.
This routine is called from several places to get data and save it for
analysis. You do not need to worry about missing any data as 9600 baud is
very slow and should never come c;ose to filling the com buffer during data
processing. If this should be a concern, increase the size of your com
buffer/
-------------------------------------------------------------------
get.com:
line.type = ""
WHILE line.type = "": GOSUB check.com: WEND
RETURN
' -------------------------------------------------------------------
check.com:
Mimic = "" ' OTII
x.cll = 0 ' com line length
' NOTE x.cfn is the comm file number..........
IF LOC(x.cfn) < 7 THEN RETURN ' Min line size (OTII) 6+CR
com.data = com.data + INPUT$(LOC(x.cfn) - 1, x.cfn) ' Get Meter Data
' Build an internal buffer of the com data disregarding type of
terminator......
' The following routines are processing I use to handle different types of
data.
' Most of it will not be of any significance to you but will show how to
pick ul a line..
IF Meter = "2" THEN ' OTII ' Line data terminates with
CRLF
x.cll = INSTR(com.data, ENTER$)
IF x.cll = 7 OR (x.cnt = 0 AND x.cll = 9) THEN
Mimic = "Y"
ELSE x.cll = 0
END IF
END IF
IF x.cll = 0 THEN x.cll = INSTR(com.data, LF$) ' Find LF, if any
IF x.cll > 0 THEN
x.cnt = x.cnt + 1
com.line = LEFT$(com.data, x.cll)
com.data = MID$(com.data, x.cll + 1) ' Del from Com.Data
com.line = LEFT$(com.line, LEN(com.line) - 1) ' Drop CR or LF
IF RIGHT$(com.line, 1) = ENTER$ THEN
com.line = LEFT$(com.line, LEN(com.line) - 1) ' Drop CR of CRLF
END IF
IF Mimic = "Y" AND LEFT$(com.line, 1) = CHR$(7) THEN
com.line = RIGHT$(com.line, LEN(com.line) - 1) ' Drop BEEP
END IF
IF LEN(com.line) < 3 THEN RETURN ' Drop it
IF LEFT$(com.line, 1) <= "9" OR Mimic = "Y" THEN ' OTP / OTII
line.type = "S" ' Meter Screen Line
GOSUB Mimic.Meter
ELSE
line.type = "D"
GOSUB Display.Data
END IF
ELSE
line.type = ""
END IF
RETURN
Hope this helps.....
Jim