Test and Measurement Forum

Using excel to log multiple channels from Picolog1012

Post your VB and VBA discussions here

Using excel to log multiple channels from Picolog1012

Postby GJAP » Mon Nov 25, 2013 5:26 pm

Hi there,

I am trying to log a few channels using the Pico 1012 logger.

I have downloaded the example script which allows logging of two channels but I am struggling to expand this to more (nine).

I have adjusted the script so that the user can change the logging interval and time without VBA knowledge but unfortunately my VBA knowledge is incredibly basic so I can't get further!

Code: Select all
' Excel Macro for the PicoLog 1000 series
' Pico Technology 2009

Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Integer) As Long
Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Integer) As Long
Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByVal handle As Integer, ByVal S As String, ByVal lth As Integer, ByRef requiredSize As Integer, ByVal info As Integer) As Integer
Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Integer, ByVal enabled As Integer, ByVal enable_auto As Integer, ByVal auto_ms As Integer, ByVal channel As Integer, ByVal dir As Integer, ByVal threshold As Integer, ByVal hysterisis As Integer, ByVal delay As Single) As Integer
Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Integer, ByRef us_for_block As Long, ByVal ideal_no_of_samples As Long, channels As Integer, ByVal No_of_channels As Integer) As Long
Declare Function pl1000GetValues Lib "pl1000.dll" (ByVal handle As Integer, ByRef values As Integer, ByRef no_of_values As Long, ByRef overflow As Integer, ByRef triggerIndex As Long) As Long
Declare Function pl1000Run Lib "pl1000.dll" (ByVal handle As Integer, ByVal no_of_values As Long, ByVal method As Integer) As Integer
Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Integer, ByRef ready As Integer) As Long
Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Integer, ByRef maxValue As Integer) As Long

Dim status As Long
Dim handle As Integer
Dim values(200) As Integer
Dim channels(22) As Integer
Dim nValues As Long
Dim ok As Integer
Dim ready As Integer
Dim requiredSize As Integer
Dim S As String * 255
Public port As Integer
Public product As Integer
Dim maxValue As Integer

Function adc_to_mv(value As Integer) As Integer
  adc_to_mv = value / maxValue * 2500
End Function

Sub GetPl1000()

' Open device
   status = pl1000OpenUnit(handle)
   opened = handle <> 0
   
If opened Then

  'Get the maximum ADC value for this variant
  status = pl1000MaxValue(handle, maxValue)

