none
Code Scaner - CallBack function with No Completed Event RRS feed

  • Question

  • Code scanner has a Callback function will return scanned data for each callback in a string of max. 64 alphanumeric characters.  If the scanned data is more than 64 characters then Callback will return more than one string. The scanned data length is varies up to 1000 characters.  I would to use Timer to trigger an event whenever the Callback stop call NewData function but have not figured out yet.  Please advise.

    DimonNewDataCallback AsCodeUtil.OnNewDataCallback= NewCodeUtil.OnNewDataCallback(AddressOfNewData)

    PublicFunctionNewData(ByValhandle AsIntPtr, ByValdata AsIntPtr, ByVallength AsInteger) AsInt32

    End Function

    Thanks.

    Thanh

    Wednesday, February 7, 2018 12:41 PM

All replies

  • If the scanned data is more than 64 characters then Callback will return more than one string.

    If the function returns more than one string then you problem is converting multiple strings to a readable format, but that seems unlikely.   If you mean that the function is called more then once then you need to append each new string to a buffer and only process the buffer when the last string has been received.  This is usually indicated by a return value less then 64.   But a timer is not needed - the event will fire each time that a new string is available to be appended.  There is no additional event that is called when the last string is received.  You can define your own event to fire when the last string is received.

        Public Event onNewDataEnd(ByVal Data As String)
    
        Dim onNewDataCallback As CodeUtil.OnNewDataCallback = NewCodeUtil.OnNewDataCallback(AddressOf NewData)
    
        Public Function NewData(ByVal handle As IntPtr, ByVal data As IntPtr, ByVal length As Integer) As Int32
            Static Buffer As String = ""
            Buffer &= PtrToStringUni(data, length)
            If length < 64 Then
                RaiseEvent onNewDataEnd(Buffer)
                Buffer = ""
            End If
        End Function
    
        Public Sub NewDataEnd(ThisData As String) Handles Me.onNewDataEnd
            'Process the data
        End Sub
    
    
    The detail dpends on the description for OnNewDataCallback.

    Wednesday, February 7, 2018 8:42 PM