我制作了一个MS Access DB表,并添加了Visual Basic以与Arduino一起使用。该表具有列(SerialNumber,Name,RFID_Number,Date / time,foodtype),我可以将arduino的RFID标签发送到Visual Basic Windows程序。 那么我想知道如何使用来自Arduino的串行数据来比较表中的数据,例如:如果RFID数字与日期/时间匹配,然后向arduino发送命令以打开Serve1来给狗吃东西。
该程序使三只狗= D每天按时为他们提供食物。
我的问题是如何比较表DB中的变量。
这是我在Visual Basic中的全部代码,现在我可以从Arduino接收RFID编号了。
Imports System
Imports System.IO.Ports
Public Class Form1
Dim comPORT As String
Dim receivedData As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'SpringdbDataSet.SpringData' table. You can move, or remove it, as needed.
Timer1.Enabled = False
comPORT = ""
For Each sp As String In My.Computer.Ports.SerialPortNames
comPort_ComboBox.Items.Add(sp)
Next
Me.SpringDataTableAdapter.Fill(Me.SpringdbDataSet.SpringData)
SerialNumberTextBox.Clear()
FullnameTextBox.Clear()
RFIDTagTextBox.Clear()
SpringSizeTextBox.Clear()
OperationTimeDateTimePicker.Value = Now
End Sub
Private Sub PreBnt_Click(sender As Object, e As EventArgs) Handles PreBnt.Click
SpringDataBindingSource.MovePrevious()
End Sub
Private Sub AddBnt_Click(sender As Object, e As EventArgs) Handles AddBnt.Click
SpringDataBindingSource.AddNew()
End Sub
Private Sub SaveBnt_Click(sender As Object, e As EventArgs) Handles SaveBnt.Click
Try
SpringDataBindingSource.EndEdit()
TableAdapterManager.UpdateAll(SpringdbDataSet)
MsgBox("Success")
Catch ex As Exception
MsgBox("Error occur, please recheck the fields and try again.")
End Try
End Sub
Private Sub DeleteBnt_Click(sender As Object, e As EventArgs) Handles DeleteBnt.Click
SpringDataBindingSource.RemoveCurrent()
TableAdapterManager.UpdateAll(SpringdbDataSet)
MsgBox("Current Record Deleted")
End Sub
Private Sub NextBnt_Click(sender As Object, e As EventArgs) Handles NextBnt.Click
SpringDataBindingSource.MoveNext()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
SpringDataBindingSource.Filter = "SerialNumber LIKE '%" & TextBox1.Text & "%'" & " OR Fullname LIKE '%" & TextBox1.Text & "%'"
End Sub
Private Sub comPort_ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comPort_ComboBox.SelectedIndexChanged
If (comPort_ComboBox.SelectedItem <> "") Then
comPORT = comPort_ComboBox.SelectedItem
End If
End Sub
Private Sub connect_BTN_Click(sender As Object, e As EventArgs) Handles connect_BTN.Click
If (connect_BTN.Text = "Connect") Then
If (comPORT <> "") Then
SerialPort1.Close()
SerialPort1.PortName = comPORT
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default 'very important!
SerialPort1.ReadTimeout = 10000
SerialPort1.Open()
connect_BTN.Text = "Dis-connect"
Timer1.Enabled = True
Timer_LBL.Text = "Timer: ON"
Else
MsgBox("Select a COM port first")
End If
Else
SerialPort1.Close()
connect_BTN.Text = "Connect"
Timer1.Enabled = False
Timer_LBL.Text = "Timer: OFF"
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
receivedData = ReceiveSerialData()
RFIDTagTextBox.Text &= receivedData
End Sub
Function ReceiveSerialData() As String
Dim Incoming As String
Try
Incoming = SerialPort1.ReadExisting()
If Incoming Is Nothing Then
Return "nothing" & vbCrLf
Else
Return Incoming
End If
Catch ex As TimeoutException
Return "Error: Serial Port read timed out."
End Try
End Function
Private Sub Timer_LBL_Click(sender As Object, e As EventArgs) Handles Timer_LBL.Click
End Sub
Private Sub RFIDTagTextBox_TextChanged(sender As Object, e As EventArgs) Handles RFIDTagTextBox.TextChanged
End Sub
End Class