Results 1 to 2 of 2

Thread: [RESOLVED] How to retrieve value from RFID card.

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Resolved [RESOLVED] How to retrieve value from RFID card.

    Hi all,

    I'm using RFID Reader to read the data from RFID Card.

    The code using as below





    vb Code:
    1. Dim WithEvents serialPort As New IO.Ports.SerialPort
    2.     Public Event onComm(ByVal sender As Object, ByVal e As System.EventArgs)
    3.     Private psInput As String
    4.  
    5.  
    6.  Private Sub DataReceived( _
    7.    ByVal sender As Object, _
    8.    ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
    9.    Handles serialPort.DataReceived
    10.         Dim strv As String
    11.         strv = serialPort.ReadExisting
    12.         If strv <> "" Then
    13.             psInput = strv
    14.             Session("InputRFID") = psInput
    15.            
    16.         End If
    17.     End Sub
    18.  
    19. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    20.  
    21.         If Me.IsPostBack = False Then
    22.             With serialPort
    23.                 .PortName = "COM" & "4"
    24.                 .BaudRate = 9600
    25.                 .Parity = IO.Ports.Parity.None
    26.                 .DataBits = 8
    27.                 .StopBits = IO.Ports.StopBits.One
    28.                 .ReceivedBytesThreshold = 11
    29.                 Try
    30.                     If .IsOpen = False Then .Open()
    31.                 Catch ex As Exception
    32.  
    33.                 End Try
    34.  
    35.  
    36.             End With
    37.         End If
    38.  
    39.     End Sub

    Now My Problem is when the card was scanned, It will firing DataReceived event. I successfully get the data and try to display data on a textbox.

    The page do not postback after DataReceived event so the textbox cannot display.

    How do I accomplish it ?

    Thanks in advance
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to retrieve value from RFID card.

    vb Code:
    1. Public Shared Sub RegisterClientScriptForRFIDObject(ByVal page As Page)
    2.        
    3.  
    4.         Dim csInitRFID As [String] = "InitRFID"
    5.         Dim csWaitRFIDEvent As [String] = "WaitRFIDEvent"
    6.  
    7.         Dim cstype As Type = page.[GetType]()
    8.         Dim cs As ClientScriptManager = page.ClientScript
    9.         Dim sb As System.Text.StringBuilder = Nothing
    10.  
    11.         If Not cs.IsStartupScriptRegistered(cstype, csInitRFID) Then
    12.             sb = New System.Text.StringBuilder()
    13.             sb.AppendLine("var loaded;")
    14.             sb.AppendLine("var rf40 = new ActiveXObject('IDLinkLibrary.CardReader');")
    15.             sb.AppendLine("document.body.onload = InitPort;")
    16.             sb.AppendLine("document.body.onunload = ClosePort;")
    17.             sb.AppendLine("function ClosePort()")
    18.             sb.AppendLine("{")
    19.             sb.AppendLine(" if (rf40 != null && loaded) rf40.ClosePort();")
    20.             sb.AppendLine("}")
    21.             sb.AppendLine("function InitPort()")
    22.             sb.AppendLine("{")
    23.             sb.AppendLine(" loaded = false;")
    24.             sb.AppendLine(" if (rf40 == null) rf40 = new ActiveXObject('IDLinkLibrary.CardReader');")
    25.             sb.AppendLine(" port = rf40.GetCommPort();")
    26.             sb.AppendLine(" if (port.indexOf('Err') > -1)")
    27.             sb.AppendLine(" {")
    28.             sb.AppendLine(" port = window.prompt('Please fill in serial port for RFID Reader:', '');")
    29.             sb.AppendLine(" if (port == null) port = '';")
    30.             sb.AppendLine(" }")
    31.             sb.AppendLine(" if (rf40.OpenPort(port))")
    32.             sb.AppendLine(" {")
    33.             sb.AppendLine(" loaded = true;")
    34.             sb.AppendLine(" }")
    35.             sb.AppendLine("}")
    36.             cs.RegisterStartupScript(cstype, csInitRFID, sb.ToString(), True)
    37.         End If
    38.         If Not cs.IsStartupScriptRegistered(cstype, csWaitRFIDEvent) Then
    39.             sb = New System.Text.StringBuilder()
    40.             sb.AppendLine("<script type='text/jscript' language='jscript'>")
    41.             sb.AppendLine(" function rf40::OnReadCard(cardSN)")
    42.             sb.AppendLine(" {")
    43.             sb.AppendLine(" if (loaded)")
    44.             sb.AppendLine(" {")
    45.             sb.AppendLine(" __doPostBack('__Page', cardSN);")
    46.             sb.AppendLine(" }")
    47.             sb.AppendLine(" }")
    48.             sb.AppendLine(" function rf40::OnReadError(errorMessage)")
    49.             sb.AppendLine(" {")
    50.             sb.AppendLine(" if (loaded)")
    51.             sb.AppendLine(" {")
    52.             sb.AppendLine(" alert('Please click OK then scan the card again.');")
    53.             sb.AppendLine(" }")
    54.             sb.AppendLine(" }")
    55.             sb.AppendLine("</script>")
    56.             cs.RegisterStartupScript(cstype, csWaitRFIDEvent, sb.ToString(), False)
    57.         End If
    58.     End Sub
    59.  
    60.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    61.         RegisterClientScriptForRFIDObject(Me)
    62.         If Me.IsPostBack = true Then
    63.             Me.txtRName.Text = Request("__EVENTARGUMENT")
    64.         End If
    65.  
    66.     End Sub

    Problem solved by using source code above
    Thanks for reading.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width