I have a porblem with reading a raspberry pi file in a fuction. I get the Erro: Call to MATLAB function aborted: Invalid file identifier. Use fopen to generate a valid file identifier.
    8 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
persistent sensorPath;
if isempty(sensorPath)
path = '/sys/bus/w1/devices/10-0008032a1531';
fileSeperator = '/';
sensorPath = [path,fileSeperator,'w1_slave'];
end
% Open file, read, and close it
fid = fopen(sensorPath);
w1_slave = fread(fid,1024);
fclose(fid);
0 Kommentare
Antworten (2)
  Ankitha Kollegal Arjun
    
 am 18 Apr. 2017
        Check the value of 'fid' obtained. You can add the following lines to your code:
if fid == -1
 error('File not found')
end
If the value of fid is -1, then it is likely that the file is not located in the supplied path.
Also, check if the unique sensor ID supplied in the path (10-0008032a1531) is the right one.
0 Kommentare
  Stephen23
      
      
 am 18 Apr. 2017
        
      Bearbeitet: Stephen23
      
      
 am 18 Apr. 2017
  
      The best solution is to always return fopen's second output message, and use it to display exactly what occurred when fopen tried to open the file:
[fid,msg] = fopen(...)
assert(fid>=3,msg)
Anyone who tells you to check the value of fid but does not tell you to get the second output is only telling you half of the answer!
0 Kommentare
Siehe auch
Kategorien
				Mehr zu MATLAB Support Package for Raspberry Pi Hardware finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


