Test and Measurement Forum

PT104A, VB.NET & UsbPt104GetUnitInfo

Post your .Net discussions here

PT104A, VB.NET & UsbPt104GetUnitInfo

Postby jlittlejohn » Wed Sep 09, 2015 8:32 pm

Hello.

I'm having some issues communicating with our PT-104A via VB.NET.

I get the correct PICO_STATUS back from the UsbPt104OpenUnit() call (0-"PICO_OK"), but when I try to call UsbPt104GetUnitInfo, it immediately exits the sub without even throwing an error.

I'm using the 32bit SDK as my end application will need to be compiled 32bit.

What am I doing wrong? I've tried passing the string as a ByRef StringBuilder and a ByRef String

Declarations are here:
Code: Select all
Module modPT104A
    Declare Function UsbPt104OpenUnit Lib "C:\Program Files (x86)\Pico Technology\SDK\lib\USBPT104.dll" _
        (ByRef handle As Int16, ByVal serial As UInt32) As PICO_STATUS

    Declare Function UsbPt104Enumerate Lib "C:\temp\USBPT104.dll" _
        (ByRef devices As String, ByRef stringLength As Integer, CommunicationType As Integer) As Integer

    Declare Function UsbPt104CloseUnit Lib "C:\Program Files (x86)\Pico Technology\SDK\lib\USBPT104.dll" _
        (ByVal handle As Int16) As PICO_STATUS

    Declare Function UsbPt104GetUnitInfo Lib "C:\Program Files (x86)\Pico Technology\SDK\lib\USBPT104.dll" _
        (ByVal handle As Int16, ByRef str As StringBuilder, ByVal stringLength As Int16, ByRef requiredSize As Int16, ByVal info As PICO_INFO) As PICO_STATUS

    Declare Function UsbPt104SetChannel Lib "C:\Program Files (x86)\Pico Technology\SDK\lib\USBPT104.dll" _
        (ByVal handle As Int16, ByVal channel As UInt32, ByVal measurementType As UInt32, ByVal noOfWires As UInt16) As PICO_STATUS

    Declare Function UsbPt104GetValue Lib "C:\Program Files (x86)\Pico Technology\SDK\lib\USBPT104.dll" _
        (ByVal handle As Int16, ByVal channel As UInt32, ByRef value As UInt32, ByVal filtered As Integer) As PICO_STATUS

    Enum PICO_STATUS As UInt32
        PICO_OK = &H0
        PICO_MAX_UNITS_OPENED = &H1
        PICO_MEMORY_FAIL = &H2
        PICO_NOT_FOUND = &H3
        PICO_FW_FAIL = &H4
        PICO_OPEN_OPERATION_IN_PROGRESS = &H5
        PICO_OPERATION_FAILED = &H6
        PICO_NOT_RESPONDING = &H7
        PICO_CONFIG_FAIL = &H8
        PICO_KERNEL_DRIVER_TOO_OLD = &H9
        PICO_EEPROM_CORRUPT = &HA
        PICO_OS_NOT_SUPPORTED = &HB
        PICO_INVALID_HANDLE = &HC
        PICO_INVALID_PARAMETER = &HD
        PICO_INVALID_TIMEBASE = &HE
        PICO_INVALID_VOLTAGE_RANGE = &HF
        PICO_INVALID_CHANNEL = &H10
        PICO_INVALID_TRIGGER_CHANNEL = &H11
        PICO_INVALID_CONDITION_CHANNEL = &H12
        PICO_NO_SIGNAL_GENERATOR = &H13
        PICO_STREAMING_FAILED = &H14
        PICO_BLOCK_MODE_FAILED = &H15
        PICO_NULL_PARAMETER = &H16
        PICO_ETS_MODE_SET = &H17
        PICO_DATA_NOT_AVAILABLE = &H18
        PICO_STRING_BUFFER_TO_SMALL = &H19
        PICO_ETS_NOT_SUPPORTED = &H1A
        PICO_AUTO_TRIGGER_TIME_TO_SHORT = &H1B
        PICO_BUFFER_STALL = &H1C
        PICO_TOO_MANY_SAMPLES = &H1D
        PICO_TOO_MANY_SEGMENTS = &H1E
        PICO_PULSE_WIDTH_QUALIFIER = &H1F
        PICO_DELAY = &H20
        PICO_SOURCE_DETAILS = &H21
        PICO_CONDITIONS = &H22
        PICO_USER_CALLBACK = &H23
        PICO_DEVICE_SAMPLING = &H24
        PICO_NO_SAMPLES_AVAILABLE = &H25
        PICO_SEGMENT_OUT_OF_RANGE = &H26
        PICO_BUSY = &H27
        PICO_STARTINDEX_INVALID = &H28
        PICO_INVALID_INFO = &H29
        PICO_INFO_UNAVAILABLE = &H2A
        PICO_INVALID_SAMPLE_INTERVAL = &H2B
        PICO_TRIGGER_ERROR = &H2C
        PICO_MEMORY = &H2D
        PICO_SIG_GEN_PARAM = &H2E
        PICO_SHOTS_SWEEPS_WARNING = &H2F
        PICO_SIGGEN_TRIGGER_SOURCE = &H30
        PICO_AUX_OUTPUT_CONFLICT = &H31
        PICO_AUX_OUTPUT_ETS_CONFLICT = &H32
        PICO_WARNING_EXT_THRESHOLD_CONFLICT = &H33
        PICO_WARNING_AUX_OUTPUT_CONFLICT = &H34
        PICO_SIGGEN_OUTPUT_OVER_VOLTAGE = &H35
        PICO_DELAY_NULL = &H36
        PICO_INVALID_BUFFER = &H37
        PICO_SIGGEN_OFFSET_VOLTAGE = &H38
        PICO_SIGGEN_PK_TO_PK = &H39
        PICO_CANCELLED = &H3A
        PICO_SEGMENT_NOT_USED = &H3B
        PICO_INVALID_CALL = &H3C
        PICO_GET_VALUES_INTERRUPTED = &H3D
        PICO_NOT_USED = &H3F
        PICO_INVALID_SAMPLERATIO = &H40
        PICO_INVALID_STATE = &H41
        PICO_NOT_ENOUGH_SEGMENTS = &H42
        PICO_DRIVER_FUNCTION = &H43
        PICO_RESERVED = &H44
        PICO_INVALID_COUPLING = &H45
        PICO_BUFFERS_NOT_SET = &H46
        PICO_RATIO_MODE_NOT_SUPPORTED = &H47
        PICO_RAPID_NOT_SUPPORT_AGGREGATION = &H48
        PICO_INVALID_TRIGGER_PROPERTY = &H49
        PICO_INTERFACE_NOT_CONNECTED = &H4A
        PICO_RESISTANCE_AND_PROBE_NOT_ALLOWED = &H4B
        PICO_POWER_FAILED = &H4C
        PICO_SIGGEN_WAVEFORM_SETUP_FAILED = &H4D
        PICO_FPGA_FAIL = &H4E
        PICO_POWER_MANAGER = &H4F
        PICO_INVALID_ANALOGUE_OFFSET = &H50
        PICO_PLL_LOCK_FAILED = &H51
        PICO_ANALOG_BOARD = &H52
        PICO_CONFIG_FAIL_AWG = &H53
        PICO_INITIALISE_FPGA = &H54
        PICO_EXTERNAL_FREQUENCY_INVALID = &H56
        PICO_CLOCK_CHANGE_ERROR = &H57
        PICO_TRIGGER_AND_EXTERNAL_CLOCK_CLASH = &H58
        PICO_PWQ_AND_EXTERNAL_CLOCK_CLASH = &H59
        PICO_UNABLE_TO_OPEN_SCALING_FILE = &H5A
        PICO_MEMORY_CLOCK_FREQUENCY = &H5B
        PICO_I2C_NOT_RESPONDING = &H5C
        PICO_NO_CAPTURES_AVAILABLE = &H5D
        PICO_NOT_USED_IN_THIS_CAPTURE_MODE = &H5E
        PICO_GET_DATA_ACTIVE = &H103
        PICO_IP_NETWORKED = &H104
        PICO_INVALID_IP_ADDRESS = &H105
        PICO_IPSOCKET_FAILED = &H106
        PICO_IPSOCKET_TIMEDOUT = &H107
        PICO_SETTINGS_FAILED = &H108
        PICO_NETWORK_FAILED = &H109
        PICO_WS2_32_DLL_NOT_LOADED = &H10A
        PICO_INVALID_IP_PORT = &H10B
        PICO_COUPLING_NOT_SUPPORTED = &H10C
        PICO_BANDWIDTH_NOT_SUPPORTED = &H10D
        PICO_INVALID_BANDWIDTH = &H10E
        PICO_AWG_NOT_SUPPORTED = &H10F
        PICO_ETS_NOT_RUNNING = &H110
        PICO_SIG_GEN_WHITENOISE_NOT_SUPPORTED = &H111
        PICO_SIG_GEN_WAVETYPE_NOT_SUPPORTED = &H112
        PICO_INVALID_DIGITAL_PORT = &H113
        PICO_INVALID_DIGITAL_CHANNEL = &H114
        PICO_INVALID_DIGITAL_TRIGGER_DIRECTION = &H115
        PICO_SIG_GEN_PRBS_NOT_SUPPORTED = &H116
        PICO_ETS_NOT_AVAILABLE_WITH_LOGIC_CHANNELS = &H117
        PICO_WARNING_REPEAT_VALUE = &H118
        PICO_POWER_SUPPLY_CONNECTED = &H119
        PICO_POWER_SUPPLY_NOT_CONNECTED = &H11A
        PICO_POWER_SUPPLY_REQUEST_INVALID = &H11B
        PICO_POWER_SUPPLY_UNDERVOLTAGE = &H11C
    End Enum

    Enum PICO_INFO As UInt32
        PICO_DRIVER_VERSION = 0
        PICO_USB_VERSION = 1
        PICO_HARDWARE_VERSION = 2
        PICO_VARIANT_INFO = 3
        PICO_BATCH_AND_SERIAL = 4
        PICO_CAL_DATE = 5
        PICO_KERNEL_DRIVER_VERSION = 6
        PICO_DIGITAL_HARDWARE_VERSION = 7
        PICO_ANALOGUE_HARDWARE_VERSION = 8
        PICO_FIRMWARE_VERSION_1 = 9
        PICO_FIRMWARE_VERSION_2 = 10
        PICO_MAC_ADDRESS = 11
    End Enum

