I am using the code I posted on the DataAvailable Event.
[quote=187299:@Chris Carter]I think you should use the
DataAvailable event to accumulate whole lines
( until chr(13) is met, assuming that is your end-of-line character )
and then parse out the number, something like this
( This is off the top of my head, untested, so beware )…
[code]Form property: input_buffer as string
// Add available data to our buffer…
input_buffer = input_buffer + me.readall(Encodings.ISOLatin1)
// Look for end-of-line by splitting the line up…
// ( This also copes with multiple values having been accumulated )
dim items(-1) as string
items = input_buffer.split( chr(13 )
dim last_item as integer = items.ubound
if last_item > 0 then
// last item can be empty, or part-value
input_buffer = item( last_item )
last_item = last_item - 1 // last full value
for at as integer = 0 to last_item
call process_value( item(at).trim )
Function: process_value( value_string as string )
readpressure = false [/code]
Note: Also: If a value is only sent in response to the string you are sending,
then would it might be better to do this from your 1 sec timer, like…
[code]In timer code:
if NOT readpressure then
// Only do this if we are not already waiting for a reading
readpressure = true
dim s as string = “!001:SYS?” + chr(13)
end if [/code][/quote]
The readpressure property is a boolean that sets it to input the data into a listbox to be charted.
Shouldn’t I not use a timer to run the serial port?
[quote=187301:@Russ Lunn]@Chris Carter is right, use the dataavailable event
use the lookahead function.
it returns whats in the buffer without removing it.
so you can do something like
eolPos = serial1.lookahead.instr(endofline)
if eolpos > 0 then
thiscmd = serial.read(eolpos)
which will let the dataavailableevents fire, but only read the data once it contains the endofline character
much cleaner and less error prone i find[/quote]
So does that look for a quantifiable amount or for the end line character?
The problem isn’t zeros, it is partial numbers. The carts will look like this
So the end line character is a great idea. How would y’all edit the code I started with to look ahead for that?
Obviously a LookAhead code is needed, but what would it be?