Accessing Comms Buffers in QuickBasic 
Author Message
 Accessing Comms Buffers in QuickBasic

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



Thu, 25 May 2000 03:00:00 GMT  
 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



Thu, 01 Jun 2000 03:00:00 GMT  
 Accessing Comms Buffers in QuickBasic

I finally solved my problem, i want to acknowledge all the people that
helped me.
As everyone said me my problem was not in reading the comms buffer. In
fact, what was slowing down the program was the string resizing each
time it grew by one or two chars.
I post here the main loop of the program that solved my problem. I
used a fixed length string as a buffer.

DEFINT A-Z
PORTINI$ = "COM1: 9600,O,7,1,DS,RB10000"
NUMPORT = AskWhichPort(1)                       'port to use
MID$(PORTINI$, 4, 1) = LTRIM$(STR$(NUMPORT))
OPEN PORTINI$ FOR RANDOM AS #1    

'rx$ is a constant length input buffer, rxptr a pointer to the end of
'the buffer, rxtemp has nr of bytes waiting at the port
RX$ = SPACE$(2048): RXPTR = 1: RXTEMP = 0       'rx$=input buffer
CLS
SendDeviceInitMsg

'main loop
CAD$ = ""                                     'command buffer
DO
    A$ = INKEY$                                 'get keys from user
    'update pointer in command buffer, add a$ to buffer
    EDIT A$, CAD$                              
    'if cad$ has a complete command execute it (send comm, change
mode,
    'quit,...)  
    DoCommand CAD$                              'obey command
'This is the answer i found for my question
    RXTEMP = LOC(1)                             'no of bytes waiting
    MID$(RX$, RXPTR) = INPUT$(RXTEMP, 1)        'do the reading
    RXPTR = RXPTR + RXTEMP                      'increase ptr
    ENDMSg = INSTR(RX$, CHR$(3))                'search end of message
    IF Endmsg THEN                              'found                          
        IF Endmsg < RXPTR THEN                  'not past end of input
                 B$ = LEFT$(RX$, endmsg)        'copy message to
string
                'clear message from buffer
                MID$(RX$, 1) = MID$(RX$, endmsg + 1, RXPTR - endmsg)
                RXPTR = RXPTR - endmsg          'update ptr
         END IF
    END IF
    ProcessInput B$                             'process received msg

LOOP



Sun, 04 Jun 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Comms Transmit Buffer Query

2. Comms Transmit Buffer query

3. Question on serial comms for QuickBASIC

4. VB on 3.11 accessing NT comms pipe

5. Serial COMMs in Access 97

6. Paasing Struct containg Pointers to buffer and len of buffer to Dll

7. converting quickbasic code to ascii, or vb, or anything besides quickbasic

8. Access Keyboard Buffer?

9. accessing windows text buffer

10. Direct access to COPY BUFFER possible?

11. Buffered file access?

12. Need access to COPY BUFFER in JET

 

 
Powered by phpBB® Forum Software