Vb2015写入串口问题 [英] Vb2015 problems writing to serial ports

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

问题描述

我有一台设备通过USB端口连接到我的电脑。这显示为COM7。



使用VB我可以打开端口,但发送给它的任何数据都无法到达。我可以告诉我,因为命令应该打开灯,等等。我已经尝试将COM7更改为COM19并且端口无法打开。



我可以打开端口并从HyperTerminal和Docklight发送数据。我可以将我的PC连接到运行Docklight或HyperTerminal的另一台PC,数据就到了那里。所以我对我的代码非常有信心,如下所示。



我读过几年前发表的文章,谈论串口并说有问题净3.5。问题是你不能用它来解决串口问题。









I have a piece of equipment connected to my PC by USB port. This is showing up as COM7.

Using VB I can open the port, but any data sent to it does not get there. This I can tell because the command should switch a light on, amongst other things. I have tried changing COM7 to COM19 and port does not open.

I can open port and send data from HyperTerminal and from Docklight. I can connect my PC to another PC running Docklight or HyperTerminal and the data gets there. So I am fairly confident about my code, shown below.

I have read an article published a few years ago, talking about serial ports and saying that there were problems with Net 3.5. The problems were such that you couldn't use it to address serial ports.




Sub SendSerialData(ByVal data As String)

        ' Send strings to a serial port.
        Dim J As Integer
        Dim jl As Integer


        Try
            SerialPort1.Open()

            'Using com1 As IO.Ports.SerialPort =
            'My.Computer.Ports.OpenSerialPort("COM7", 115200, Parity.None, 8, StopBits.One)

            

            jl = Len(data)

            For J = 1 To jl
                SerialPort1.Write(Mid(data, J, 1))
                MsgBox(Mid(data, J, 1))
            Next

            SerialPort1.Write(Chr(13))

            '   SerialPort1.WriteLine(data)
            '    com1.WriteLine(data)

            MsgBox("Sent - " & data )

            SerialPort1.Close()

            ';End Using
        Catch
            MsgBox("Problem sending")
        End Try

    End Sub





我尝试过的事情:



我尝试过各种各样的选择,其中两个你可以看到我的上面的代码,重新排除的行是替代选项。



我尝试一次发送字符串,一个字符和整行,nether工作。



我也试过设置端口参数,比如设备管理器中的波特率。



我有尝试在表单上有Seri​​alPort,而没有它。



首先,任何人都知道Net 3.5中的问题是否已修复? 4.6有效吗?



有什么建议请对此进行排序吗?我想我已经尝试了大多数写选项。



一旦有效,我就需要它来阅读回复....



谢谢用于阅读。



What I have tried:

I have tried various options, two of which you can see in my code above, the remmed out lines being the alternative option.

I have tried sending string, one character at a time and the whole line at a time, nether works.

I have also tried setting port parameters, such as baud rate in device manager.

I have tried have SerialPort on the form, and not having it.

Firstly anyone know if the problems in Net 3.5 have been fixed ? Does 4.6 work ?

Any suggestions please to sort this ? I think I have tried most of write options .

Once this works then I'll need it to read the responses....

Thanks for reading.

推荐答案

我已经将项目中的Net Framework从4.0更新到4.6,现在我可以将字符串发送到设备了。接下来整理阅读......
I have updated Net Framework in the project from 4.0 to 4.6 and I can now send strings to the device. Next to sort out reading......


这篇关于Vb2015写入串口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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