473,383 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

funny looping and serial data problem

Hello everyone:
I am new to Visual Basic and I have a problem that I cannot put my
finger on. I am working on a school project and I am getting some serial
data from a microprocessor. I have designed my "Do" loop to wait for
each data set coming in at intervals of about 1/2 a second from the
microprocessor.

When I comment the following lines:

bufferVar = ""
myBufferData = ""
myDataString = ""

in my code below I get the correct serial data set the first time around
and after that it repeats the same data in the textbox however many
times determined by the "for" loop with only one serial data delay (1/2
a second). BUT if I uncomment these lines I only get the last data set
once after the correct delay determined by the for loop. So, if I have 6
serial data sets my program will run for 3 seconds and display only the
last data set.

What I would like it to do is to print each data set as it arrives for a
long period of time. Any Ideas? Thanks in advance.
Here is my code:
Private Sub Command1_Click(Index As Integer)

'setup the port
If MSComm1.PortOpen = False Then MSComm1.CommPort = 5
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeText

For i = 1 To 3
'reset data to enter clean every time
'endFlag used to find out when buffer has one full data set
endFlag = False
'MSComm1.InBufferCount = 0 to start with empty buffer every time
MSComm1.InBufferCount = 0
'start clean every time to extract serial data
'OK, if I comment these three variables I get only the first serial
data set
'repeated however many times is indicated in the "for" loop
'BUT, if I uncomment these three variables I get only the last data set
'with the correct delay (1/2 a sec per iteration of "for" loop)
bufferVar = ""
myBufferData = ""
myDataString = ""

setEnd = 0

'loops until "last item" marker is found
'and sets location value to setEnd
Do
myBufferData = myBufferData & MSComm1.Input
endFlag = InStr(myBufferData, ",")
Loop Until endFlag = True

'locates last item marker on data set
setEnd = InStr(myBufferData, ",")

'gets location markers for x, y and z
xPos = InStr(myBufferData, "x")
yPos = InStr(myBufferData, "y")
zPos = InStr(myBufferData, "z")

'builds buffer data set string
'used to print the variable locations to the screen, not important
bufferVar = bufferVar & "xPos = " & xPos & vbCrLf
bufferVar = bufferVar & "yPos = " & yPos & vbCrLf
bufferVar = bufferVar & "zPos = " & zPos & vbCrLf
bufferVar = bufferVar & "setEnd = " & setEnd & vbCrLf

myDataString = myDataString & "x = " & Mid(myBufferData, (xPos +
1), (yPos - xPos - 1)) & " "
myDataString = myDataString & "y = " & Mid(myBufferData, (yPos +
1), (zPos - yPos - 1)) & " "
myDataString = myDataString & "z = " & Mid(myBufferData, (zPos +
1), (setEnd - zPos - 1)) & vbCrLf

'write to textBoxes
txtData.Text = myDataString
txtBuffer.Text = bufferVar

Next i

'when done close com port
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub
Jul 17 '05 #1
2 3587
On Mon, 25 Oct 2004 20:46:12 -0400, Sonoman <bi*******@microsoft.com>
you typed some letters in random order:

What do you expect to receive in to the comport exactly ?

If you know how long the string is you are receiving,then try using
the 'MSC_OnComm()' event.

This event gets triggered when the input buffer reaches a certain
size. The size can be set on the 'Rthreshold' property

perhaps this helps


Groetjenz,

Mickey
--
#### gewoan skrieve su ast ut seist ####
Jul 17 '05 #2
mickey wrote:
On Mon, 25 Oct 2004 20:46:12 -0400, Sonoman <bi*******@microsoft.com>
you typed some letters in random order:

What do you expect to receive in to the comport exactly ?

If you know how long the string is you are receiving,then try using
the 'MSC_OnComm()' event.

This event gets triggered when the input buffer reaches a certain
size. The size can be set on the 'Rthreshold' property

perhaps this helps


Groetjenz,

Mickey


Thank you for your response. I have the Do loop because the length of
the string varies from 7 to 13 characters randomly. Like I said before
this is my first time using VB, so I will look into that MSC_OnComm()
function to see if I could use it.

Anyway, I don't think that is going to solve my data displaying problem.
I spoke to one of my professors today and he pointed out something
interesting about the way I am building my strings. I did not really
understand him then but now I know where to look.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
1
by: kiran | last post by:
Hi all, I have a problem to communicate with serial port(COM3:). I am able to open the handle but cannot send any data. 1. I connected my motoroala handset to PC through datacable. 2. I...
7
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
2
by: findyasir | last post by:
Hi all, I am having problem comunication with serial port in linux. I have tested the serial port with attaching a serial modem and dialing the numbers with wvdial. it works okie but when i...
5
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The...
2
by: joaquimfpinto | last post by:
Dear All, I made an app in c# that uses several serial ports. For the serial ports I use a pnp Sunix board, some with 8 serial ports other with 4 or even 2 serial ports. Whenever I use the...
2
by: mmrasheed | last post by:
Hi, I am newbie in python. I am working on Telit GM862 GPS/GPRS module which has python interpreter built in. But it seems this problem is pretty much related to general python structure. I...
4
by: JDS | last post by:
I have an application that interfaces with a USB device using the .Net serial port. The code works fine, displaying live data on the screen; that is until the USB lead is pulled out from the PC...
4
by: Xavier | last post by:
Hi, I try to access to a Bluetooth GPS data-logger with Python. I use pySerial. Sending and receiving little messages (~100 char) works fine. However, when I ask the GPS to dump the trails,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.