colinoflynn / pico-python

PicoScope Python Interface
Other
101 stars 80 forks source link

Handling the connection with USB2 wire for ps5000D #199

Closed elechapt closed 7 months ago

elechapt commented 7 months ago

Fixing issue #198

hmaarrfk commented 7 months ago

I somewhat don't want to fix this.

USB2.0 only gives you 500mA of power (by spec) so it will cause you many problems.

I would almost want it to be an option like:

usb_2_power_ok=True

to ensure that the user knows that they are connecting to a low power, lower datarate port.

elechapt commented 7 months ago

Indeed, the problem is that the bandwidth is divided by four, but the alternative is no connection at all. And I think a user wanting high datarate will be aware of that problem, or at least see it in its datas. This patch connects via USB2 only if it's required. We can have a warning message indicating the error while connecting if you prefer.

hmaarrfk commented 7 months ago

No. I want it to error by default unless the user tells me explicitly that usb2 is ok.

Silently switching to usb2 on a device that is supposed to be high performance is not good for API design.

I'm still curious, in your use case. Are you able to use USB3? In my mind this is such a trivial issue to solve in real life that providing the opt8ok to workaround it in software seems like more work (and maintenance)

elechapt commented 7 months ago

I'm not the only one using the equipment. I'm the low-level guy making things for non-programmers && non-electronicians in the lab. I have to make sure things work no matter what, even if someone uses the wrong wire or another computer, so I handle the warnings for low datarates. And the picoscope is embedded in another device, no one is supposed to know what's inside the box. Those people know how to use the official "Picoscope 6" software, which handles the low datarate for USB2.

Do you want me to add that as an option in both _Picobase.open(...) and PS5000a._lowLevelOpenUnit(...) ?

hmaarrfk commented 7 months ago

And the picoscope is embedded in another device

Ok this is a usecase that was not considered before. Embedded devices sometimes only function at 2.0 levels so it is "impossible" to change the cable for an "upgrade".

Truthfully I don't really know the semantics of the error. Does it mean:

or

I just want to make sure that the problem I outlined 8 years ago worse:

        # This will check if the power supply is not connected
        # and change the power supply accordingly
        # Personally (me = Mark), I don't like this
        # since the user should address this immediately, and we
        # shouldn't let this go as a soft error
        # but I think this should do for now

And the picoscope is embedded in another device, no one is supposed to know what's inside the box.

PS. For your own sake, I hope you QC to ensure that the right cable goes in the box ;)

elechapt commented 7 months ago

Quoting the programmers' guide, it is apparently intended, "normal" in a way, that ps5000aOpenUnit returns a code status saying that USB3 is not available and the user has to change power source:

PICO_USB3_0_DEVICE_NON_USB3_0_PORT: · Call ps5000aChangePowerSource to complete the two-stage power-up sequence for a USB 2.0 port

and

PICO_USB3_0_DEVICE_NON_USB3_0_PORT – for 2-channel 5000D and 5000D MSO devices

I have no clue a priori whether external power is connected on the picoscope, I wasn't handling this part, but for what I can see inside the box, it's only connected through USB3, no external power (I think ther isn't, it is a 2 channels model). I think the error arise whether or not external power is there, only if USB2 instead of USB3 is used.

hmaarrfk commented 7 months ago

ok, deal.

elechapt commented 7 months ago

@hmaarrfk Just to make you laugh a bit : I've checked with a USB3 wire. It is a USB3 inside, but the connection from outside doesn't work : they didn't tested it !! So until it's fixed, the only available connection is USB2 !

hmaarrfk commented 7 months ago

@hmaarrfk Just to make you laugh a bit : I've checked with a USB3 wire. It is a USB3 inside, but the connection from outside doesn't work : they didn't tested it !! So until it's fixed, the only available connection is USB2 !

The saga never ends with embedded development!

Godspeed with fixing things! Thanks for your contribution and willingness to discuss!