Problems with STG4002 control by McsUsbNET.dll
2 posters
Problems with STG4002 control by McsUsbNET.dll
Hi,
We've recently been trying to control STG4002 by McsUsbNET.dll.
However, as a beginner, we encountered some troubles generating the stimuli we want.
Here are some questions about our code:
1. We could already detect the STG4002 connected to the computer, but we didn't receive the corresponding voltage in the output channel.
2. From the example package offered by MCS online, McsUsbNet.dll cannot be opened, so we could only use McsUsbNet_v20.dll. What’s the difference?
3. NET.convertArray can only run when we use the mode in ‘Int16’
4. Device.EnqueueData gives us the correct bytes of data imported, but we still cannot see the stimuli coming out. We are not sure what Device.EnqueueData means, ‘equed’ is still the same amount of bytes even when the channel number is changed. Dose the channel start from zero or one?~
Here's the code we use:
We've recently been trying to control STG4002 by McsUsbNET.dll.
However, as a beginner, we encountered some troubles generating the stimuli we want.
Here are some questions about our code:
1. We could already detect the STG4002 connected to the computer, but we didn't receive the corresponding voltage in the output channel.
2. From the example package offered by MCS online, McsUsbNet.dll cannot be opened, so we could only use McsUsbNet_v20.dll. What’s the difference?
3. NET.convertArray can only run when we use the mode in ‘Int16’
4. Device.EnqueueData gives us the correct bytes of data imported, but we still cannot see the stimuli coming out. We are not sure what Device.EnqueueData means, ‘equed’ is still the same amount of bytes even when the channel number is changed. Dose the channel start from zero or one?~
Here's the code we use:
- Code:
dll = NET.addAssembly([pwd '\McsUsbNet_v20.dll']);
import Mcs.Usb.*
deviceList = CMcsUsbListNet();
deviceList.Initialize(DeviceEnumNet.MCS_STG_DEVICE);
fprintf('Found %d STGs\n', deviceList.GetNumberOfDevices());
for i=1:deviceList.GetNumberOfDevices()
SerialNumber = char(deviceList.GetUsbListEntry(i-1).SerialNumber);
fprintf('Serial Number: %s\n', SerialNumber);
end
channels=8;
device = CStg200xStreamingNet(50000);
device.Connect(deviceList.GetUsbListEntry(0));
device.EnableContinousMode();
device.SetOutputRate(1000);
ntrigger = device.GetNumberOfTriggerInputs();
fprintf('Number of Triggers: %d\n', ntrigger);
number_devices_connected = 1;
stg_triggercapacity=uint32(50000*ones(1,ntrigger(number_devices_connected)));
device.SetCapacity(NET.convertArray(stg_triggercapacity,'System.UInt32'));
% de
%
%
%
%
%
% device.SetupTrigger(ntrigger,2,2,0,1)
% device.StopLoop
%
% %
% device.SetCurrentMode()
% channelmap = uint32(zeros(1,ntrigger(number_devices_connected)));
% syncoutmap = uint32(zeros(1,ntrigger(number_devices_connected)));
% digoutmap = uint32(zeros(1,ntrigger(number_devices_connected)));
% autostart = uint32(zeros(1,ntrigger(number_devices_connected)));
channelmap = uint32([0 0]);
syncoutmap = uint32([0 0]);
digoutmap = uint32([0 0]);
autostart = uint32([1 1]);
callbackThreshold = uint32([0 0]);
channelmap(1) = 255;
callbackThreshold(1) = 50;
device.SetupTrigger(NET.convertArray(channelmap,'System.UInt32')...
,NET.convertArray(syncoutmap,'System.UInt32')...
,NET.convertArray(digoutmap,'System.UInt32')...
,NET.convertArray(autostart,'System.UInt32')...
,NET.convertArray(callbackThreshold,'System.UInt32'))
device.StartLoop
device.SendStart(uint32(1))
i= 1;
xx = 1 : 5000;
% inputSignal = 127680*rand(1,10000)-1;%1*((2^15-1)*sin(2*i*pi/1000*2));%
inputSignal = 1*((2^15-1)*sin(2*xx*pi/1000*2));%
data2channel = NET.convertArray(inputSignal(:),'System.Int16');
equed = device.EnqueueData(1,data2channel)
device.SendStop(uint32(1))
device.Disconnect();
delete(deviceList);
delete(device);
Hydrolab320- Posts : 5
Join date : 2015-07-27
Re: Problems with STG4002 control by McsUsbNET.dll
Are you sure that you want to use the streaming interface?
The download interface is much more easier to use and is what you want for fixed stimuli.
Jens
The download interface is much more easier to use and is what you want for fixed stimuli.
Jens
Re: Problems with STG4002 control by McsUsbNET.dll
Jens wrote:Are you sure that you want to use the streaming interface?
The download interface is much more easier to use and is what you want for fixed stimuli.
Jens
Thanks for replying. We are already using the streaming interface for simple stimuli in experiments.
However, in some new experiments, we want to feedback stimuli in real time after detecting signals.
In that case it'll be better to control it through the .dll file.
Hydrolab320- Posts : 5
Join date : 2015-07-27
Re: Problems with STG4002 control by McsUsbNET.dll
We modified you code a bit to make it run:
The changes are:
Jens
- Code:
dll = NET.addAssembly([pwd '\McsUsbNet.dll']); % was ..._v20.dll
import Mcs.Usb.*
deviceList = CMcsUsbListNet();
deviceList.Initialize(DeviceEnumNet.MCS_STG_DEVICE);
fprintf('Found %d STGs\n', deviceList.GetNumberOfDevices());
for i=1:deviceList.GetNumberOfDevices()
SerialNumber = char(deviceList.GetUsbListEntry(i-1).SerialNumber);
fprintf('Serial Number: %s\n', SerialNumber);
end
%%
channels=8;
device = CStg200xStreamingNet(50000);
device.Connect(deviceList.GetUsbListEntry(0));
device.EnableContinousMode();
device.SetOutputRate(1000);
ntrigger = device.GetNumberOfTriggerInputs();
fprintf('Number of Triggers: %d\n', ntrigger);
number_devices_connected = 1;
stg_triggercapacity=uint32(50000*ones(1,ntrigger(number_devices_connected)));
device.SetCapacity(NET.convertArray(stg_triggercapacity,'System.UInt32'));
%%
% de
%
%
%
%
%
% device.SetupTrigger(ntrigger,2,2,0,1)
% device.StopLoop
%
% %
% device.SetCurrentMode()
% channelmap = uint32(zeros(1,ntrigger(number_devices_connected)));
% syncoutmap = uint32(zeros(1,ntrigger(number_devices_connected)));
% digoutmap = uint32(zeros(1,ntrigger(number_devices_connected)));
% autostart = uint32(zeros(1,ntrigger(number_devices_connected)));
channelmap = uint32([0 0]);
syncoutmap = uint32([0 0]);
digoutmap = uint32([0 0]);
autostart = uint32([1 1]);
callbackThreshold = uint32([0 0]);
channelmap(1) = 1; % was 255
callbackThreshold(1) = 50;
device.SetVoltageMode(); % was missing
device.SetupTrigger(NET.convertArray(channelmap,'System.UInt32')...
,NET.convertArray(syncoutmap,'System.UInt32')...
,NET.convertArray(digoutmap,'System.UInt32')...
,NET.convertArray(autostart,'System.UInt32')...
,NET.convertArray(callbackThreshold,'System.UInt32'))
device.StartLoop
%%
device.SendStart(uint32(1))
% modified from here...
for rep = 1:100
queueSpace = device.GetDataQueueSpace(0);
while queueSpace < 5000
queueSpace = device.GetDataQueueSpace(0);
end
i= 1;
xx = 1 : 5000;
% inputSignal = 127680*rand(1,10000)-1;%1*((2^15-1)*sin(2*i*pi/1000*2));%
inputSignal = 1*((2^15-1)*sin(2*xx*pi/1000*2));%
data2channel = NET.convertArray(inputSignal(:),'System.Int16');
equed = device.EnqueueData(0,data2channel) % was 1
end
%... to here
device.SendStop(uint32(1))
%%
device.StopLoop()
device.Disconnect();
delete(deviceList);
delete(device);
The changes are:
- We did not observe a problem with the McsUsbNet.dll. The _v20 means that it is using the .Net framework version 2.0, the normal version is using .Net 4.0. You need to use the 64bit version of McsUsbNet.dll for 64bit Matlab.
- We reduced the channelmap for trigger one to channel 1, other wise you have to enqueue data for all 8 channels
- We explicitly set voltage mode, otherwise no mode is set
- We enqueue data for some time depending on the queue filling state.
- We enqueue data for some time before stopping the trigger. When the trigger stops not signal comes out any more.
- We enqueue data to channel 0, because this is the first channel.
- We issue StopLoop as well, as opposed to StartLoop
Jens
Re: Problems with STG4002 control by McsUsbNET.dll
Hello, it is very useful using this code. Thanks a lot! We can now output data by .dll. However, now we want to send synchronize data using EnqueueSyncout, as in the software:
we tried to do it by adding the code in for loop:
However, we did not see analog data in mcd. Is this how we should use EnqueueSyncout?
we tried to do it by adding the code in for loop:
- Code:
sy = 1:5000;
sy = mod(sy,2);
equed_sync = device.EnqueueSyncout(0,sy);
However, we did not see analog data in mcd. Is this how we should use EnqueueSyncout?
Hydrolab320- Posts : 5
Join date : 2015-07-27
Re: Problems with STG4002 control by McsUsbNET.dll
You need to add the sync channel to the trigger map:
- Code:
syncoutmap(1) = 1;
Re: Problems with STG4002 control by McsUsbNET.dll
Thank you very much! We are now using it greatly!
Hydrolab320- Posts : 5
Join date : 2015-07-27
Similar topics
» Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
» Problems with Matlab-MEX files (McsUsbDLL.h) on 64Bit for STG400x
» MC RACK stops recording - Electrode Raw data in watchog
» Problems getting good signals
» Automatic control of stimulation
» Problems with Matlab-MEX files (McsUsbDLL.h) on 64Bit for STG400x
» MC RACK stops recording - Electrode Raw data in watchog
» Problems getting good signals
» Automatic control of stimulation
Permissions in this forum:
You cannot reply to topics in this forum