Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB powered picoscope 5000a #44

Closed
thomaspmann opened this issue Apr 14, 2016 · 11 comments
Closed

USB powered picoscope 5000a #44

thomaspmann opened this issue Apr 14, 2016 · 11 comments

Comments

@thomaspmann
Copy link

Has anyone got a way to avoid the error when the picoscope is powered from USB rather than from the power supply?

@hmaarrfk
Copy link
Collaborator

What error specifically?

Haven't used the picoscope for a while, so I'm not exactly fresh on all the little quirks.

@morgatron
Copy link
Contributor

Are you using a ps544x? I haven't had the issue myself, but maybe you've
seen that the c examples seem to check for power supply changes and
undervoltage, e.g. this straight from the example included for my scope:

/****************************************************************************************

  • ChangePowerSource - function to handle switches between +5V supply, and
    USB only power
  • Only applies to PS544xA/B units
    ******************************************************************************************/
    PICO_STATUS changePowerSource(int16_t handle, PICO_STATUS status, UNIT *
    unit)
    {
    int8_t ch;

switch (status)
{
case PICO_POWER_SUPPLY_NOT_CONNECTED: // User must acknowledge they want to
power via USB
do
{
printf("\n5V power supply not connected.");
printf("\nDo you want to run using USB only Y/N?\n");
ch = toupper(_getch());
if(ch == 'Y')
{
printf("\nPowering the unit via USB\n");
status = ps5000aChangePowerSource(handle, PICO_POWER_SUPPLY_NOT_CONNECTED); //
Tell the driver that's ok
if(status == PICO_OK && unit->channelCount == QUAD_SCOPE)
{
unit->channelSettings[PS5000A_CHANNEL_C].enabled = FALSE;
unit->channelSettings[PS5000A_CHANNEL_D].enabled = FALSE;
}
else if (status == PICO_POWER_SUPPLY_UNDERVOLTAGE)
{
status = changePowerSource(handle, status, unit);
}
else
{
// Do nothing
}

}
}
while(ch != 'Y' && ch != 'N');
printf(ch == 'N'?"Please use the +5V power supply to power this unit\n":"");
break;

case PICO_POWER_SUPPLY_CONNECTED:
printf("\nUsing +5V power supply voltage\n");
status = ps5000aChangePowerSource(handle, PICO_POWER_SUPPLY_CONNECTED); //
Tell the driver we are powered from +5V supply
break;

case PICO_POWER_SUPPLY_UNDERVOLTAGE:
do
{
printf("\nUSB not supplying required voltage");
printf("\nPlease plug in the +5V power supply\n");
printf("\nHit any key to continue, or Esc to exit...\n");
ch = _getch();
if (ch == 0x1B) // ESC key
exit(0);
else
status = ps5000aChangePowerSource(handle, PICO_POWER_SUPPLY_CONNECTED); //
Tell the driver that's ok
}
while (status == PICO_POWER_SUPPLY_REQUEST_INVALID);
break;
}
return status;
}

Maybe a python version of that is what you need?

On Thu, Apr 14, 2016 at 10:59 AM, Mark Harfouche notifications@github.com
wrote:

What error specifically?

Haven't used the picoscope for a while, so I'm not exactly fresh on all
the little quirks.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#44 (comment)

@thomaspmann
Copy link
Author

It's the Ps5242a. The error is PICO_POWER_SUPPLY_NOT_CONNECTED. Yes as you say morgatron, I need to use the function ps5000aChangePowerSource. I'm not quite sure why they say it only applies to the PS544xa series. The error is in checkResult in picobase.py and there is a note mentioning this. what would be the best way to implement this function - add it to picobase or the picoscope5000a class? Cheers

@hmaarrfk
Copy link
Collaborator

hmaarrfk commented Apr 14, 2016

Our general strategy has been the following:

Add all the logic and "default parameter" settings to the picobase. The picobase should NOT have ctypes.

the ps5000a class should simply convert from python datatypes to ctypes as much as possible.
IF you think the function only applies to a particular family of scopes, then it might be appropriate to include it only in the ps5000a class.

Generally:
picobase: LIGHT parameter checking (the drivers do a fair bit of error checking,

for example

        if not isinstance(channel, int):
            chNum = self.CHANNELS[channel]
        else:
            chNum = channel

allows you to set a channel either by letter "B" or by number int(1). We don't check for out of bound integers because the driver will do that for you.

Once you have done things that you call your _lowLevel function that calls the appropriate function in the dll. The picobase does not have access to the dll, nor should it.

I'll try to write this up nicely some time.

Thanks for helping make this library better!

@thomaspmann
Copy link
Author

i know it's been a while since i raised this issue, however the solution that i have been using its to add

# Change power source if status is PICO_POWER_SUPPLY_NOT_CONNECTED (m==282) before checking the result m
 if m == 282:
        m = self.lib.ps5000aChangePowerSource(c_handle, m)

between m = self.lib.ps5000aOpenUnit(byref(c_handle), serialNullTermStr, self.resolution) and self.checkResult(m) in the _lowLevelOpenUnit function inside picoscope500a class.

I'm think that this should be within the ps500a class as not all picoscopes can be powered by USB.

@hmaarrfk
Copy link
Collaborator

hmaarrfk commented Aug 9, 2016

Can you try the branch ps5000aChangePowerSource

I was hesitant to inject the code in the open function, but I think that is a fair thing to do.

See the 3 locations were code was changed:

  1. picoscope.py
    Translation between optional string input and ints
    We will let python deal with the fact that not all scopes can have USB power.
    We could theoretically put this function in ps5000a.py instead of picoscope.
  2. ps5000a.py
    The actual call to the library. All input should be correct at this point
  3. ps5000a.py
    The _lowLevelOpenUnit call, as you wanted it to be :D

@hmaarrfk
Copy link
Collaborator

hmaarrfk commented Aug 9, 2016

Let me know if this fixes things, I will push it to the master branch if it does

@colinoflynn
Copy link
Owner

I just tried this, had a few bug-fixes (commited). I wasn't sure on the RV for the function how it was supposed to work.

But it doesn't work for me - I get an error that the PICO is not responding to USB commands inside of the call to changePowerState(). Not sure if it's just a hardware setup issue on my side though.

hmaarrfk added a commit that referenced this issue Aug 9, 2016
@hmaarrfk
Copy link
Collaborator

hmaarrfk commented Aug 9, 2016

Sorry about the RV. I forgot we were being pythonic and didn't actually return error codes from the picoscope class.

My commit removes the RV. Thanks for placing the handle at the correct location.

It should be pretty easy to test, just connect the scope to the USB, nothing else. The USB cable should be a good one though, maybe the one supplied by picotech, else there might be a big voltage drop from the computer to the scope.

@colinoflynn
Copy link
Owner

Gotcha thanks - your code looks more reasonable! Fixed a small typo + error reporting problem and it works for me I think now.

My original problem was indeeed a crappy USB cable :/

@thomaspmann
Copy link
Author

Hmm strange. Which picoscope are you using it on Colin?

I do agree that implementing the change power source function by default isn't pretty and could potentially hide other bugs. Would it possibly make sense to add a parameter to _lowLevelOpenUnit that by default is set to use DC power but could be set by a user for USB power. Then an if function after ps5000aOpenUnit can change the power source if the parameter is set to USB?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants