09-22-2010 01:00 PM
Hello,
I am reading in data from a DAQ and am writing it to a .csv file in LabWindows/CVI. I am then sending this data to Matlab to be filtered. I would like the filtered data to be accessed by LabWindows/CVI so that I can display it as a strip chart. I have gotten everything to work except the writing to a file in a Matlab script that is called from LabWindows/CVI. I am basically using the shipped example in found in the activex demo. (http://zone.ni.com/devzone/cda/epd/p/id/2994). I select the script that I want to run and each time it tries to open a file with write permissions I get a "Permission Denied" error. This occurs when using fopen() in Matlab. I have also tried using csvwrite() as well as dlmwrite(). Each one gives me a similar error. The script currently does not try to do any data processing. It just opens the file, if it is successful it then prints "hello" and then closes it. The script works well when it is run in Matlab, just not when it is called in LabWindows/CVI. Below is the script. Any thoughts, comments or suggestions are greatly appreciated. I am also open to using other approaches for sending data between Matlab and LabWindows/CVI. Thanks in advance!!
fclose('all');
[file, errmsg] = fopen('out.txt', 'w');
if(file<0)
disp(errmsg)
else
fprintf(file, 'hello');
fclose('all');
end;
09-23-2010 03:54 PM
Hi dicksoch,
Have you considered making the matlab code into a DLL and calling the DLL from CVI instead? This might be a better approach, eliminating opening any active communication to Matlab.
09-27-2010 11:42 AM
Hello,
Thank you for your response. The problem with creating a DLL is that this application is going to be for students. These students will download a licensed version of MATLAB from the university's engineering server. This version of MATLAB does not come with the package containing mcc or even mbuild. This means one of two things. First, if I wrote the CVI application to have the user select the .m script file to run, then the application would have to compile it into a DLL. Second, if I do just have the students select the DLL to run, the students would have to compile and create a DLL, something they cannot do without mcc. Is there any other simple solution to passing data between Matlab and CVI? Also, is there any explanation for why I cannot open a file to write in Matlab when calling the script from CVI? Thanks in advance for any suggestions and help!
Chris
09-28-2010 09:33 AM
Hello Chris
What OS are you using? and are you running CVI as an administrator on this machine? I'm wondering if the lack of permissions is because CVI is running Matlab in non-administrator mode, thus limiting file access.
09-29-2010 11:03 AM
I am using Windows 7. I am running CVI as an administrator and was able to get rid of the "Permission Denied" error by going into the User Account Controls in windows and changing it to "Never Notify". However, this did not fix the problem of Matlab not being able to write to a file when the script is run from CVI. In the Matlab code below, It now gets in to the "else", suggesting that fopen() returns a good file handle. After getting in to the else statement, it will not actually write to the file, nor does it create it. However, I can make changes to the plot settings and those appear. Everything is functional when run from Matlab but when run from CVI, things get screwy with opening the file for writing. It handles the read well. It seems like there would have to be some file permission errors but, in the CVI program, I open and write to the file "in.csv". Any help is greatly appreciated.
Thanks,
Chris