home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 8,907 of 10,840   
   Sonoman to All   
   funny looping and serial data problem   
   25 Oct 04 20:46:12   
   
   From: billgates@microsoft.com   
      
   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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca