微控制器通过串口到ASP.net Web表单 [英] Microcontroller to ASP.net Web Form through Serial Port

查看:62
本文介绍了微控制器通过串口到ASP.net Web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我对我的编码进行了一些更改并对其进行了测试。它仍然没有完美的工作因此我希望在这里有一些指导。



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







我遇到的错误:

- TextBox2没有显示读数,只有TextBox1显示阅读。

- Web表单不令人耳目一新,因此我的读数没有更新。有什么方法可以自动更新Web表单吗?



感谢所有指导。

谢谢。




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.

推荐答案

首先,你在这里没有代码告诉borwser不要缓存页面并经常刷新它。



其次,您的代码只会填充TextBox1和TextBox2中的一个文本框,而不会填充另一个文本框,具体取决于您在字符串中查看的一个字符位置。只需按照 if 语句和你在字符串中跟踪的字符就可以理解为什么。
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.


我google了一下,发现Meta刷新适合我需要的东西。



i更改了if语句,使得我使用2个字符串变量读取并让它们显示在两个文本框中。



以上两种方法可能都不太合适,但我认为这对我的演示项目来说已经足够了。



谢谢。



PS:在Web窗体中实现之前,我实际上已在WinForm中测试过编码,它们实际上是在两个文本框中显示我想要的内容而只使用1个字符串变量来读取。所以我很困惑为什么它在WebForm中不会起作用。

也许有人可以解释一下这个?
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 ?


这篇关于微控制器通过串口到ASP.net Web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