colinoflynn / pico-python

PicoScope Python Interface
Other
101 stars 80 forks source link

the picoscope does not work #162

Open Zorro9999 opened 4 years ago

Zorro9999 commented 4 years ago

Does not open picoscope Good day . I'm trying to connect with an oscilloscope, for example, with this example:

"""
Shows a demo of use to use the enumerate devices feature.

By: Mark Harfouche

"""
from __future__ import division
import picoscope
import imp
picoscope = imp.reload(picoscope)
from picoscope import ps3000a
ps3000a = imp.reload(ps3000a)
import time

if __name__ == "__main__":

    SERIAL_NUM = 'AT635/230'
    ps = ps3000a.PS3000a(SERIAL_NUM)
    #ps = ps3000a.PS3000a( )

    allSerialNumbers = ps.enumerateUnits()

    print("Found the following device serial numbers: ")
    for serial in allSerialNumbers:
        print(serial + "\n")

    # you can open devices by serial number
    serial = allSerialNumbers[0]
    ps = ps3000a.PS3000a(serial)

    # do stuff
    ps.flashLed(10)
    time.sleep(4.0)  # the above flash takes roughly 4 seconds 
    ps.close()

And getting an error:

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\ctypes\__init__.py in create_string_buffer(init, size)
     61         buf = buftype()
     62         return buf
---> 63     raise TypeError(init)
     64 
     65 def c_buffer(init, size=None):

TypeError: AT635/230

Using SERIAL_NUM = "AT635 / 230\x00" It produces the same error as described above. When you try to set data in a picoscope without using a serial number, an error such as a picoscope is not detected. This has already been considered in the comments in this thread.

What could be the problem ?

hmaarrfk commented 4 years ago

The script above is trying to connect to a picoscope twice.

The first time with the serial number you provide.

The second time a few lines down.

That example is better used by running things line by line. Interactively

Zorro9999 commented 4 years ago
from __future__ import division
import picoscope
import imp
picoscope = imp.reload(picoscope)
from picoscope import ps3000a
ps3000a = imp.reload(ps3000a)
import time

if __name__ == "__main__":

    SERIAL_NUM = 'AT635/230\x00'
    ps = ps3000a.PS3000a(SERIAL_NUM)
    #ps = ps3000a.PS3000a( )

    #allSerialNumbers = ps.enumerateUnits()

    #print("Found the following device serial numbers: ")
    #for serial in allSerialNumbers:
        #print(serial + "\n")

    # you can open devices by serial number
    #serial = allSerialNumbers[0]
    #ps = ps3000a.PS3000a(serial)

    # do stuff
    ps.flashLed(10)
    time.sleep(4.0)  # the above flash takes roughly 4 seconds 
    ps.close()

When commenting out the lines of the second connection, the dummy still falls out with an error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-1ab1e46cfffe> in <module>
     16 
     17     SERIAL_NUM = 'AT635/230\x00'
---> 18     ps = ps3000a.PS3000a(SERIAL_NUM)
     19     #ps = ps3000a.PS3000a( )
     20 

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\ps3000a.py in __init__(self, serialNumber, connect)
    147         self.resolution = self.ADC_RESOLUTIONS["8"]
    148 
--> 149         super(PS3000a, self).__init__(serialNumber, connect)
    150 
    151     def _lowLevelOpenUnit(self, sn):

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\picobase.py in __init__(self, serialNumber, connect)
    145 
    146         if connect is True:
--> 147             self.open(serialNumber)
    148 
    149     def getUnitInfo(self, info):

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\picobase.py in open(self, serialNumber)
    855     def open(self, serialNumber=None):
    856         """Open the scope, using a serialNumber if given."""
--> 857         self._lowLevelOpenUnit(serialNumber)
    858 
    859     def openUnitAsync(self, serialNumber=None):

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\ps3000a.py in _lowLevelOpenUnit(self, sn)
    152         c_handle = c_int16()
    153         if sn is not None:
--> 154             serialNullTermStr = create_string_buffer(str(sn))
    155         else:
    156             serialNullTermStr = None

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\ctypes\__init__.py in create_string_buffer(init, size)
     61         buf = buftype()
     62         return buf
---> 63     raise TypeError(init)
     64 
     65 def c_buffer(init, size=None):

TypeError: AT635/230
Zorro9999 commented 4 years ago

The most interesting thing is if you use functions like ps.flashLed (10) then the picoscope fulfills this function correctly, but when specifying, let's say

 ps.setChannel (channel = "A", coupling = "DC", VRange = 1) 

then there is an error that the picoscope is not available. the

print function (ps.getAllUnitInfo () + "\ n") 

works correctly and returns:


DriverVersion                 : 2.1.17.1457
USBVersion                    : 2.0
HardwareVersion               : 1
VariantInfo                   : 3206B
BatchAndSerial                : AT635/230
CalDate                       : 24Oct11
KernelVersion                 : 1.0
DigitalHardwareVersion        : 1
AnalogueHardwareVersion       : 1
PicoFirmwareVersion1          : 1.3.3.0
PicoFirmwareVersion2          : 1.0.16.0
hmaarrfk commented 4 years ago

