Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
Hi,

I have done some changes to my coding and tested it. It is still not working perfectly hence i hope to have some guidance here.

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO.Ports

Partial Class Main
    Inherits System.Web.UI.Page

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load

        Dim Serialport7 As New IO.Ports.SerialPort

        With Serialport7
            .PortName = "COM7"
            .BaudRate = 9600
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
        End With

        Try
            Serialport7.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


        Dim ReceivedData As String

        ReceivedData = Serialport7.ReadLine()

        If ReceivedData.Substring(0, 1) = "T" Then

            TextBox1.Text = ReceivedData.Remove(0, 1)

        ElseIf ReceivedData.Substring(0, 1) = "H" Then

            TextBox2.Text = ReceivedData.Remove(0, 1)

        End If

        TextBox3.Text = System.DateTime.Now

        Serialport7.Close()

    End Sub

End Class



The errors i have encountered:
- TextBox2 is not displaying the reading, only TextBox1 is showing the reading.
- The Web form is not refreshing hence my readings are not updated. Is there any way i can auto update the Web form ?

Appreciates all guidance.
Thanks.
Posted
Comments
Manfred Rudolf Bihy 30-Mar-13 17:43pm    
As Dave already noted you need to show us the ASP.net markup as well, because this is where your caching and refresh issues arise from.

Regards,

Manfred

First, you've got no code in here that tells the borwser to not cache the page and to refresh it every so often.

Second, your code will only fill one textbox, out of TextBox1 and TextBox2, and not the other, depending on the one character position you look at in the string. Just follow the if statements and the character that you're tracking in the string received and you'll understand why.
 
Share this answer
 
I googled a bit and found the Meta refresh to be suited to what i need.

i changed the if statements such that im using 2 string variables to readline and have them display at both textboxes.

Both the above methods may not be nicely suited but i think it will suffice for my demo project.

Thanks.

PS: I have actually tested the coding in WinForm before implementing in Web Form and they are actually displaying what i want in both textboxes while using only 1 string variable to readline. So im quite confused why it would not work the same in WebForm.
Perhaps someone can explain this ?
 
Share this answer
 
v2
Comments
Dave Kreskowiak 31-Mar-13 21:23pm    
You can't really port code from Windows Forms to ASP.NET without knowing WHY the code works in Windows Forms.

Windows Forms maintains state, constantly. If you set the value of a textbox, that value will stay there forever, until it's changed or removed.

In ASP.NET, there is no state. Every time the page refreshes itself, it's rebuilt from the ground up knowing nothing about the previous contents of controls. So, if you set the value of a textbox in one refresh of the page but don't set it again in the next refresh of the page, the value disappears. Well, that is, unless you enable ViewState.

I suggest going through a beginners book on ASP.NET.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900