如何写串口 [英] How to write to serial port
本文介绍了如何写串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写和获取有关串行端口的信息.
how to write and get information about serial port.
推荐答案
使用它在串行端口上进行写入
Use this, to write on serial port
Public Class Tester
Public Shared Sub Main
Dim com1Port As IO.Ports.SerialPort = Nothing
Try
com1Port = My.Computer.Ports.OpenSerialPort("COM1")
com1Port.WriteLine("serialData")
com1Port.Write("serialData")
com1Port.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
If (com1Port IsNot Nothing) Then com1Port.Dispose()
com1Port = Nothing
End Try
End Sub
End Class
获取所有端口的名称都使用此
Fot getting names of all port use this
Option Strict On
Imports System.Collections.ObjectModel
Public Module PortsTest
Public Sub Main()
Dim ports As ReadOnlyCollection(Of String) = _
My.Computer.Ports.SerialPortNames
For Each port As String In ports
Console.WriteLine(port)
Next
End Sub
End Module
这篇关于如何写串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文