Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Access to UsbSession GetAttribute? Visual basic 2010 .NET 4.0

Solved!
Go to solution

Hello,

 

I'm trying to read the data of my device after the device is interrupted (triggered from external source) in visual basic 2010 .NET 4.0

 

 

Imports NationalInstruments.VisaNS
Imports Microsoft.VisualBasic


Module Module1
    Private objUsbSession As UsbSession
    Dim DeviceNotAvailable As Boolean = True

    Sub Main()
        Dim resources() As String = ResourceManager.GetLocalManager().FindResources("?*")
        Dim device As String

        For Each device In resources
            'first found device is used
            Dim deviceDetected As Boolean = device.Contains("0xsome value")
            If deviceDetected Then
                'open usb session
                objUsbSession = CType(ResourceManager.GetLocalManager().Open(device), UsbSession)
                'print to let user now wich device is used
                Console.WriteLine(objUsbSession.LastStatus.ToString)
                Console.WriteLine(objUsbSession.ResourceName)
                'set DeviceNotAvailable because we have found one
                DeviceNotAvailable = False
                Exit For
            End If
        Next
        'check is a device was found
        If DeviceNotAvailable Then
            Console.WriteLine("No device detected")
        Else
            ' enable the usb interrupt event
            objUsbSession.EnableEvent(UsbSessionEventType.UsbInterrupt, EventMechanism.Queue)

            Dim i As Integer = 0
            While i < 10
                i += 1
                ' wait on event to be true
                objUsbSession.WaitOnEvent(UsbSessionEventType.UsbInterrupt, 5000)

                'read data from the device

                  here i need to but it is not present 
objUsbSession.GetAttribute????????? End While 'close the session objUsbSession.Dispose() End If 'wait for user to close the application Console.WriteLine("Press any key to exit the application.") Console.ReadKey() End Sub End Module

 

so everything works but now I must read the data back (the interrupt is seen)

 

I manage to do it in Labview and VC++and C++

VC++/C++

    viGetAttribute(IntHandle, VI_ATTR_USB_RECV_INTR_DATA, databuffer);

 

to retrieve the data but this command i cant acces it?

 

can anyone help me to solve this?

 

best regard

 

 

 

 

 

0 Kudos
Message 1 of 2
(3,755 Views)
Solution
Accepted by topic author Jimmy84

Solved it

 

sorry but the language VB I'm not familiar with.

 

but the sullution is as follow.

 

code was:

' wait on event to be true
objUsbSession.WaitOnEvent(UsbSessionEventType.UsbInterrupt, 5000)

'read data from the device

here i need to but it is not present
objUsbSession.GetAttribute?????????

 

code must be

'databuffer is returned in UsbSessionInterruptEventArgs
Dim ResultData As UsbSessionInterruptEventArgs
'wait on event to be true and return result in ResultData
ResultData = objUsbSession.WaitOnEvent(UsbSessionEventType.UsbInterrupt, 5000)

'result is a string U8 format and is located in ResultData.Buffer
Dim StringDataBuffer As String
Dim enc As New System.Text.UTF8Encoding
StringDataBuffer = enc.GetString(ResultData.DataBuffer)

 

The data is returned in UsbSessionInterruptEventArgs.Buffer

and is a byte array.

so to show it as a string result U must encode it to UTF8

 

 

 

 

 

0 Kudos
Message 2 of 2
(3,742 Views)