Hi I'm new to this site so please forgive me if this is the wrong forum.

I am developing a program which takes data from a reader (impinj) and displays results on a form.

The Datatable is filled on a separate thread to the main form, and as such I can only update the datagridview when the sub thread has completed. This results in a 5-10 second delay (dependant on read time) before the datagrid is updated.

I am at a loss as to how to update the datagrid in realtime (in Access it's easy, but cannot use access in this instance), any help would be appreciated

best regards


Please, post the codes you wrote first and then describe your problem. Forum members are here to help you.

Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Text
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Configuration
Imports System.Data.SqlClient
Imports Impinj.OctaneSdk
Imports Org.LLRP
Imports Org.LLRP.LTK
Imports Org.LLRP.LTK.LLRPV1.DataType
Imports Org.LLRP.LTK.LLRPV1.Impinj
Imports Impinj

Module SpeedwayReader

  Public tagsRead As New Dictionary(Of String, Tag)()
    Dim TID
    Dim RSSI

    Dim opIdUser As Integer, opIdTid As Integer
    Public Sub impinjscan(scan_table As DataTable, tagcount As Integer)


            AddHandler reader.TagsReported, AddressOf OnTagsReported

            Dim settings As Settings = reader.QueryDefaultSettings()

            Select Case My.Settings.ReaderMode
                Case ReaderMode.AutoSetDenseReader
                    settings.ReaderMode = ReaderMode.AutoSetDenseReader
                Case ReaderMode.AutoSetSingleReader
                    settings.ReaderMode = ReaderMode.AutoSetSingleReader
                Case ReaderMode.DenseReaderM4
                    settings.ReaderMode = ReaderMode.DenseReaderM4
                Case ReaderMode.DenseReaderM8
                    settings.ReaderMode = ReaderMode.DenseReaderM8
                Case ReaderMode.Hybrid
                    settings.ReaderMode = ReaderMode.Hybrid
                Case ReaderMode.MaxMiller
                    settings.ReaderMode = ReaderMode.MaxMiller
                Case ReaderMode.MaxThroughput
                    settings.ReaderMode = ReaderMode.MaxThroughput
            End Select

            Select Case My.Settings.SearchMode
                Case SearchMode.DualTarget
                    settings.SearchMode = SearchMode.DualTarget
                Case SearchMode.ReaderSelected
                    settings.SearchMode = SearchMode.ReaderSelected
                Case SearchMode.SingleTarget
                    settings.SearchMode = SearchMode.SingleTarget
                Case SearchMode.TagFocus
                    settings.SearchMode = SearchMode.TagFocus
            End Select

            settings.Report.IncludeFastId = My.Settings.IncludeFastID
            settings.Report.IncludeAntennaPortNumber = My.Settings.IncludeAntennaPortNumber
            settings.Session = My.Settings.Session
            settings.TagPopulationEstimate = My.Settings.TagPopulationEstimate

            settings.Antennas.GetAntenna(1).IsEnabled = My.Settings.Antenna1
            If My.Settings.Antenna1 = True Then
                settings.Antennas.GetAntenna(1).MaxTransmitPower = My.Settings.Ant1MaxTX
                If My.Settings.Ant1MaxTX = False Then
                    settings.Antennas.GetAntenna(1).TxPowerInDbm = My.Settings.Ant1TXPwr
                End If
                settings.Antennas.GetAntenna(1).MaxRxSensitivity = My.Settings.Ant1MaxRX
                If My.Settings.Ant1MaxRX = False Then
                    settings.Antennas.GetAntenna(1).RxSensitivityInDbm = My.Settings.Ant1RXSen
                End If
            End If

            settings.Antennas.GetAntenna(2).IsEnabled = My.Settings.Antenna2
            If My.Settings.Antenna2 = True Then
                settings.Antennas.GetAntenna(2).MaxTransmitPower = My.Settings.Ant2MaxTX
                If My.Settings.Ant2MaxTX = False Then
                    settings.Antennas.GetAntenna(2).TxPowerInDbm = My.Settings.Ant2TXPwr
                End If
                settings.Antennas.GetAntenna(2).MaxRxSensitivity = My.Settings.Ant2MaxRX
                If My.Settings.Ant2MaxRX = False Then
                    settings.Antennas.GetAntenna(2).RxSensitivityInDbm = My.Settings.Ant2RXSen
                End If
            End If

            settings.Report.IncludePeakRssi = True

            ' Send a tag report for every tag read.
            settings.Report.Mode = ReportMode.Individual

            ' Apply the newly modified settings.

            ' Start reading.


            'Wait while tags read



Catch e As OctaneSdkException
            ' Handle Octane SDK errors.
            Console.WriteLine("Octane SDK exception: {0}", e.Message)
        Catch e As Exception
            ' Handle other .NET errors.
            Console.WriteLine("Exception : {0}", e.Message)
        End Try
    End Sub


    ' This event handler will be called when tag 
    ' operations have been executed by the reader.

    Public Sub OnTagsReported(sender As ImpinjReader, report As TagReport)

        Dim dtNewRow As DataRow
        Dim TID
        Dim RSSI

        If Scan_table.Columns.Contains("Tagcode") Then
            Scan_table.Columns.Add("Tagcode", GetType(String))
        End If

        If Scan_table.Columns.Contains("TID") Then
            Scan_table.Columns.Add("TID", GetType(String))
        End If

        If Scan_table.Columns.Contains("RSSI") Then
            Scan_table.Columns.Add("RSSI", GetType(String))
        End If

        For Each tag As Tag In report

            TID = tag.Tid.ToHexString()
            RSSI = [String].Format("{0:0.00}", tag.PeakRssiInDbm)

            ' Add this tag to the list of tags we've read.
            dtNewRow = Scan_table.NewRow()
            dtNewRow.Item("Tagcode") = tag.Epc.ToHexString()
            dtNewRow.Item("TID") = TID
            dtNewRow.Item("RSSI") = RSSI




    End Sub
End Module

This works but requires sub to finish before updating the datagrid on the main form.

As an aside, this routine was originally set to provide TID, EPC & RSSI via console Writeline. in which case it ran real time (console data after each read)

But I cannot find an effective method to accomplish the same in a Datagrid.
All my research seems to require the sub to finish before a Datagrid can be refreshed from the datatable

What is contained in "reader.Start()"?

Reader.start() is a dll call. it responds via onTagsReported on a separate thread. if you use console writeline in Ontagsreported() in a console application you can show the values in tyhe console in realtime. However try to do that in a windows form, and you can't due to separate thread from Main Form thread. Hvae tried Invoke etc, but with no success, so looking for some help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.