How do I reset a connection to a picoscope without instrreset?

17 views (last 30 days)
I am using a picoscope 5444D MSO in matlab to capute some data. However, sometimes my code is buggy during testing and the only way I know to reset the picoscope is to use the command instrreset. Now Matlab r2025b tells me, that this command will be removed in future releases and displays the following list of possible commands to replace instrreset:
Warning: instrreset will be removed in a future release. For objects of type
- serialport use delete(serialportfind)
- tcpclient use delete(tcpclientfind)
- tcpserver use delete(tcpserverfind)
- udpport use delete(udpportfind)
- visadev use delete(visadevfind)
- aardvark use delete(aardvarkfind)
- ni845x use delete(ni845xfind)
- icdevice with LegacyMode=false use delete(icdevicefind)
However, none of these work to actually reset my picoscope. Is there any other way?

Accepted Answer

Umar
Umar on 28 Oct 2025 at 19:03

Hi @Patrick,

I saw your question regarding the deprecation of `instrreset` in MATLAB R2025b, and I wanted to provide some insights based on the new recommendations. It seems that the removal of `instrreset` is a bit of a pain, especially if it’s been your go-to method for resetting your Picoscope 5444D. But no worries, there is work around in the newer MATLAB versions, you will need to manually manage the connection cleanup instead of relying on `instrreset`. The general workflow would look like this:

1. Stop any asynchronous operations: If your code is running asynchronous tasks (like data capture), you need to ensure those are stopped.

     if strcmp(icdev.Status, 'open')
       stopasync(icdev);  % Stop any async operations running
     end

2. Close the connection: Use `fclose` to disconnect from the Picoscope.

   fclose(icdev);  % Close the connection to the Picoscope

3. Delete the instrument object: This will disconnect the device from MATLAB and free the associated resources.

   delete(icdev);  % Delete the object, disconnecting the device

4. Clear the object from the workspace: Finally, remove the object reference from the workspace to ensure that it's completely cleaned up.

   clear icdev;  % Clear the object from the workspace

Here is full example

% Assuming icdev is your Picoscope device object
% Stop asynchronous operations if any
if strcmp(icdev.Status, 'open')
  stopasync(icdev);
end
% Close the connection
fclose(icdev);
% Delete the device object and disconnect from the instrument
delete(icdev);
% Clear the object from the workspace
clear icdev;

This sequence should provide the same functionality as `instrreset`, effectively resetting your Picoscope. Now, if you need to reset all connected devices (similar to `instrreset`'s old behavior), I’ve also created a small helper function that will loop through all connected devices and clean them up. Here’s an example:

function resetAllInstruments()
  % Find all connected icdevice objects
  devices = icdevicefind('PicoScope');  % Adjust with your specific device name
    % Stop async, close, delete, and clear each device
    for i = 1:length(devices)
        if strcmp(devices(i).Status, 'open')
            stopasync(devices(i));  % Stop async if needed
            fclose(devices(i));     % Close the connection
        end
        delete(devices(i));         % Delete the object
        clear devices(i);           % Clear it from the workspace
    end
  end

You can call this whenever you need to reset all connected Picoscope devices at once. It’ll handle everything for you.

Let me recap, instrreset is being phased out, but you can still reset your Picoscope using `stopasync`, `fclose`, `delete`, and `clear`. The steps I’ve outlined should work seamlessly in the upcoming versions of MATLAB.

Hope this helps!

  2 Comments
Patrick
Patrick on 30 Oct 2025 at 13:20
Thank you for the answer, but this does not quiet solve my problem. In the meantime, I saw that my main problem is probabaly due to the fact, that the picoscope I use registers as a legacy device when calling
icdevice('picotech_ps5000a_generic');
Apparently icdevicefind command can not find legacy devices. Is there any command that actually finds legacy devices? Otherwise I have to have a look over at the picoscope SKD and see if they offer any non legacy method to connect the picosope. Just adding LegacyMode=false as an option to the connection command
icdevice('picotech_ps5000a_generic',LegacyMode=false);
does not work, as it provoces additional errors.
Umar
Umar on 30 Oct 2025 at 14:05

Hi @Patrick,

You've correctly identified the core issue. Since your PicoScope registers as a legacy device when calling icdevice('picotech_ps5000a_generic'), the problem is that the icdevicefind function finds only those device connections created with LegacyMode=false.

For finding legacy icdevice objects, you must use instrfind or instrfindall.While the documentation shows these functions are being deprecated for serial port objects, they still work with legacy icdevice objects. However, it's important to note that the legacy mode of icdevice will be removed in a future release, and the instrfind and instrfindall functions will also be removed (with icdevicefind as the recommended replacement). So, for icdevice objects, use disconnect() rather than fclose(), as shown in the documentation examples which consistently use disconnect(d) followed by delete([d g]).

Regarding LegacyMode=false: You're correct that simply adding it as an option doesn't work. When creating a device object with icdevice(driver,hwobj), you need to provide a hardware interface object (hwobj) which can be a serial port, GPIB, VISA, TCPIP, or UDP object. The 'picotech_ps5000a_generic' driver is a MATLAB interface driver designed to work in legacy mode without requiring a separate interface object.

Your best path forward:

1. Use instrfind with the proper cleanup sequence while it's still available in your current MATLAB version

2. Contact Pico Technology to inquire about updated drivers that support non-legacy mode or alternative connection methods

3. Explore the PicoScope SDK for a more future-proof solution using MATLAB's library interface capabilities (loadlibrary functions)

The instrfind approach will work in your current MATLAB version, giving you time to plan for the eventual migration away from legacy mode.

Hope this helps clarify the situation!

Sign in to comment.

More Answers (0)

Categories

Find more on Instrument Connection and Communication in Help Center and File Exchange

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!