Having spent a week attempting to write a function to extract string
data from a receive queue, I have come to the point of needing a little
help. I have noticed at the standard SerialPort_24.bas and all it's
variants have never addressed this issue so I expect that it is not easy.
Here is my miserable attempt to write such a function. It does not seem
to work.
First, these are the declarations at my serial port module. I have
essentially used SerialPort_24 my way and have used it successfully
(until now it seems) so I have confidence in all the other functions in
it. Be NOT concerned about any function/subroutine calls that are not
familiar to you.
'===============================================================================
Public Const NOINVERT as byte = &H08
Public Const INVERT as byte = &H88
'Define serial comm and queue sizes
Public Const QSIZE as Byte = 50 'com queue Size 41 + 9 bytes
Public Const BAUD12 as Long = 1200
Public Const BAUD24 as Long = 2400
Public Const BAUD96 as Long = 9600
Public Const BAUD192 as Long = 19200
'define queues
Public tq3(1 to QSIZE) as Byte 'transmit queue
Public rq3(1 to QSIZE) as Byte 'receive queue
'===============================================================================
Public Function Com3GetStr( ByRef Data() as Byte, _
ByVal startflag as Byte, _
ByVal endflag as Byte) as String
'this function extracts data from the receive queue. If the routine
times out
'without receiving the endflag byte then the function returns null
string else
'it returns string up to and including the endflag.
Dim timeout as Single
Dim ct as Byte
dim first as Byte
ct = 0 'assume failure
first = 0
Call Clearqueue(rq3) 'throw away all received
data
Do While CBool(StatusCom(1) And &H04) 'wait til xmission complete
Loop
Do While first <> startflag
Call PeekQueue(rq3, first, 1) 'look for start flag
Loop
ct = 1
timeout = Timer() + 0.2
Do While StatusQueue(rq3) And Timer() < timeout
Call GetQueue(rq3, data(ct), 1)
If data(ct) = endflag Then 'end of data is endflag
Exit Do
End If
ct = ct + 1 'get next byte
Loop
If data(ct) = endflag Then
Com3GetStr = MakeString(MemAddress(data), ct)'return actual byte count
Else
Com3GetStr = "" 'return error flag - empty string
End If
End Function 'Com3GetStr
'===============================================================================
Any enlightenment will be greatly appreciated.
Vic
--
*____________________________________________________________________________________________*
*Victor Fraenckel
KC2GUI
victorf ATSIGN windreader DOT com**
*

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )