CM3 libplcm3.so python wrapper for network access

Post your Linux discussions here
Post Reply
vince_smedley
Newbie
Posts: 0
Joined: Wed Mar 02, 2016 6:24 pm

CM3 libplcm3.so python wrapper for network access

Post by vince_smedley »

hi everyone,

I'm trying to access a CM3 data logger via Ethernet using a python wrapper around the libplcm3.so driver. I've installed the driver on Ubuntu 14.04, compiled the C code example, and seem to be able to access the CM3 remotely so I assume that everything is working fine.

There seems to be plenty of examples of python wrappers for the picoscope USB interface & so I've written a very simple test harness based on this code to interface to the logger.

Code: Select all

#!/usr/bin/env python
import ctypes
from ctypes import *

testlib = ctypes.CDLL('/opt/picoscope/lib/libplcm3.so')

def main():

    c_handle = c_int16()
    serial = None
    IPAddress = create_string_buffer("192.168.1.150")

    g_status = testlib.PLCM3OpenUnitViaIp(byref(c_handle), serial, IPAddress)

    print "PICO status: ", g_status

if __name__ == "__main__":
   main()
   exit(0)
However when I run this script I get the following error: terminate called after throwing an instance of 'char const*'
Aborted (core dumped)

The problem seems to be with the handle call, any one done this already or any suggestions as to what is happening here?

Cheers, V.

vince_smedley
Newbie
Posts: 0
Joined: Wed Mar 02, 2016 6:24 pm

Re: CM3 libplcm3.so python wrapper for network access

Post by vince_smedley »

Hi All,

I had an hour free this morning, so I had another play around with the code. It appears that I am able to connect to the CM3 via the USB connector using the following class method code.

Code: Select all

    def _openUnit(self, serial):
        c_handle = c_int16()
        if serial is not None:
            serialNullTermStr = create_string_buffer(serial)
        else:
            serialNullTermStr = None

        # Passing None is the same as passing NULL
        pico_status = self.lib.PLCM3OpenUnit(byref(c_handle), serialNullTermStr)
Or at least I received a return of zero from the library (PICO_OK), and an error code if I screwed around with the serial parameter. Don't know if this throws any light on my previous enquiry.

This seemed a positive step forward so for the time being I'll work on the USB interface and see if that goes anywhere. Ideally what I'd like to be able to do is have full access to the CM3 through a pure python interface so that I can analyse the data output through numpy.

BTW - I'm basing this code on the Github pico-python project code (thanks), do any of the picoscopes have an ethernet interface?

Hitesh

Re: CM3 libplcm3.so python wrapper for network access

Post by Hitesh »

Hi Vince,

There are a couple of things that you can try with connecting to the device via the Ethernet connection:
  • If the device is on a local network, try connecting using the Serial number parameter instead of the IP address.
  • Try appending the port number to the IP address e.g. if the configured port is 4000, pass the string "192.168.1.150:4000"
Does the device IP address and port appear if you query the PLCM3Enumerate() function with the communication type parameter corresponding to 0x00000002?

Which version of the driver are you using?

Regards,

vince_smedley
Newbie
Posts: 0
Joined: Wed Mar 02, 2016 6:24 pm

Re: CM3 libplcm3.so python wrapper for network access

Post by vince_smedley »

Hi Hitesh,

Thanks for getting back to me, really appreciate it. Using the PLCM3GetUnitInfo call I get the following information:

Code: Select all

PICO status:  0
PICO_DRIVER_VERSION:  PLCM3 Linux Driver, 1.0.5.11
PICO_USB_VERSION:  1.1
PICO_HARDWARE_VERSION:  1
PICO_VARIANT_INFO:  PLCM3 (USB)
PICO_BATCH_AND_SERIAL:  CX714/086
PICO_CAL_DATE:  14Jan16
PICO_KERNEL_DRIVER_VERSION:  1.0
I'm currently testing on my local network & I get the same results whether I input an IP address + port or the device serial number. I just tested again with the provided C code example and I'm getting the same error with a network connection. My mistake I thought I had tested this earlier & it had worked. I installed the linux driver via your PPA.

Thanks,

Vince

PS With the USB interface ATM everything seems to behave as expected.
PPS I realised after posting this that I'd used the wrong forum, hope that's not an inconvenience.

Hitesh

Re: CM3 libplcm3.so python wrapper for network access

Post by Hitesh »

Hi Vince,

I have been able to reproduce the issue using our C console application on a Linux PC and have reported this to our Development Team as it seems to affect the PLCM3Enumerate() function as well when attempting to search for Ethernet connected devices.

I hope to provide an update as soon as possible - please continue to develop your application using the USB connection until then.

Ps. I have moved the topic into the correct forum area :)

Regards,

vince_smedley
Newbie
Posts: 0
Joined: Wed Mar 02, 2016 6:24 pm

Re: CM3 libplcm3.so python wrapper for network access

Post by vince_smedley »

Hi Hitesh,

Thanks for the feedback, really appreciate your prompt response with following this up!

I had a little look at the software again this afternoon in USB mode. Acquisition doesn't seem to be working either. Up until now I hadn't tested with current probes, today I tested with a known reference current. The error I'm getting is:

Code: Select all

0x25 "PICO_NO_SAMPLES_AVAILABLE", "because a run has not been completed."
I made a few changes to the example C code and got the same problem there. As a reference I tested the data logger connected to a windows PC and I did appear to be getting an acquisition with the GUI application.

Regards,

Vince

Hitesh

Re: CM3 libplcm3.so python wrapper for network access

Post by Hitesh »

Hi Vince,

In the C code example, are you putting any kind of sleep after the call to PLCM3GetValue()?

It takes around 720ms for each reading to convert so your application will need to wait briefly until it takes a reading for the next channel.

If this does not resolve the issue, please post your C code here and I can take a look.

Regards,

Post Reply