使用VB.net的串行端口 [英] Serial Port Using VB.net

查看:75
本文介绍了使用VB.net的串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!大家,

我正在制作一个连接到串行端口设备The Newbridge 36110 MainStreet的应用程序,我可以使用"CFG"之类的命令登录,然后终端会提示我CFG>.
但是,当我发送"FEP 01,X25"之类的命令时,它给我一个错误语法错误,并且仅显示"FEP [] []",然后当我再次发送该命令时,它将显示"FEP,X [] []"然后会再次显示"FEP 0 [] []",就像只能处理第一种语法,不能确定是空格还是逐字节.顺便说一下,[]是一个ASCII框代码.请帮我这个家伙.实际代码如下.

Hi! everyone,

I''m making an app that connect to a serial port device, The Newbridge 36110 MainStreet, I am able to login type in a command like "CFG" then the terminal would prompt me with CFG>
but when I send a command like "FEP 01,X25" it gives me an error syntax error and it displays only "FEP[][]" then when I send that command again it would display "FEP,X[][]" then again would display "FEP 0[][]" it like can only process the 1st syntax not after the space or byte by byte not sure. By the way the [] is an ascii box code. Please help me on this guys. actual code below.

       Dim WithEvents SP As New IO.Ports.SerialPort

       Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SP.PortName = "COM1"
        SP.BaudRate = 9600
        SP.Parity = IO.Ports.Parity.None
        SP.StopBits = IO.Ports.StopBits.One
        SP.DataBits = 8
        SP.DtrEnable = True
        SP.RtsEnable = True
        SP.Encoding = System.Text.Encoding.ASCII
        SP.Handshake = IO.Ports.Handshake.None
    End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Try
            SP.Write(txtCommand.Text & Chr(13))
            txtCommand.Text = String.Empty
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub


Private Sub btnFEP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFEP.Click
        'Send A FEP 01,X25 Command
        Dim str As String = "FEP 01,X25"
        SP.Write(str & Chr(13))
    End Sub



我创建了btnFEP来自动发送命令,也可以从btnSEND发送命令,其中txtCommand是在语法中键入的位置.



I created the btnFEP to send the command automatically, the command can also be sent from btnSEND where the txtCommand is where typed in the syntax.

推荐答案

在字符串表达式中,符号"X"用于特定目的,请查看msdn库中的字符串格式,您会发现它,这是我认为未获得正确输出的原因.
In string expressions the symbol "X" is used for specific purpose, check out the string format on msdn library you will find it, it is the reason I believe you are not getting the right output.


这篇关于使用VB.net的串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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