RFID阅读器和VB.Net应用程序
嗨!我设法创建一个简单的应用程序来通过串口接收数据。现在我尝试使用我的RFID阅读器来显示其中检测到的RFID卡。但我收到的消息或字符串/数据只是"?"。
Hi! I've managed to create a simple application to received a data through serial port. And now i tried to use my RFID Reader to display the RFID card detected in it. But the message or string/data i received is only "?".
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().ToString()
MessageBox.Show(indata)
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button3.Click
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
com1.Open()
TextBox1.Text = com1.PortName
TextBox2.Text = com1.BaudRate
Button1.IsEnabled = False
Label1.Visibility = Windows.Visibility.Visible
Label2.Visibility = Windows.Visibility.Hidden
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
com1.Close()
Button1.IsEnabled = True
TextBox1.Text = String.Empty
TextBox2.Text = String.Empty
Button1.IsEnabled = True
Label1.Visibility = Windows.Visibility.Hidden
Label2.Visibility = Windows.Visibility.Visible
End Sub
Private Sub ListBox1_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
End Sub
End Class
我如何收到RFID卡的唯一ID?我认为唯一的id是12byte?
How can i received the unique id of the RFID card? i think the unique id is a 12byte?
你有RFID协议的链接吗? 如果你这样做,请发帖。
Do you have a link for the RFID protocol? Please post if you do.
'?'可能是因为RFID的字符串编码不是ASCII,是串口的默认值,但不知道只是一个协议猜测..
The '?' could be because the string encoding for the RFID is not ASCII, the default for the serial port, but without knowing the protocol that is just a guess..
对ReadExisting的调用不能保证读取协议定义的整个消息。
The call to ReadExisting is not guaranteed to read an entire message as defined by the protocol.