ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   CommRead data with unknown length (https://www.excelbanter.com/excel-programming/447177-commread-data-unknown-length.html)

Christof Kluß

CommRead data with unknown length
 
Hi

there are many good tutorial for communication with the serial port via
VBA like http://www.thescarms.com/vbasic/commio.aspx or
http://dev.emcelettronica.com/serial...tion-excel-vba
All of them seems to use something like

CommRead(intPortID, strData, lngSize)

But my device sends data with unknown length. Is there a way to
implement an wrapper for CommRead that bypass the lngsize, so that i can
read the whole string sended?

thx
Christof

Bruce Bowler

CommRead data with unknown length
 
On Thu, 20 Sep 2012 17:13:42 +0200, Christof Kluß wrote:

Hi

there are many good tutorial for communication with the serial port via
VBA like http://www.thescarms.com/vbasic/commio.aspx or
http://dev.emcelettronica.com/serial...tion-excel-vba All of
them seems to use something like

CommRead(intPortID, strData, lngSize)

But my device sends data with unknown length. Is there a way to
implement an wrapper for CommRead that bypass the lngsize, so that i can
read the whole string sended?

thx Christof


How does the device terminate what ever it is it sends? If that's known,
you should be able to read a character at a time, concatenating them
together, until you get the "end of data" indicator...

Bruce


Christof Kluß

CommRead data with unknown length
 
Hi Bruce

Am 20-09-2012 20:10, schrieb Bruce Bowler:
On Thu, 20 Sep 2012 17:13:42 +0200, Christof Kluß wrote:
How does the device terminate what ever it is it sends? If that's known,
you should be able to read a character at a time, concatenating them
together, until you get the "end of data" indicator...


I only know that the output comes in lines that end with "CRLF", but it
is not set how many lines. Perhaps I can read until long time nothing
comes (after a CRLF)? Do you have an idea how to do this?

Probably, like you said, I have to read one character at time, but how
do I know, if I am out of time?

Do
lngStatus = CommRead(intPortID, strData, 1)
buffer = buffer & strData
...
Loop Until outoftime

Christof

Christof Kluß

CommRead data with unknown length
 

Is there a way to implement a SerialPort.ReadExisting in VBA?

For NET there is

http://msdn.microsoft.com/library/sy...dexisting.aspx

Am 20-09-2012 20:37, schrieb Christof Kluß:
Hi Bruce

Am 20-09-2012 20:10, schrieb Bruce Bowler:
On Thu, 20 Sep 2012 17:13:42 +0200, Christof Kluß wrote:
How does the device terminate what ever it is it sends? If that's known,
you should be able to read a character at a time, concatenating them
together, until you get the "end of data" indicator...


I only know that the output comes in lines that end with "CRLF", but it
is not set how many lines. Perhaps I can read until long time nothing
comes (after a CRLF)? Do you have an idea how to do this?

Probably, like you said, I have to read one character at time, but how
do I know, if I am out of time?

Do
lngStatus = CommRead(intPortID, strData, 1)
buffer = buffer & strData
...
Loop Until outoftime

Christof




All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com