Are you running this in a notebook. Or Spyder?

Could you start fresh ensure all other python kernels are closed

Zorro9999 commented 4 years ago

Yes, the launch in jupiter python is true. I have restarted many times. It produces exactly such errors. operating system 64 bit, installed from the picoscope from the site. By the way, there is an error in the code: ps3000a.py. The value of paragraph 123 AWGMaxVa = 32767 is not yet completed

Here is another example similar to the one discussed earlier, where there is an error that the picoscope was not detected. Example

from __future__ import division
from picoscope import ps3000a

import time
if __name__ == "__main__":
    serialNumber= "AT635/230\x00"
    ps = ps3000a.PS3000a()
    #ps = ps3000a.PS3000a()

   # serialNumber= "AT635/230\x00"
    ps.open()
    print(ps.getAllUnitInfo())
    ps.setChannel(channel="B", enabled=False)

    # you can open devices by serial number

   # do stuff
    ps.flashLed(10)
    time.sleep(4.0)  # the above flash takes roughly 4 seconds

    ps.close()

Error tracing


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-f7211da71b08> in <module>
      9 
     10    # serialNumber= "AT635/230\x00"
---> 11     ps.open()
     12     print(ps.getAllUnitInfo())
     13     ps.setChannel(channel="B", enabled=False)

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\picobase.py in open(self, serialNumber)
    855     def open(self, serialNumber=None):
    856         """Open the scope, using a serialNumber if given."""
--> 857         self._lowLevelOpenUnit(serialNumber)
    858 
    859     def openUnitAsync(self, serialNumber=None):

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\ps3000a.py in _lowLevelOpenUnit(self, sn)
    169             self.changePowerSource("PICO_POWER_SUPPLY_NOT_CONNECTED")
    170         else:
--> 171             self.checkResult(m)
    172 
    173     def _lowLevelCloseUnit(self):

E:\ChipWhisperer5_64\WPy64-3740\python-3.7.4.amd64\lib\site-packages\picoscope\picobase.py in checkResult(self, ec)
    898             ecDesc = self.errorNumToDesc(ec)
    899             raise IOError('Error calling %s: %s (%s)' % (
--> 900                 str(inspect.stack()[1][3]), ecName, ecDesc))
    901 
    902     def errorNumToName(self, num):

OSError: Error calling _lowLevelOpenUnit: PICO_NOT_FOUND (No PicoScope XXXX could be found.)
hmaarrfk commented 4 years ago

can you please reformat your error messages with code blocks https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks

hmaarrfk commented 4 years ago

So you have the power supply connected? Can you make sure you are using a high quality USb cable. I would try to recreate the issue with picos software directly and posst on their forum.

Ours is but a thin wrapper on their stuff

Zorro9999 commented 4 years ago

Good day. The original program from the picoscope and the picoscope itself works. The picopitone library is installed and some of the things from this library work. I gave code examples a little higher that display information about the picoscope and blink the LED a certain number of times. I still assume that the program cannot communicate with the picoscope because it is necessary to indicate its number somewhere, the methods given in the examples for some reason do not work. Perhaps this is due to the features of python 3.7. Yes, I pointed out an error in the library of work with a picoscope 3000a; there is an incorrect variable name AWGMaxVa = 32767, it should be AWGMaxVal = 32767

hmaarrfk commented 4 years ago

Ah, well constructive changes to the library are welcome. Would you like to make the pull request?

Zorro9999 commented 4 years ago

No . Unfortunately, I am only new to python.

hmaarrfk commented 4 years ago

You found the perfect issue to submit a fix for!

You can follow the getting started instructions here. https://www.thinkful.com/learn/github-pull-request-tutorial/#Time-to-Submit-Your-First-PR

Otherwise, it might take a while for us to get to it. Since we don't have the 3000a to test it on.

As to why it works in C and not with us, can you provide us with the C code that does work for work?

Our python function calls map directly to the C functions

Zorro9999 commented 4 years ago

Thanks for the link. Now I tried to install the original library from this branch https://github.com/picotech/picosdk-python-wrappers And fulfilled their examples. Everything works and graphs are built.

Of course, I would love to plmog in fixing the code, but as I already told you, my knowledge in python is not enough for this. I'm still trying to understand the reason why the source code does not want to connect to the picoscope.

hmaarrfk commented 4 years ago

there is an incorrect variable name AWGMaxVa = 32767, it should be AWGMaxVal = 32767

You've identified an incorrect variable name! That is a great first contribution. Whether you choose it is worth your time contributing is up to you.

Yes, picosdk-python-wrappers are the official ones provided by picotech. Our library predates those. Personally, I think our stuff is more in line with Python, and easier to install.

Anyway, I created the isolated issue: https://github.com/colinoflynn/pico-python/issues/163 for somebody to fix.