End Module


and

Code: Select all
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim requiredSize As Int16
        Dim PT104A_status As PICO_STATUS
        Dim PT104A_handle As Int16
        Dim PT104A_serial As String = ""
        Dim S As New StringBuilder

        Try
            PT104A_status = UsbPt104OpenUnit(PT104A_handle, 0)
        Catch ex As Exception
            MsgBox(ex.Message, vbInformation)
        End Try

        If PT104A_status <> 0 Then
            MsgBox("Unit not opened, returned " & PT104A_status.ToString, vbOKOnly, "Error")
            Exit Sub
        End If
        Try
            PT104A_status = UsbPt104GetUnitInfo(PT104A_handle, S, 255S, requiredSize, 4) ' <-- Immediately exits sub after this function call
        Catch ex As Exception
            MsgBox(ex.Message, vbInformation)
        End Try

        MsgBox(S.ToString)
        PT104A_status = UsbPt104CloseUnit(PT104A_handle)
    End Sub


Any help is apprecaited!
jlittlejohn
Newbie
 
Posts: 0
Joined: Wed Sep 09, 2015 8:19 pm

Re: PT104A, VB.NET & UsbPt104GetUnitInfo

Postby Hitesh » Thu Sep 10, 2015 11:00 am

Hi jlittlejohn,

Try passing the String or StringBuilder object 'ByVal' rather than 'ByRef'.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: PT104A, VB.NET & UsbPt104GetUnitInfo

Postby jlittlejohn » Thu Sep 10, 2015 4:34 pm

That did it! Thank you!

I'm still kinda scratching my head here, since the function call is modifying the string, wouldn't you need to pass it byref?

Either way, thank you very much! It's working!
jlittlejohn
Newbie
 
Posts: 0
Joined: Wed Sep 09, 2015 8:19 pm

Re: PT104A, VB.NET & UsbPt104GetUnitInfo

Postby Hitesh » Fri Sep 11, 2015 8:01 am

Hi jlittlejohn,

This article on the Microsoft MSDN site should help explain this.

Please note that Pico Technology is not responsible for the content of third party sites.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests