我设法使用vb.net在VS2010中创建一个简单的应用程序,以便从COM2接收数据。
我的RFID阅读器通过RS232连接。当我的读卡器检测到我的被动或有源RFID标签时,我收到的数据只是"?"。
我是否需要转换标签的数据?
这是我到目前为止的代码。
Imports System.IO.Ports
Class MainWindow
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Label1.Visibility = Windows.Visibility.Hidden
Label2.Visibility = Windows.Visibility.Hidden
TextBox1.Text = com1.PortName
TextBox2.Text = com1.BaudRate
Button1.IsEnabled = False
Try
With com1
.DtrEnable = True
.RtsEnable = True
.Handshake = IO.Ports.Handshake.None
AddHandler .DataReceived, AddressOf DataReceivedHandler
End With
com1.Open()
If com1.IsOpen = True Then
Label1.Visibility = Windows.Visibility.Visible
End If
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Shared Sub DataReceivedHandler(sender As Object, e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Dim indata As String = sp.ReadExisting()
MessageBox.Show(indata)
End Sub