Author | Topic: Serial Port In Buffer Search | |
---|---|---|
Al Wimberly | Serial Port In Buffer Search on Wed, 14 Apr 2010 13:50:30 -0400 Is there some way to search the in buffer on a serial port for a specific character without removing or changing any characters? | |
James Loughner | Re: Serial Port In Buffer Search on Wed, 14 Apr 2010 15:16:44 -0400 On 04/14/2010 01:50 PM, Al Wimberly wrote: > Is there some way to search the in buffer on a serial port for a specific > character without removing or changing any characters? > > > > What are you using to control the serial port? Jim | |
Jack Duijf | Re: Serial Port In Buffer Search on Wed, 14 Apr 2010 21:58:22 +0200 Hello Al, This goes back to Clipper 5.x with Clipper tools. In those old days, you were able to use: cData := Com_Read( 1 , ,.T.) This read the com buffer, but the buffer was not cleared. So you could Com_Read(1,,.F.) and read the same buffer again (and clears the read buffer). Unfortunaly this option is not availeble in Xbase++ tools. The help says: Com_Read( <nComPortNum> , ; [<nBytesToRead>], ; <ignored> ; ) --> cString NOTE: The CA-Tools function allows a third parameter that specifies whether or not the bytes are to be deleted from the receive buffer. This feature cannot be provided and the third parameter is ignored. However, there is a workarround. Create a thread that reads the COM input port continuesly, and build your own read-buffer. Then in another thread you can monitor / read the COM device. See speudo code below, that should point you in the right direction. Regards, Jack Duijf Procedure Main() LOCAL nPort := 1 LOCAL oComm := ComPort():New(nPort) oComm:Start() Do while Inkey(.1) <> 27 if oComm:TestBuffer("Hello") ? oComm:GetBuffer() endif Enddo oComm:Terminate() Return CLASS ComPort From Thread HIDDEN: VAR lAbort VAR cBuffer VAR lTerminated EXPORTED METHOD Init SYNC METHOD TestBuffer SYNC METHOD GetBuffer SYNC METHOD AddToBuffer METHOD Execute METHOD Terminate Endclass METHOD ComPort:Init(nPort) Thread:init() ... Com_open(...) ... Return SELF METHOD ComPort:Execute() ::lAbort := FALSE ::lTerminated := FALSE nRead := 0 Do while !lAbort if (nRead := Com_Count(nPort)) > 0 ::AddToBuffer(Com_Read(nPort)) else Sleep(10) endif enddo ::lTerminate := TRUE Com_Close(...) Return METHOD Comport:Terminate() ::lAbort := TRUE Do while !::lTerminated Sleep(5) Enddo Return METHOD Comport:AddToBuffer(cData) ::cBuffer += cData Return METHOD Comport:TestBuffer(cData) Return (cData $ ::cBuffer) METHOD Comport:GetBuffer(nLen) LOCAL cRet := "" Default nLen To Len(::cBuffer) nLen := Min(nLen,Len(::cBuffer)) cRet := Substr(::cBuffer,1,nLen) ::cBuffer := Substr(::cBuffer,nLen+1) Return cRet Op 14-4-2010 19:50, Al Wimberly schreef: > Is there some way to search the in buffer on a serial port for a specific > character without removing or changing any characters? > > > > |