Closed cnguyen-blackrockneuro closed 2 years ago
There are some definitions missing in the current McsUsbNet.dll for the old device STG200x: In C# you should try something like: CMcsUsbListNet deviceList = new CMcsUsbListNet(new DeviceIdNet[1]{new DeviceIdNet(VendorIdEnumNet.Any, ProductIdEnumNet.Any, -1, McsBusTypeEnumNet.MCS_USB_BUS)}); instead of deviceList = Mcs.Usb.CMcsUsbListNet(Mcs.Usb.DeviceEnumNet.MCS_STG_DEVICE); in Matlab run_stg.m
Do you know how to translate that C# code to MATLAB? I am not familiar with C#, and I am not an expert programmer.
I have tried the following:
import Mcs.Usb.*
% Create STG object
fprintf('Creating STG object...');
assembly = NET.addAssembly(libFilePath);
stg = CStg200xDownloadNet();
fprintf('done\n');
% Connects to a MCS STG device
fprintf('Finding number of devices...');
deviceID = DeviceIdNet(...
VendorIdEnumNet.Any,...
ProductIdEnumNet.Any,...
-1,...
McsBusTypeEnumNet.MCS_USB_BUS);
connection = DeviceEnumNet.MCS_STG_DEVICE;
deviceList = CMcsUsbListNet(connection);
numOfDevices = deviceList.GetNumberOfDevices();
fprintf('%d\n',numOfDevices);
Results in:
Creating STG object...done
Finding number of devices...0
Do you know how to code this for MATLAB?
Could be something like this (googled: matlab create .net array). I do not have Matlab at hand:
deviceID = DeviceIdNet(... VendorIdEnumNet.Any,... ProductIdEnumNet.Any,... -1,... McsBusTypeEnumNet.MCS_USB_BUS);
connection = NET.createArray('DeviceIdNet',1); connection(1) = deviceID;
deviceList = CMcsUsbListNet(connection);
I was successful at getting the code to run like you suggested, but it still does not detect any devices. The deviceList and numOfDevices still return 0.
%% STG Initialization
% Declare STG object
fprintf('Declaring STG object...');
assembly = NET.addAssembly(libFilePath);
stg = Mcs.Usb.CStg200xDownloadNet();
fprintf('done\n');
% Connects to a MCS STG device
fprintf('Finding number of devices...');
deviceID = Mcs.Usb.DeviceIdNet(...
Mcs.Usb.VendorIdEnumNet.Any,...
Mcs.Usb.ProductIdEnumNet.Any,...
-1,...
Mcs.Usb.McsBusTypeEnumNet.MCS_USB_BUS);
connection = NET.createArray('Mcs.Usb.DeviceIdNet',1);
connection(1) = deviceID;
deviceList = Mcs.Usb.CMcsUsbListNet(connection);
numOfDevices = deviceList.GetNumberOfDevices();
fprintf('%d\n',numOfDevices);
disp(deviceList);
Declaring STG object...done
Finding number of devices...0
CMcsUsbListNet with properties:
Count: 0
Actually I realized that Mcs.Usb.VendorIdEnumNet.Any was not handled as expected. I just updated the McsUsbNet.dll submodule in Github with a correct handling of Mcs.Usb.VendorIdEnumNet.Any. As well Mcs.Usb.VendorIdEnumNet.MCS_old should be possible now.
Thank you! The code can detect and connect with the device. However, now I am running into a different issue. McsUsbNet does not recognize functions like GetTotalMemory, GetNumberOfAnalogChannels, and GetNumberOfSyncoutChannels.
fprintf('Getting total available memory...');
totalMem = stg.GetTotalMemory();
fprintf('%d\n',totalMem);
fprintf('Getting number of available analog channels...');
numOfChannels = stg.GetNumberOfAnalogChannels();
fprintf('%d\n',numOfChannels);
fprintf('Getting number of available SYNC OUT channels...');
numOfSyncOut = stg.GetNumberOfSyncoutChannels();
fprintf('%d\n',numOfSyncOut);
Getting number of available analog channels...Error using STG_Script
Message: Request timeout
Source: McsUsbNet
HelpLink: None
Probably these functions are not available for the STG200x. The example is for the STG400x series. Just skip those functions. I hope that stimulation will work, but I must admit, that we do not support the STG200x any longer. So I will not be able to do tests with the device.
I am trying to program an STG2008 with MATLAB. MC_Stimulus_II can connect with it. After closing MC_Stimulus_II, I try connecting to it with MATLAB by running "init_stg.m" and then "run_stg.m"; however, it always results in a "Found 0 STGs."