1 Replies - 4490 Views - Last Post: 25 August 2012 - 11:57 PM Rate Topic: -----

#1 Sythez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-July 12

Receiving data from serial port then into array.

Posted 25 August 2012 - 11:08 PM

Hey guys, can you help me on my problem. The program (RFID) im working on can only read one data at a time from serial port. What i need is for it to read 5 data at a time.

Scenario is this, it will read 5 RFID tags at a time. Then the value of the first tag will be put into textbox1, then the second will be put into textbox 2, and so on until all tags are read.

Here is the code of the program wherein it reads the data it receives.

    Private Sub serialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Dim rx As Integer
        rx = SerialPort1.BytesToRead
        Dim comBuff As Byte() = New Byte(rx - 1) {}
        SerialPort1.Read(comBuff, 0, rx)
        txtRxData.Invoke(New DisplayDelegate(AddressOf DisplayCharacter), New Object() {BytetoHex(comBuff)})
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Receiving data from serial port then into array.

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Receiving data from serial port then into array.

Posted 25 August 2012 - 11:57 PM

View PostSythez, on 25 August 2012 - 11:08 PM, said:

Hey guys, can you help me on my problem. The program (RFID) im working on can only read one data at a time from serial port. What i need is for it to read 5 data at a time.

Scenario is this, it will read 5 RFID tags at a time. Then the value of the first tag will be put into textbox1, then the second will be put into textbox 2, and so on until all tags are read.

Here is the code of the program wherein it reads the data it receives.

    Private Sub serialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Dim rx As Integer
        rx = SerialPort1.BytesToRead
        Dim comBuff As Byte() = New Byte(rx - 1) {}
        SerialPort1.Read(comBuff, 0, rx)
        txtRxData.Invoke(New DisplayDelegate(AddressOf DisplayCharacter), New Object() {BytetoHex(comBuff)})
    End Sub


As the code you pasted is clearly from here, I'd like to know if you understand what the code does at each line of it? What the method receives, and why (what triggers it)?

If you do understand it, than you might fill the desired data to a collection of some type, or maybe custom structure/class, and code a public event that it triggers when it gets all 5 properties filled. Than a method, that will listen to this event could populate your text fields...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1