Jump to content
Sign in to follow this  
mon678

Coding Vb.net Utk Rfid

Recommended Posts

tolong sy kawan2 perlukan utk simple coding utk baca S/N drpd RFID reader dan masuk ke dalam database.

p/s : using visual studio 2008 and SQL server 2005

Share this post


Link to post
Share on other sites
interface -> [img]http://s12.postimage.org/oa93sybnt/Untitled.jpg[/img]


scan RFID card utk login...

COM port x slh aku Port 8 rasenya nnti aku cek blik

Share this post


Link to post
Share on other sites
Pakai RS232 la ni?takat nak baca COM dari mana2 port xde hal..cuma data structure tu kena tahu dulu macam mana...header brape byte, body brape byte..ada brape section..then brape dia punya baud rate..

Share this post


Link to post
Share on other sites
[quote name='NeoLogy' timestamp='1330621589' post='1079787']
Pakai RS232 la ni?takat nak baca COM dari mana2 port xde hal..cuma data structure tu kena tahu dulu macam mana...header brape byte, body brape byte..ada brape section..then brape dia punya baud rate..
[/quote]

aku dh buat coding RFID utk detect card dri com yg di pilih tp setelah detect card tu ada error "invoke"....
coding nya adalah seperti berikut ->
Public Class Form1
Dim WithEvents myComPort As New System.IO.Ports.SerialPort
Dim data As String
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ComboBox1.Enabled = True
Button2.Enabled = False
Button1.Enabled = True
RadioButton1.Enabled = False
RadioButton2.Checked = True
myComPort.Close()
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not ComboBox1.SelectedItem Is Nothing Then
If Not myComPort.IsOpen Then
Try
myComPort.BaudRate = 19200
myComPort.PortName = ComboBox1.SelectedItem
myComPort.Parity = IO.Ports.Parity.None
myComPort.DataBits = 8
myComPort.StopBits = IO.Ports.StopBits.One
myComPort.Handshake = IO.Ports.Handshake.None
myComPort.ReadTimeout = 3000
myComPort.ReceivedBytesThreshold = 1
myComPort.DtrEnable = True

myComPort.Open()

ComboBox1.Enabled = False
Button1.Enabled = False
Button2.Enabled = True
RadioButton1.Enabled = True
RadioButton1.Checked = True

Catch ex As Exception
MsgBox("Error Opening COM Port", MsgBoxStyle.Critical)
End Try
End If
Else
MsgBox("Select a valid COM Port", MsgBoxStyle.Information)
End If
End Sub

Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each portName As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(portName)
Next
' CheckBox1.Checked = True
If Not myComPort.IsOpen Then
Button2.Enabled = False
ComboBox1.Text = ComboBox1.Items(0)
RadioButton1.Enabled = False
RadioButton2.Checked = True
Else
Button1.Enabled = False
ComboBox1.Text = myComPort.PortName
RadioButton2.Checked = True
End If
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
myComPort.DtrEnable = True
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
myComPort.DtrEnable = False
End Sub
Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles myComPort.DataReceived
TextBox1.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
myComPort.Close()
End Sub
Public Delegate Sub myDelegate()
Public Sub updateTextBox()

data = data + myComPort.ReadExisting()
If Len(data) = 4 Then
TextBox1.Text = TextBox1.Text + Microsoft.VisualBasic.Mid(data, 1, 4)
myComPort.DtrEnable = False
RadioButton1.Enabled = False
RadioButton2.Checked = True



'If CheckBox1.Checked = True Then
'Beep()
'End If

Dim timeOut As DateTimeOffset = Now.AddMilliseconds(1500)
Do
Application.DoEvents()
Loop Until Now > timeOut
data = myComPort.ReadExisting()
myComPort.DiscardInBuffer()
data = ""
myComPort.DtrEnable = True
RadioButton1.Enabled = True
RadioButton1.Checked = True



Me.Close()
'Me.Hide()


End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = ""
End Sub




End Class

interfacenya begini -> [img]http://img851.imageshack.us/img851/5724/68796298.jpg[/img]

Share this post


Link to post
Share on other sites
salam mon678, sample code yg u download tu mula2 nampak macam tak working(value yg kuar cth "?").
So setelah digodek2 beberapa kali dapatlah jgak value dari card tu. data = data.Replace(ch, "") tu untuk replace character yg tak berkenaan. selamat mencuba.


myComPort.BaudRate = 9600

..........................

Public Sub updateTextBox()

Thread.Sleep(100)
data = myComPort.ReadExisting

Dim ch = Mid(data, 1, 1)
data = data.Replace(ch, "")
ch = Mid(data, 11, 11)
data = data.Replace(ch, "")

'If Len(data) = 12 Then
TextBox1.Text = TextBox1.Text + data & vbNewLine 'TextBox1.Text + Microsoft.VisualBasic.Mid(data, 2, 11) & vbLf
'myComPort.DtrEnable = False
RadioButton1.Enabled = False
RadioButton2.Checked = True

If CheckBox1.Checked = True Then
Beep()
End If

Dim timeOut As DateTimeOffset = Now.AddMilliseconds(500)
Do
Application.DoEvents()
Loop Until Now > timeOut
'data = myComPort.ReadExisting()
'myComPort.DiscardInBuffer()
data = ""
myComPort.DtrEnable = True
RadioButton1.Enabled = True
RadioButton1.Checked = True

'End If
End Sub Edited by halim56

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...