this is my first topic if anything wrong please advise me.
I am not a great matlab user but I need to use matlab with sensoray 826 to capture the data.
However, once I install the driver and try to run 826 Matlab demo I got the error code below.
Warning: Warnings messages were produced while parsing. Check the functions you intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
I try to find the root cause of this problem and get new error.
[notfound, warnings] = loadlibrary('C:\Program Files (x86)\Sensoray\826\API\x64\s826.dll')
Error using loadlibrary
There was an error loading the library "C:\Program Files (x86)\Sensoray\826\API\x64\s826.dll"
Unrecognized function or variable 's826_proto'.
Caused by:
Error using feval
Unrecognized function or variable 's826_proto'.
At this point I believe that the error is cause from incorrect DLL file from the sensoray.
I try to contact the Sensoray but they rarely answer back to me.
If anyone know how to solve this issue please kindly reply back to me.
The code I use to run in Matlab:
% Load the 826 API and open a connection to the 826 board
dllPath = 'C:\Program Files (x86)\Sensoray\826\API\x64\s826.dll'; % Replace with the correct path to the DLL file
hdrPath = 'C:\Program Files (x86)\Sensoray\826\API\826api.h'; % Replace with the correct path to the header file
[errcode, boardflags] = s826.SystemOpen(dllPath, hdrPath);
if errcode ~= 0
error('Error opening connection to 826 board: %d', errcode);
end
% Configure the rotary sensor
counter = 0; % Choose the counter that the rotary sensor is connected to (0-3)
s826.CounterModeWrite(counter, s826.CNTR_QUADX4); % Configure the counter for quadrature input
s826.CounterPreloadWrite(counter, 0, 0); % Reset the counter
% Read the counter value
count = s826.CounterRead(counter);
% Close the connection to the 826 board
s826.SystemClose();
I would like to go step by step since I never use this 826 cards before.
So first just correctly call the DLL and H file is enough for me.
Related
I have this code that is supposed to change the referenced subsystems in a model to normal subsystems, because I have another script that no longer works on matlab 2020, only on 2017, due to the change of the applications libraries to referenced subsystems. When I run it, I get multiple:
*** W02293: SIMULINK DATA TYPE RESTRICTIONS:
*** Could not perform min/max logging or overflow detection for signal.
*** The ufix1 Simulink data type is not supported.
Followed by:
Error using change (line 4)
Invalid Simulink object handle
Anybody know why? I use the version Matlab R2020b with TargetLink 5.1p1
refSubsystem = 'subsys20b';
modelName = 'modelRefSubsys20b';
open_system("Application Name");
oldBlock = [ modelName '/Subsystem Reference'];
newBlock = [ modelName '/subsystem'];
% create a copy of the referenced subsystem
add_block('built-in/Subsystem', newBlock)
Simulink.BlockDiagram.copyContentsToSubsystem(refSubsystem, newBlock)
% Retrieve useful info from the old block
t1 = get_param(oldBlock, 'Portconnectivity');
t2 = get_param(oldBlock, 'PortHandles');
t3 = get_param(newBlock, 'PortHandles');
% delete old lines
h = get_param(oldBlock, 'LineHandles');
ni = numel(h.Inport);
no = numel(h.Outport);
delete_line(h.Inport);
delete_line(h.Outport);
% create connections to new block
for i=1:numel(t2.Inport)
srcBkhdl = t1(i).SrcBlock; % source block handle
srcNm = getfullname(srcBkhdl); % source block name
srcBkPts = get_param(srcNm, 'PortHandles'); % source block port handles
srcPt = srcBkPts.Outport(t1(i).SrcPort+1); % source port
dstPt = t3.Inport(i); % destination port
add_line(modelName, srcPt, dstPt);
end
% create connections from new block
for i=1:numel(t2.Outport)
dstBkhdl = t1(ni+i).DstBlock; % dest block handle
dstNm = getfullname(dstBkhdl); % dest block name
dstBkPts = get_param(dstNm, 'PortHandles'); % dest block port handles
dstPt = dstBkPts.Inport(t1(ni+i).DstPort+1); % dest port
srcPt = t3.Outport(i); % src port
add_line(modelName, srcPt, dstPt);
end
% copy to same position
pos = get_param(oldBlock, 'position');
set_param(newBlock, 'position', pos);
% remove old block
delete_block(oldBlock);
% save changes
save_system(modelName);
I just had a similar error wanting to revert Referenced Subsystems to simple Subsystems. In my case however, I did not want to do that programmatically.
I use MATLAB2021a and had a project initializing the Search Paths.
Removing the Referenced Subsystem link from the Block Parameters raised:
Invalid Simulink object handle
and prevented me to save the model.
The workaround that I found was:
To open the model without loading my project. Not loading the project prevented the Referenced Subsystem from loading since it couldn't find its referenced file. In someone else's case, one could simply move the referenced file outside of your Search Path.
Remove the link to the referenced file. I found that doing this after failing to load did not cause the same error.
Once the link removed, it is safe to open said referenced file, copy its content and paste it in the now simple subsystem block.
Save
I am aware that you wanted to perform this programmatically and I hope this helps you or someone else. Keep in mind, I am no expert. I simply messed around and found something that worked for me.
as the title says...
I want to check the SBR register of device connected over GPIB. I am interested in reading the MAV bit 4, which should be set if instrument has something it would like to send me.
The problem is, that in order to check the SBR, I inevitably have to send another query (*STB?), which clears the device output buffer by default. In other words, whenever I check if there is something to read, I remove it just by looking. Here is code to reproduce it, problem is at the last call to fscanf():
>> fid = gpib('agilent', 7, 26);
>> fopen(fid)
>> fprintf(fid, '*SRE 255; *SRE?') % Enable everything in SBR
>> fscanf(fid) % Returns +191 as expected (255 - 64 for MSS)
>> fprintf(fid, '*IDN?') % Make any query...
>> fprintf(fid, '*STB?') % Read SBR
% The line above generates device Query Error (beep)
>> fscanf(fid) % << Returns +0 !!!
>> fclose(fid) % Just to prevent flames :]
I suspect, that there is some way to check the SBR without querying the device, but I could not find anything. MATLAB help for VISA drivers is silent on the topic of communicating directly with the driver or the bus.
I also tried to check for BusManagementStatus with no avail.
For reference, I am using MATLAB R2011b, with 32-bit Agilent VISA drivers, and the GPIB enabled device is Agilent E4980A LCR Meter. Thanks for any help.
OK, I think that I figured it out. Please correct me if I am wrong...
First of all I need to anticipate the need to check for available message, because in my solution I won't be able to check for Error Queue, Master Summary, and other bits, that are set in SBR.
Then, before my actual commands (that may produce some output), I need to mask the Service Request Enable Register (SRER) to only allow MAV bit. Thats done like so (following from example in question):
>> fprintf(fid, '*SRE 16');
>> fprintf(fid, '...ACTUAL COMMANDS THAT ARE TO BE EXECUTED...');
Now I can check, whether the device sends a service request, using the aforementioned BusManagementStatus command. The following command returns true iff there is MAV bit set in SBR.
>> strcmp(fid.BusManagementStatus.ServiceRequest, 'on')
The disadvantage is that there is no way to check for errors during my ACTUAL COMMANDS execution. If I do so, it might produce errors... :]
I asked today a question about Parallel Computing with Matlab-Simulink. Since my earlier question is a bit messy and there are a lot of things in the code which doesnt really belong to the problem.
My problem is
I want to simulate something in a parfor-Loop, while my Simulink-Simulation uses the "From Workspace" block to integrate the needed Data from the workspace into the simulation. For some reason it doesnt work.
My code looks as follows:
load DemoData
path = pwd;
apool = gcp('nocreate');
if isempty(apool)
apool = parpool('local');
end
parfor k = 1 : 2
load_system(strcat(path,'\DemoMDL'))
set_param('DemoMDL/Mask', 'DataInput', 'DemoData')
SimOut(k) = sim('DemoMDL')
end
delete(apool);
My simulation looks as follows
The DemoData-File is just a zeros(100,20)-Matrix. It's an example for Data.
Now if I simulate the Script following error message occures:
Errors
Error using DemoScript (line 9)
Error evaluating parameter 'DataInput' in 'DemoMDL/Mask'
Caused by:
Error using parallel_function>make_general_channel/channel_general (line 907)
Error evaluating parameter 'DataInput' in 'DemoMDL/Mask'
Error using parallel_function>make_general_channel/channel_general (line 907)
Undefined function or variable 'DemoData'.
Now do you have an idea why this happens??
The strange thing is, that if I try to acces the 'DemoData' inside the parfor-Loop it works. For excample with that code:
load DemoData
path = pwd;
apool = gcp('nocreate');
if isempty(apool)
apool = parpool('local');
end
parfor k = 1 : 2
load_system(strcat(path,'\DemoMDL'))
set_param('DemoMDL/Mask', 'DataInput', 'DemoData')
fprintf(num2str(DemoData))
end
delete(apool);
Thats my output without simulating and displaying the Data
'>>'DemoScript
00000000000000000 .....
Thanks a lot. That's the original question with a lot more (unnecessary) details:
EarlierQuestion
I suspect the issue is that when MATLAB is pre-processing the parfor loop to determine what variables need to be passed to the workers it does not know what DemoData is. In your first example it's just a string, so no data gets sent over. In your second example it explicitly knows about the variable and hence does pass it over.
You could try either using the Model Workspace, or perhaps just inserting the line
DemoData = DemoData;
in the parfor loop code.
Your error is because workers did not have access to DemoData in the client workspace.
When running parallel simulations with Simulink it would be easier to manage data from workspace if you move them to model workspace. Then each worker can access this data from its model workspace. You can load a MAT file or write MATLAB code to initialize data in model workspace. You can access model workspace using the Simulink model menu View->Model Explorer->Model Workspace.
Also see documentation at http://www.mathworks.com/help/simulink/ug/running-parallel-simulations.html that talks about "Resolving workspace access issues".
You can also move the line
load DemoData
to within the parfor loop. Doing this, you assure that the data will be available in each worker base workspace, wich is accessible to the model, instead of the client workspace.
I have a ".mat" file supposedly containing a [30720000x4 double] matrix (values from accelerometers). When I try to open this file with "Import data" in Matlab I get the following error:
Error using load
Can't read file F:\vibration_exp_2\GR_UB50n\bearing1\GR_UB50n_1_2.mat.
Error using load
Unknown text on line number 1 of ASCII file
F:\vibration_exp_2\GR_UB50n\bearing1\GR_UB50n_1_2.mat
"MATLAB".
Error in uiimport/runImportdata (line 456)
datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 424)
[datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath,
type);
Error in uiimport (line 240)
[ctorPreviewText, ctorHeaderLines, ctorDelim] = ...
The filesize is 921MB which is the same as my other files that do open. I also tried opening the file using python, but no success. Any suggestions? I use MATLAB R2013b .
More info:
How the file was create:
%% acquisition of vibration data
% input:
% sample rate in Hz (max. 51200 Hz, should be used as bearing
% faults are high-frequent)
% time in seconds, stating the duration of the measurement
% (e.g. 600 seconds = 10 minutes)
% filename for the file to be saved
%
% examples:
% data = DAQ(51200, 600, 'NF1_1.mat');
% data = DAQ(51200, 600, 'NF1_2.mat');
function data = DAQ(samplerate,time,filename)
s = daq.createSession('ni'); % Creates the DAQ session
%%% Add the channels as accelerometer channels (meaning IEPE is turned on)
s.addAnalogInputChannel('cDAQ1Mod1','ai0','Accelerometer');
s.addAnalogInputChannel('cDAQ1Mod1','ai1','Accelerometer');
s.addAnalogInputChannel('cDAQ1Mod1','ai2','Accelerometer');
s.addAnalogInputChannel('cDAQ1Mod1','ai3','Accelerometer');
%s.addAnalogInputChannel('cDAQ1Mod2','ai0','Accelerometer');
s.Rate = samplerate;
s.NumberOfScans = samplerate*time;
%%% Defining the Sensitivities in V/g
s.Channels(1).Sensitivity = 0.09478; %31965, top outer
s.Channels(2).Sensitivity = 0.09531; %31966, back outer
s.Channels(3).Sensitivity = 0.09275; %31964, top inner
s.Channels(4).Sensitivity = 0.09363; %31963, back inner
data = s.startForeground(); %Acquiring the data
save(filename, 'data');
More info:
When I open the file using a simple text editor I can see a lot of characters that do not make sense but also the first line:
MATLAB 5.0 MAT-FILE, Platform: PCWIN64, Created on: Thu Apr 30
16:29:07 2015
More info:
The file itself: https://www.dropbox.com/s/r7mavil79j47xa2/GR_UB50n_1_2.mat?dl=0
It is 921MB.
EDIT:
How can I recover my data?
I've tried this, but got memory errors.
I've also tried this, but it did not work.
I fear I can't add many good news to what you know already, but it hasn't been mentioned yet.
The reason the .mat-file can't be load is due to the data beeing corrupted. What makes it 'unrecoverable' is the way it is stored internally. The exact format is specified in the MAT-File Format Documentation. So I decided to manually construct a simple reader to specifically read your .mat file.
It makes sense, that the splitmat.m can't recover anything, as it will basicly split the data into chunks, one stored variable per chunk, however in this case there is only 1 variable stored and thus only one chunk, which happens to be the corrupted one.
In this case, the data is stored as a miCOMPRESSED, which is a normal matlab array compressed using gzip. (Which, as a side note, doesn't seem like a good fit for 'random' vibration data.) This might explain previous comments about the smaller file size then the full data, as the filesize matches exatly with the internally stored value.
I extracted the compressed archive and tried to uncompress it in a variety of ways. Basicly it is a '.gz' without the header, that can be appended manually. Unfortunatly there seems to be a corrupted block near the start of the dataset. I am by no means an expert on gzip, but as far as I know the dictionary (or decryption key) is stored dynamicly which makes all data useless from the point the block is corrupted. If you are really eager, there seems to be a way to recover data even behind the point where data is corrupted, but that method is massively timeconsuming. Also the only way to validate data of those sections is manual inspection, which in your case might proof very difficult.
Below is the code, that I used to extract the .gz-file, so if you want to give it a try, this might get you started. If you manage to decrypt the data, you can read it as described in the MAT-File Format, 13f.
corrupted_file_id = fopen('corrupt.mat','r');
%% some header data
% can be skipped replacing this block with
% fread(id,132);
%header of .mat file
header_text = char(fread(corrupted_file_id,116,'char')');
subsystem_data_offset = fread(corrupted_file_id,8,'uint8');
version = fread(corrupted_file_id,1,'int16');
endian_indicator = char(fread(corrupted_file_id,2,'int8')');
data_type = fread(corrupted_file_id,4,'uint8');
%data_type is 15, so it is a compressed matlab array
%% save te content
data_size = fread(corrupted_file_id,1,'uint32');
gz_file_id = fopen('compressed_array.gz','w');
% first write a valid gzip head
fwrite(gz_file_id,hex2dec('1f8b080000000000'),'uint64',0,'b');
% then write the data sequentialy
step = 1:1e3:data_size;% 1MB steps
for idx = step
fwrite(gz_file_id,fread(corrupted_file_id,1e3,'uint8'));
end
step = step(end):data_size;% 1B steps
for idx = step
fwrite(gz_file_id,fread(corrupted_file_id,1,'uint8'));
end
fclose(gz_file_id);
fclose(corrupted_file_id);
To answer literally to the question, my suggestion would be to make sure first that the file is okay. This tool on File Exchange apparently knows how to diagnose corrupted .MAT files starting with version V5 (R8):
http://www.mathworks.com/matlabcentral/fileexchange/6893-matcat-mat-file-corruption-analysis-tool
The file's size (indices going out of range) seems to be a problem. Octave, which should read .mat files, gives the error
memory exhausted or requested size too large for range of Octave's index type
To find out what is wrong you may need to write a test program outside MatLab, where you have more control over memory management. Examples are here, including instructions on how to build them on your own platform. These stand-alone programs may not have the same memory issues. The program matdgns.c is specifically made to check .mat files for errors.
I have used the vlfeat toolbox and the vl_sift, lot of times with no problem. I decided to use it in Matlab R2009a, with ubuntu 14.04. This is the error I get while running vl_setup()
??? XML-file failed validation against schema located in:
/home/tonystark/Matlab_prg/sys/namespace/info/v1/info.xsd
XML-file name:
/home/tonystark/freelancing/Content_based_image_retrieval/code/new_code/vlfeat-0.9.18/toolbox/info.xml
To retest the XML-file against the schema, call the following java method:
com.mathworks.xml.XMLValidator.validate(...
'/home/tonystark/freelancing/Content_based_image_retrieval/code/new_code/vlfeat-0.9.18/toolbox/info.xml',...
'/home/tonystark/Matlab_prg/sys/namespace/info/v1/info.xsd', true)
Errors:
org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found
starting with element 'help_contents_icon'. One of '{product_name_ends_with_type,
help_addon, preference_panel, dialogpref_registrar, project_plugin, state_item, list}'
is expected.
But when I run the same code again, the error doesn't come and the code vl_setup compiles, but no output displayed
And when I run this sample code
clc;
close all;
clear all;
I1 = imread('/home/tonystark/freelancing/Content_based_image_retrieval/Dataset/all_souls_000140.jpg');
I2 = imread('/home/tonystark/freelancing/Content_based_image_retrieval/Dataset/all_souls_000146.jpg');
[f1 d1] = vl_sift(single(rgb2gray(I1)));
[f2 d2] = vl_sift(single(rgb2gray(I2)));
matlab crashes with the following error on the terminal
*** invalid %N$ use detected ***
Aborted (core dumped)
I am stuck here for quite some time without any specific direction. If somebody can point me in the right direction or solve this, it would be of great help! Your help is much appreciated.
UPDATE 1
The readme file of vlfeat says it requires matlab 2009b min, for the toolbox to work. could that be a reason?