Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi.

 

Seems here to have a big problem. Tried to make this work without ask for help but can�t do it.

 

I have this application, which makes a serial communication with one device.

 

I have one function, which put from the serial char by char in one variable named �output�. This �writemessage� function is looping until the last char is out from the device, so in the last loop my output variable will contain the all string

 

This is it:

 

Private Sub WriteMessage(ByVal message As String, ByVal linefeed As Boolean)

 output += message

       If main_tab.SelectedIndex = 0 Then
           get_status_tab1()
       End If

       If main_tab.SelectedIndex = 2 Then
           get_status_tab3()
       End If

End Sub

 

 

Ok�.

 

I have a main tab with some tab pages. For two tab pages ( 1 and 3) I have two functions:

 

Public Sub get_status_tab1()

       contor2 = contor2 + 1
       If output.Length = contor2 Then
           Dim values_status1() =            System.Text.RegularExpressions.Regex.Split(output, ",")
           set_disp.Text = values_status1(7)
           interval_e.Text = values_status1(1)
           stop_h.Text = values_status1(2)
           stop_m.Text = values_status1(3)
           start_h.Text = values_status1(4)
           start_m.Text = values_status1(5)
       End If

   End Sub

 

And�.

 

Public Sub get_status_tab3()

   

       contor2 = contor2 + 1
       If output.Length = contor2 Then
           Dim values_status1() = System.Text.RegularExpressions.Regex.Split(output, vbCrLf)
           Dim values_status2() = System.Text.RegularExpressions.Regex.Split(values_status1(3), ",")

           soft_ver.Text = values_status1(1)

           If values_status2(0) = "N0" Or values_status2(0) = "N1" Then
               dig1.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(1) = "0") Or (values_status2(1) = "1") Then
               dig2.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(2) = "0") Or (values_status2(2) = "1") Then
               dig3.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(3) = "0") Or (values_status2(3) = "1") Then
               dig4.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(4) = "0") Or (values_status2(4) = "1") Then
               dig5.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(5) = "0") Or (values_status2(5) = "1") Then
               dig6.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(6) = "0") Or (values_status2(6) = "1") Then
               dig7.BackColor = System.Drawing.Color.IndianRed
           End If

           If (values_status2(7) = "0") Or (values_status2(7) = "1") Then
               dig8.BackColor = System.Drawing.Color.IndianRed
           End If



       End If

 

The issue is, that is working just one time. What I mean is, when I select the first tab and press �get status�, is perfect, I receive the info, I put them in the textbox�s, but when I go to tab 3 and press the �get status� button I have the old info (from the first tab) and everything is wrong of course. The same problem is when I go first time to tab 3 and then to tab 1.

 

I need some kind of method to flush the outoput variable and for each time I press the �get status� this variable to be empty and then to be filled by writemessage function. For those two tab pages functions.

 

 

 

Bellow is the code for sending request data to the device in my tab pages:

 

If main_tab.SelectedIndex = 0 Then

           Try
               oCP.Write(Encoding.ASCII.GetBytes("D" & Chr(13)))
           Catch ex As Exception
               MessageBox.Show("Unable to write to comm port")
           Finally
           End Try

       End If


       If main_tab.SelectedIndex = 2 Then

           Try
               oCP.Write(Encoding.ASCII.GetBytes("G" & Chr(13)))
           Catch ex As Exception
               MessageBox.Show("Unable to write to comm port")
           Finally
           End Try


           Try
               TextBox2.Text = ""
               oCP.Write(Encoding.ASCII.GetBytes("N,?" & Chr(13)))
           Catch ex As Exception
               MessageBox.Show("Unable to write to comm port")
           Finally
           End Try


       End If


 

please make me understand where I make it wrong because I can't see it.

 

thanks

Posted

done.

 

the problem was verry simple after all.

 

In every function like get_status_tab1() I have this:

 

contor2 = contor2 + 1
       If output.Length = contor2 Then

 

when I set the output variable to 0 the if condition was not true so everything after that if was not reached.

 

I know :) ... ....maybe I was tired. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...