Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
2 posters
Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
I'm trying to stream randomly generated sinusoid signals to all channels of an STG4008 from Matlab (r2011b 32 bit). The .Net assambly (McsUsbNet.dll) has been imported to Matlab. I'm able to query the serial number, the number of devices connected and also to establish the connection between the PC and the STG. The parameters (channelmap, syncoutmap, digoutmap etc.) necessary to start the transmission of the signals being generated have also been set. I have difficulties in sending the sinusoid signals to either 1 or all 8 channels. Below you can find the related part of the Matlab script I'm using. I don't have idea on how to move on with putting different signals to all 8 channels. Any help would be appreciated.
- Code:
asm = NET.addAssembly('i:\UofA\MultipleStimulators\McsUsbNetPackage\McsUsbNet.dll');
import Mcs.Usb.*
deviceList = CMcsUsbListNet();
deviceList.Initialize(DeviceEnumNet.MCS_STG_DEVICE);
number_devices_connected = deviceList.GetNumberOfDevices();
SerialNumber = cell(number_devices_connected,1);
fprintf('Found %d STGs\n', number_devices_connected);
for i=1:number_devices_connected
SerialNumber{i,1} = char(deviceList.GetUsbListEntry(i-1).SerialNumber);
fprintf('Serial Number: %s\n', SerialNumber{i,1});
end
switch number_devices_connected
case 1
% 1st device
Channels = 8;
device1 = CStg200xStreamingNet(50000); % device object - actually the problem is that DataHandler should use the device1 object although it has not been created
device1.Connect(deviceList.GetUsbListEntry(0));
device1.EnableContinousMode();
device1.SetOutputRate(50000);
ntrigger(number_devices_connected) = device1.GetNumberOfTriggerInputs();
fprintf(['Number of Triggers for ' num2str(SerialNumber{1,1}) ' is: ' num2str(ntrigger(1)) '\n']);
channelmap=zeros(1,ntrigger(number_devices_connected));
syncoutmap=zeros(1,ntrigger(number_devices_connected));
digoutmap=zeros(1,ntrigger(number_devices_connected));
autostart=zeros(1,ntrigger(number_devices_connected));
callbackThreshold=zeros(1,ntrigger(number_devices_connected));
channelmap(1)=1; % assign all channels to trigger 1
callbackThreshold(1)=50;
device1.SetupTrigger(channelmap,syncoutmap,digoutmap,autostart,callbackThreshold)
for k = 1:number_devices_connected
if ~strcmp(SerialNumber(k,1),'9027-0077')
device1.SetCurrentMode();
end
end
device1.StartLoop();
device1.SendStart(1);
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
for periods =1:space(channel)/1000
inputSignal = 1*((2^15-1)*sin(2*i*pi/1000*channel+1)); % sin signal generated randomly
device1.EnqueueData(channel,inputSignal);
end
end
Robcsy83- Posts : 21
Join date : 2013-05-21
Using Matlab to stream multiple channels to an STG4008
Hi Robcsy83,
to use multiple channels, you have to assign all the channels you want to use to the trigger.
To use all 8 channels, it would be
What has been your result when sending data only to channel 1? How did the output look like?
Best regards,
Peter
to use multiple channels, you have to assign all the channels you want to use to the trigger.
To use all 8 channels, it would be
- Code:
channelmap(1)=255; % assign channels 1..8 to trigger 1 (set one bit per channel; bit 0 = channel 1, bit 1 = channel 2, ...
What has been your result when sending data only to channel 1? How did the output look like?
Best regards,
Peter
Peter MCS- Posts : 16
Join date : 2011-10-04
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Dear Peter,
Unfortunately, I did not receive anything either on channel 1 or on the other channels after the modification you had previously suggested was done. The output showed 0V on an oscilloscope. The oscilloscope has been set up as it's suggested in the user manual. A 10kOhm resistor has been added to the circuitry before the signals were delivered to the oscilloscope via a BNC cable. Furthermore, I wanted to exclude the possibility that either the oscilloscope or the setup of it was wrong. Therefore, I generated a series of square signals in the MCstimulus II software. Then I received the correct voltages based on Ohm's law (100uA * 10kOhm = 1V, 200uA * 10kOhm = 2V stepping until 500uA * 10kOhm = 5V etc.).
By adding the 'enqued' variable, I could figure it out that the device1.EnqueData(channel, InputSignal) function returned all 2s. However, it's been written in the manual that it should have returned all 0s in case of a successful execution. I suppose the issue might arise somewhere here. A clear evidence of this is that the LED on the STG4008 related to this function (PROG LED) was not active during the execution of the Matlab script. According to this there was nothing in the buffer to be swept.
Any other idea?
Thank you!
Unfortunately, I did not receive anything either on channel 1 or on the other channels after the modification you had previously suggested was done. The output showed 0V on an oscilloscope. The oscilloscope has been set up as it's suggested in the user manual. A 10kOhm resistor has been added to the circuitry before the signals were delivered to the oscilloscope via a BNC cable. Furthermore, I wanted to exclude the possibility that either the oscilloscope or the setup of it was wrong. Therefore, I generated a series of square signals in the MCstimulus II software. Then I received the correct voltages based on Ohm's law (100uA * 10kOhm = 1V, 200uA * 10kOhm = 2V stepping until 500uA * 10kOhm = 5V etc.).
By adding the 'enqued' variable, I could figure it out that the device1.EnqueData(channel, InputSignal) function returned all 2s. However, it's been written in the manual that it should have returned all 0s in case of a successful execution. I suppose the issue might arise somewhere here. A clear evidence of this is that the LED on the STG4008 related to this function (PROG LED) was not active during the execution of the Matlab script. According to this there was nothing in the buffer to be swept.
Any other idea?
Thank you!
- Code:
asm = NET.addAssembly('i:\UofA\MultipleStimulators\McsUsbNetPackage\McsUsbNet.dll');
import Mcs.Usb.*
deviceList = CMcsUsbListNet();
deviceList.Initialize(DeviceEnumNet.MCS_STG_DEVICE);
number_devices_connected = deviceList.GetNumberOfDevices();
SerialNumber = cell(number_devices_connected,1);
fprintf('Found %d STGs\n', number_devices_connected);
for i=1:number_devices_connected
SerialNumber{i,1} = char(deviceList.GetUsbListEntry(i-1).SerialNumber);
fprintf('Serial Number: %s\n', SerialNumber{i,1});
end
switch number_devices_connected
case 1
% 1st device
Channels = 8;
device1 = CStg200xStreamingNet(50000); % device object - actually the problem is that DataHandler should use the device1 object although it has not been created
device1.Connect(deviceList.GetUsbListEntry(0));
device1.EnableContinousMode();
device1.SetOutputRate(50000);
ntrigger(number_devices_connected) = device1.GetNumberOfTriggerInputs();
fprintf(['Number of Triggers for ' num2str(SerialNumber{1,1}) ' is: ' num2str(ntrigger(1)) '\n']);
channelmap=zeros(1,ntrigger(number_devices_connected));
syncoutmap=zeros(1,ntrigger(number_devices_connected));
digoutmap=zeros(1,ntrigger(number_devices_connected));
autostart=zeros(1,ntrigger(number_devices_connected));
callbackThreshold=zeros(1,ntrigger(number_devices_connected));
channelmap(1)=255; % suggested modification was done
callbackThreshold(1)=50;
device1.SetupTrigger(channelmap,syncoutmap,digoutmap,autostart,callbackThreshold)
for k = 1:number_devices_connected
if ~strcmp(SerialNumber(k,1),'9027-0077')
device1.SetCurrentMode();
end
end
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1))); % sin signal generated randomly
enqued(channel,:)=device1.EnqueueData(channel,inputSignal(channel)); % contained only 2s
end % [2,2,2,2,2,2,2,2]'
device1.StartLoop();
device1.SendStart(1);
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Robcsy83,
the device1.EnqueData returns the number of bytes enqueued, not zero on success, sorry, this is an error in the manual.
But the fact that you get a "2" indicates that it does not enqueue the whole array but only one datapoint of size Int16 (2 bytes).
It seems you have to use
Best Regards,
Peter
the device1.EnqueData returns the number of bytes enqueued, not zero on success, sorry, this is an error in the manual.
But the fact that you get a "2" indicates that it does not enqueue the whole array but only one datapoint of size Int16 (2 bytes).
It seems you have to use
- Code:
device1.EnqueData(channel, InputSignal(channel,:))
- Code:
arr = NET.convertArray(inputSignal(channel,:), 'System.Int16');
device1.EnqueData(channel, arr)
Best Regards,
Peter
Peter MCS- Posts : 16
Join date : 2011-10-04
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Peter,
I did the modification of the for loop (see below) but still nothing on either channels. The PROG LED on the front panel remained inactivated. I'm out of ideas.
Robert
I did the modification of the for loop (see below) but still nothing on either channels. The PROG LED on the front panel remained inactivated. I'm out of ideas.
- Code:
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
device1.EnqueueData(channel,data2channels);
end
device1.StartLoop();
device1.SendStart(1);
Robert
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Have you tried the new version with
You also have to make a loop around the whole enqueing like
What are the values for "space(channel)" ?
Could you provide output of that code? After you initially fill all queues you should see them emptying at a constant rate.
- Code:
enqued(channel,:)=device1.EnqueueData(channel,inputSignal);
You also have to make a loop around the whole enqueing like
- Code:
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
device1.EnqueueData(channel,data2channels);
end
device1.StartLoop();
device1.SendStart(1);
for loop = 1:999999999
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:) = device1.EnqueueData(channel,data2channels);
end
end
What are the values for "space(channel)" ?
Could you provide output of that code? After you initially fill all queues you should see them emptying at a constant rate.
Peter MCS- Posts : 16
Join date : 2011-10-04
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Peter,
Q1. How many bytes are enqued?
Q2. What are the values for "space(channel)"?
Values stored in space depends on the number of loops and on the signal length (length(inputSignal)=1000).
if loop = 12. Space value was 37999; if loop = 24 then space value was 25999; if loop = 36 than space value was 13999 etc. Note. you suggested to choose a value for loop ~999999999. After more then 20 minutes I had to stop the execution of the nested for loops. This is too much, especially given the fact that the purpose is to transmit stimulus patterns continuously generated in real time for at least 2 minutes. Thus we have to avoid the usage of nested for loops.
Here is the current code:
Thankx,
Robert
Q1. How many bytes are enqued?
- Code:
enqued(channel,:)=device1.EnqueueData(channel,data2channels);
- Code:
enqued(channel,:) = device1.EnqueueData(channel,inputSignal(channel,:));
Q2. What are the values for "space(channel)"?
Values stored in space depends on the number of loops and on the signal length (length(inputSignal)=1000).
if loop = 12. Space value was 37999; if loop = 24 then space value was 25999; if loop = 36 than space value was 13999 etc. Note. you suggested to choose a value for loop ~999999999. After more then 20 minutes I had to stop the execution of the nested for loops. This is too much, especially given the fact that the purpose is to transmit stimulus patterns continuously generated in real time for at least 2 minutes. Thus we have to avoid the usage of nested for loops.
Here is the current code:
- Code:
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:)=device1.EnqueueData(channel,data2channels);
end
device1.StartLoop();
device1.SendStart(1);
for loop = 1:36 % values stored in space depends on the number of loops and on the length of the signal
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:) = device1.EnqueueData(channel,data2channels);
end
end
Thankx,
Robert
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Peter,
The question is why we are not able to activate the PROG LED? In my understanding this means that nothing has been stored in the STG's buffer. Which function is responsible of doing this? Is it the .EnqueueData(channel#,data) function? I suppose the problem should be somewhere here. Based off of the manual the calling of the function is done appropriately using the right types of the input argument arrays.
Furthermore, I don't think the issue is related to either the number of loops or the memory space being occupied by the data transferred. As a start, it doesn't matter how many times a particular pattern gets repeated. Obviously, if the sine waves are loaded to the buffer only once (see the code without adding the "loop" for cycle) they should not occupy the whole space since they length is exactly 1000 pattern. The only thing I'd care about is the successful delivery of the wave forms created.
Regards,
Robert
The question is why we are not able to activate the PROG LED? In my understanding this means that nothing has been stored in the STG's buffer. Which function is responsible of doing this? Is it the .EnqueueData(channel#,data) function? I suppose the problem should be somewhere here. Based off of the manual the calling of the function is done appropriately using the right types of the input argument arrays.
Furthermore, I don't think the issue is related to either the number of loops or the memory space being occupied by the data transferred. As a start, it doesn't matter how many times a particular pattern gets repeated. Obviously, if the sine waves are loaded to the buffer only once (see the code without adding the "loop" for cycle) they should not occupy the whole space since they length is exactly 1000 pattern. The only thing I'd care about is the successful delivery of the wave forms created.
Regards,
Robert
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Robert,
could you post the complete Matlab script as it is now?
We have an example for the streaming mode written in C#. Have you tried running that example?
Does that C# example work on your machine?
Best regards,
Peter
could you post the complete Matlab script as it is now?
We have an example for the streaming mode written in C#. Have you tried running that example?
Does that C# example work on your machine?
Best regards,
Peter
Peter MCS- Posts : 16
Join date : 2011-10-04
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Peter,
I have only tried the Multichannel Software. Tomorrow, I'm planning to try the C# example.
As for the code, only case 1 has been programmed so far.
Robert
I have only tried the Multichannel Software. Tomorrow, I'm planning to try the C# example.
As for the code, only case 1 has been programmed so far.
- Code:
asm = NET.addAssembly('i:\UofA\Projects\MultipleStimulators\McsUsbNetPackage\McsUsbNet.dll');
import Mcs.Usb.*;
deviceList = CMcsUsbListNet();
deviceList.Initialize(DeviceEnumNet.MCS_STG_DEVICE);
number_devices_connected = deviceList.GetNumberOfDevices();
SerialNumber = cell(number_devices_connected,1);
fprintf('Found %d STGs\n', number_devices_connected);
for i=1:number_devices_connected
SerialNumber{i,1} = char(deviceList.GetUsbListEntry(i-1).SerialNumber);
fprintf('Serial Number: %s\n', SerialNumber{i,1});
end
switch number_devices_connected
case 1
% 1st device
Channels = 8;
device1 = CStg200xStreamingNet(50000);
device1.Connect(deviceList.GetUsbListEntry(0));
device1.EnableContinousMode();
device1.SetOutputRate(50000);
ntrigger(number_devices_connected) = device1.GetNumberOfTriggerInputs();
fprintf(['Number of Triggers for ' num2str(SerialNumber{1,1}) ' is: ' num2str(ntrigger(1)) '\n']);
channelmap=zeros(1,ntrigger(number_devices_connected));
syncoutmap=zeros(1,ntrigger(number_devices_connected));
digoutmap=zeros(1,ntrigger(number_devices_connected));
autostart=zeros(1,ntrigger(number_devices_connected));
callbackThreshold=zeros(1,ntrigger(number_devices_connected));
channelmap(1)=255; % assign all channels to trigger 1
callbackThreshold(1)=50;
device1.SetupTrigger(channelmap,syncoutmap,digoutmap,autostart,callbackThreshold)
for k = 1:number_devices_connected
if ~strcmp(SerialNumber(k,1),'9027-0077')
device1.SetCurrentMode();
end
end
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:)=device1.EnqueueData(channel,data2channels);
end
device1.StartLoop();
device1.SendStart(1);
for loop = 1:36
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:) = device1.EnqueueData(channel,data2channels);
end
end
case 2
% % 1st device
% device1 = CStg200xStreamingNet(50000); % device object
% device1.Connect(deviceList.GetUsbListEntry(0));
% device1.EnableContinousMode();
% device1.SetOutputRate(50000);
% ntrigger(number_devices_connected-1) = device1.GetNumberOfTriggerInputs();
% fprintf(['Number of Triggers for ' num2str(SerialNumber{1,1}) ' is: ' num2str(ntrigger(1)) '\n']);
% device1.Disconnect();
%
% % 2nd device
% device2 = CStg200xStreamingNet(50000); % device object
% device2.Connect(deviceList.GetUsbListEntry(1));
% device2.EnableContinousMode();
% device2.SetOutputRate(50000);
% ntrigger(number_devices_connected) = device2.GetNumberOfTriggerInputs();
% fprintf(['Number of Triggers for ' num2str(SerialNumber{2,1}) ' is: ' num2str(ntrigger(2)) '\n']);
% device2.Disconnect();
otherwise
disp('System is not ready to connect to more than 2 devices');
end
%device1.Disconnect();
%device2.Disconnect();
%delete(deviceList);
%delete(device);
Robert
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Robert,
the
You should only enqueue data when there is enough space in the queue.
The PROG LED does not have any function in streaming mode.
Hope this will solve your problem.
Regards,
Peter
the
- Code:
device1.GetDataQueueSpace
- Code:
device1.EnqueueData
- Code:
space(channel)=device1.GetDataQueueSpace(channel-1);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:) = device1.EnqueueData(channel-1,data2channels);
You should only enqueue data when there is enough space in the queue.
The PROG LED does not have any function in streaming mode.
Hope this will solve your problem.
Regards,
Peter
Peter MCS- Posts : 16
Join date : 2011-10-04
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Peter,
I managed to test the example C# project. It worked fine. I could see the sine waves on each channel having different phases as they supposed to be.
Regards,
Robert
I managed to test the example C# project. It worked fine. I could see the sine waves on each channel having different phases as they supposed to be.
Regards,
Robert
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Dear Peter,
I continued to work on the script. Unfortunately, I don't have any good news. The suggestions you made did not work.
The list of changes made (see the code below):
1) added channel-1 parameters based off of your previous suggestion
2) buffer free space check (while loop has been added to make sure there is enough space in the buffer)
3) added a new variable (spaceAfterEnq) to keep track of the space in the buffer (if the EnqueData function was executed appropriately then in each loop (repeated 50 times) the space remaining in the buffer should decrease by the number of samples of the inputSignal (1000)). See the outcome below.
A) current script -> Figure1
B) current script without data type conversion (NET.convertArray) -> Figure2
C) current script modified based on your previous suggestion (using channel-1 parameters in en-queuing and in space checks) -> Figure3
I also print screened the work spaces for each method (see the pictures). There was only one difference between them. This was related to the spaceAfterEnq (see Figure4 cases A & B and Figure5 - case C) variable. In Figure5 you can see that starting from loop #14 the decrease was no longer equal to 1000. The reason is unknown. In the other two cases within each loop the space remaining in the buffer was decreased by 1000 as expected.
The good news is that we saw that there was no issue with the buffering since the space was decreased appropriately. The bad news is that we still don't have anything on the output.
By clicking on the link you can find the pictures:
Figure 1-5
Regards,
Robert
I continued to work on the script. Unfortunately, I don't have any good news. The suggestions you made did not work.
The list of changes made (see the code below):
1) added channel-1 parameters based off of your previous suggestion
2) buffer free space check (while loop has been added to make sure there is enough space in the buffer)
3) added a new variable (spaceAfterEnq) to keep track of the space in the buffer (if the EnqueData function was executed appropriately then in each loop (repeated 50 times) the space remaining in the buffer should decrease by the number of samples of the inputSignal (1000)). See the outcome below.
- Code:
%% Signal generation
i=0:999;
for channel =1:Channels
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
end
[row col]=size(inputSignal); % col = number of samples on a single channel
%%
%% Start looping depending on free space in the buffer
device1.StartLoop();
device1.SendStart(1);
for channel = 1:Channels
space(channel)=device1.GetDataQueueSpace(channel);
%space(channel)=device1.GetDataQueueSpace(channel-1);
loop = 1;
while loop<space(channel)/1000
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
%data2channels = inputSignal(channel,:);
%device1.EnqueueData(channel,data2channels);
enqued(channel,:) = device1.EnqueueData(channel,data2channels);
spaceAfterEnq(channel,loop) = device1.GetDataQueueSpace(channel);
%enqued(channel,:) = device1.EnqueueData(channel-1,data2channels);
%spaceAfterEnq(channel,loop) = device1.GetDataQueueSpace(channel-1);
loop = loop+1;
end
end
%%
A) current script -> Figure1
B) current script without data type conversion (NET.convertArray) -> Figure2
C) current script modified based on your previous suggestion (using channel-1 parameters in en-queuing and in space checks) -> Figure3
I also print screened the work spaces for each method (see the pictures). There was only one difference between them. This was related to the spaceAfterEnq (see Figure4 cases A & B and Figure5 - case C) variable. In Figure5 you can see that starting from loop #14 the decrease was no longer equal to 1000. The reason is unknown. In the other two cases within each loop the space remaining in the buffer was decreased by 1000 as expected.
The good news is that we saw that there was no issue with the buffering since the space was decreased appropriately. The bad news is that we still don't have anything on the output.
By clicking on the link you can find the pictures:
Figure 1-5
Regards,
Robert
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
- Code:
asm = NET.addAssembly('i:\UofA\Projects\MultipleStimulators\McsUsbNetPackage\McsUsbNet.dll');
import Mcs.Usb.*;
deviceList = CMcsUsbListNet();
deviceList.Initialize(DeviceEnumNet.MCS_STG_DEVICE);
number_devices_connected = deviceList.GetNumberOfDevices();
SerialNumber = cell(number_devices_connected,1);
fprintf('Found %d STGs\n', number_devices_connected);
for i=1:number_devices_connected
SerialNumber{i,1} = char(deviceList.GetUsbListEntry(i-1).SerialNumber);
fprintf('Serial Number: %s\n', SerialNumber{i,1});
end
switch number_devices_connected
case 1
% 1st device
Channels = 8;
device1 = CStg200xStreamingNet(50000);
device1.Connect(deviceList.GetUsbListEntry(0));
device1.EnableContinousMode();
device1.SetOutputRate(50000);
ntrigger(number_devices_connected) = device1.GetNumberOfTriggerInputs();
fprintf(['Number of Triggers for ' num2str(SerialNumber{1,1}) ' is: ' num2str(ntrigger(1)) '\n']);
channelmap=zeros(1,ntrigger(number_devices_connected));
syncoutmap=zeros(1,ntrigger(number_devices_connected));
digoutmap=zeros(1,ntrigger(number_devices_connected));
autostart=zeros(1,ntrigger(number_devices_connected));
callbackThreshold=zeros(1,ntrigger(number_devices_connected));
channelmap(1)=255; % assign all channels to trigger 1
callbackThreshold(1)=50;
device1.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'))
for k = 1:number_devices_connected
if ~strcmp(SerialNumber(k,1),'9027-0077')
device1.SetCurrentMode();
end
end
i=0:999;
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel-1);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:)=device1.EnqueueData(channel-1,data2channels);
end
device1.StartLoop();
device1.SendStart(1);
for loop = 1:36
for channel =1:Channels
space(channel)=device1.GetDataQueueSpace(channel-1);
inputSignal(channel,:) = 1*((2^15-1)*sin(2*i*pi/1000*(channel+1)));
data2channels = NET.convertArray(inputSignal(channel,:),'System.Int16');
enqued(channel,:) = device1.EnqueueData(channel-1,data2channels);
end
end
case 2
% % 1st device
% device1 = CStg200xStreamingNet(50000); % device object
% device1.Connect(deviceList.GetUsbListEntry(0));
% device1.EnableContinousMode();
% device1.SetOutputRate(50000);
% ntrigger(number_devices_connected-1) = device1.GetNumberOfTriggerInputs();
% fprintf(['Number of Triggers for ' num2str(SerialNumber{1,1}) ' is: ' num2str(ntrigger(1)) '\n']);
% device1.Disconnect();
%
% % 2nd device
% device2 = CStg200xStreamingNet(50000); % device object
% device2.Connect(deviceList.GetUsbListEntry(1));
% device2.EnableContinousMode();
% device2.SetOutputRate(50000);
% ntrigger(number_devices_connected) = device2.GetNumberOfTriggerInputs();
% fprintf(['Number of Triggers for ' num2str(SerialNumber{2,1}) ' is: ' num2str(ntrigger(2)) '\n']);
% device2.Disconnect();
otherwise
disp('System is not ready to connect to more than 2 devices');
end
%device1.Disconnect();
%device2.Disconnect();
%delete(deviceList);
%delete(device);
could you try the script as it is above?
Regards,
Peter
Peter MCS- Posts : 16
Join date : 2011-10-04
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Peter,
The only modification was the addition of the code below. Is this correct?
At the same time I also tried to use the current script and modified the SetupTrigger function by doing the data type conversion. Nothing has appeared on the outputs either.
Best,
Robert
PS.: Why have you suggested to use the older script and not the new one including the memory check and the new variable (see previous post of mine)? Based on the C# example this should work since they have the same effect.
The only modification was the addition of the code below. Is this correct?
- Code:
device1.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'))
At the same time I also tried to use the current script and modified the SetupTrigger function by doing the data type conversion. Nothing has appeared on the outputs either.
Best,
Robert
PS.: Why have you suggested to use the older script and not the new one including the memory check and the new variable (see previous post of mine)? Based on the C# example this should work since they have the same effect.
Robcsy83- Posts : 21
Join date : 2013-05-21
Re: Problems with Matlab control of STG4008 based on the latest McsUsbNet.dll compiled in .Net
Hi Peter,
I have a good news.
By adding the code parts below now I can see the sine waves on each channel for a short time period.
I continue to work on this and will let you know my progress. The next time I'll be back perhaps I'm going to ask further questions.
Thank you for your help so far.
I have a good news.
By adding the code parts below now I can see the sine waves on each channel for a short time period.
I continue to work on this and will let you know my progress. The next time I'll be back perhaps I'm going to ask further questions.
Thank you for your help so far.
- Code:
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)));
callbackThreshold=uint32(zeros(1,ntrigger(number_devices_connected)));
- Code:
device1.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'));
- Code:
device1.SendStart(uint32(1));
Robcsy83- Posts : 21
Join date : 2013-05-21
Similar topics
» Setup the memory layout of the STG 4008 using Matlab?
» Problems with STG4002 control by McsUsbNET.dll
» Problems with Matlab-MEX files (McsUsbDLL.h) on 64Bit for STG400x
» Some problems
» MC RACK stops recording - Electrode Raw data in watchog
» Problems with STG4002 control by McsUsbNET.dll
» Problems with Matlab-MEX files (McsUsbDLL.h) on 64Bit for STG400x
» Some problems
» MC RACK stops recording - Electrode Raw data in watchog
Permissions in this forum:
You cannot reply to topics in this forum