【问题标题】:Send a sequence of random characters to a com port将一系列随机字符发送到 com 端口
【发布时间】:2017-01-06 04:58:42
【问题描述】:

我只需要一个现金抽屉,通过 rj11 端口连接到我的电脑。当我询问如何在我的应用程序中打开时,他们说我只需将低于 1200 bps 的序列字符发送到端口 com5 ,因为 rj11 配置为对此做出响应。我怎样才能发送它?我已经尝试过了,但没有任何反应

Using COM As System.IO.Ports.SerialPort =
                My.Computer.Ports.OpenSerialPort("COM5")
        COM.WriteLine("Enviodeprueba")
End Using

【问题讨论】:

  • 您可能需要先设置波特率。此外,通常还需要遵循一个奇偶校验协议(例如 8n1)。
  • 您还应该验证您的 PC 在设备管理器的端口下列出了 COM5。

标签: vb.net


【解决方案1】:

如果您知道这些是正确的波特率和端口号,请先为串行端口设置这些:

Dim COM As System.IO.Ports.SerialPort = New System.IO.Ports.SerialPort
With COM
     .PortName = "COM5"
     .BaudRate = "1100"  'as you stated it has to be less than 1200
     .DataBits = 8
     'and whatever other properties you want to set for the port here
End With

那你就要打开端口了:

COM.Open()

那么你应该能够向它发送信息:

COM.WriteLine("Enviodeprueba")

完成后请务必关闭端口:

COM.Close()

This is the MSDN article about WriteLine for a port.

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 2012-03-29
    • 2019-08-30
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    相关资源
    最近更新 更多