' Get the unit information
  Cells(9, "p").value = "Unit opened"
  SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 3)
  Cells(10, "P").value = S
  SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 4)
  Cells(11, "P").value = S
  SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 1)
  Cells(12, "P").value = S
 
  ' No Trigger
  Call pl1000SetTrigger(handle, False, 0, 0, 0, 0, 0, 0, 0)

  ' Say that we want to take [W3] readings in [W4] s
  ' from channels 1 and 2
   
    'Set number of samples to read
    Dim samplenum As Integer
    samplenum = Worksheets("Sheet1").Range("W3").value 'Reads number of samples from W3

    nValues = samplenum
    channels(0) = 1
    channels(1) = 2
    channels(2) = 3
    channels(3) = 4
    channels(4) = 5
    channels(5) = 6
    channels(6) = 7
    channels(7) = 8
    channels(8) = 9
   
   
    'Set test length
    Dim sampleInterval As Long
    Dim microsecs_for_block As Long
   
    Dim testlength As Integer
    testlength = Worksheets("Sheet1").Range("$w$4").value
    microsecs_for_block = testlength * 1000000
    status = pl1000SetInterval(handle, microsecs_for_block, nValues, channels(0), 2)''<changing the 2 to a nine really made the data go odd>
       
    status = pl1000Run(handle, nValues, 0)
   
    ready = 0
    Do While ready = 0
        status = pl1000Ready(handle, ready)
    Loop

  ' Get a block of 100 readings...
  ' we can call this routine repeatedly
  ' to get more blocks with the same settings
  Dim triggerIndex As Long
  Dim overflow As Integer
  status = pl1000GetValues(handle, values(0), nValues, overflow, triggerIndex)
 
  ' Copy the data into the spreadsheet
  For i = 0 To nValues - 1
     Cells(i + 4, "A").value = adc_to_mv(values(2 * i))
     Cells(i + 4, "B").value = adc_to_mv(values(2 * i + 1)) '''<I am not sure what this command is doing so I have tried simply expanding it into other columns. The sheet does add data into cells C-E but it appears to be duplicate data from A and B>
     Cells(i + 4, "C").value = adc_to_mv(values(2 * i + 2))
     Cells(i + 4, "D").value = adc_to_mv(values(2 * i + 3))
     Cells(i + 4, "E").value = adc_to_mv(values(2 * i + 4))
  Next i

  ' Close the unit when finished to drop the driver
  Call pl1000CloseUnit(handle)
 
Else
   MsgBox "Unable to open device", vbCritical
End If
 
End Sub


Can anyone shed any insight?

My file is here: https://www.dropbox.com/sh/syxdva59kqgpq4a/iDVFdXVshJ
Is this something that anyone who knows anything about VBA could solve, or do you have to have picolog knowledge too. Obviously if nothing else, on needs a picologger to test the code.
GJAP
Newbie
 
Posts: 0
Joined: Mon Nov 25, 2013 5:14 pm

Re: Using excel to log multiple channels from Picolog1012

Postby Hitesh » Wed Nov 27, 2013 5:28 pm

Hi GJAP,

An updated SDK is available but but is yet to be uploaded to the website.

You may require the updated dll in there as there have been some fixes to the driver. Could you please e-mail support@picotech.com and I can make this SDK available to you.

Best wishes,
Hitesh

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

Re: Using excel to log multiple channels from Picolog1012

Postby Hitesh » Mon Dec 02, 2013 4:18 pm

Hi,

This has been resolved via our Helpdesk e-mail system.

A few key points to note when using the PicoLog 1000 API and VBA:

  • The number of samples passed to the pl1000SetInterval and pl1000Run functions should be the TOTAL number of samples.
  • The number of samples requested by the call to pl1000GetValues should be the number of samples PER channel.
  • When specifying the number of channels to the pl1000SetInterval function, the array should consist of only the channels to enable, and not be longer than the number of channels on the device i.e.

    Code: Select all
    channels(0) = 1 ' Channel 1
    channels(1) = 2
    channels(2) = 3

  • In VBA, the size of an array is given as the length - 1 i.e.

    Code: Select all
    Dim channels(2) As Integer ' An array of 3 elements

Thanks,
Hitesh

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

Re: Using excel to log multiple channels from Picolog1012

Postby GJAP » Wed Dec 04, 2013 12:57 pm

Thanks hitesh,

This file now works and can be accessed here.

What I'm wondering now is whether I can add a timestamp and prevent excel "not responding" when it gathers data.
GJAP
Newbie
 
Posts: 0
Joined: Mon Nov 25, 2013 5:14 pm

Re: Using excel to log multiple channels from Picolog1012

Postby Hitesh » Wed Dec 04, 2013 3:52 pm

Hi GJAP,

Timestamping can be calculated based on the sampling interval being used - try using the microseconds per block parameter from the pl1000SetInterval function and the total number of samples to calculate the interval.

With regards to MS Excel not responding, it might be busy collecting the data.

Hope this helps.
Hitesh

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

Re: Using excel to log multiple channels from Picolog1012

Postby GJAP » Thu Dec 05, 2013 2:25 pm

Yes, excel is indeed busy collecting data when it is not responding. It's a shame but I presume it's unavoidable.

I have used the logging interval to place timestamps when desired.

You can see the new and hopefully final version of the spreadsheet here. Hopefully it will be of use to someone else too.

picologging spreadsheet.xlsm
GJAP
Newbie
 
Posts: 0
Joined: Mon Nov 25, 2013 5:14 pm


Return to VB and VBA (Excel, Access)

Who is online

Users browsing this forum: No registered users and 0 guests