LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use an error handler to save data

I am new to CVI (from LabVIEW background). I am having trouble working through the example manual saving my data. The example from the website works great (Get project directory, make path, etc.) However, I cannot seem to create my own path (example c:\windows\desktop\testfile.dat) to save to. I always get errors. I thought I could use an error handler (if the file does not exist then create it else open it). I know this is a very simple thing to do so I am naturally getting very frustrated. I would appreciate any help
0 Kudos
Message 1 of 3
(3,055 Views)
Hi,

My project involves to save data to file. and I do not have any problem. Yes there's a handler. I'll try to help you with some code. I don't know how well is your C programming. If you need more help. Ask me 🙂

what I'm doing here is that your Application will ask you to specify the file with a Savepopup panel.

static int data[5]={0,1,2,3,4};
FP * FilePointer; // Declaration of a file pointer
// open the file in BINARY mode
if((FilePointer = fopen("temp.dat", "wb")) == NULL)
{
MessagePopup("Error", "Can't create the file");
}
else
{
// your code here....
fwrite (data, sizeof(int), 5, FilePointer);
// if you open your file you will see 1,2,3,4 in INT format
}

I suggest you to download the HEXworkshop software so you can see the conte
nts of your file. And work with it
go to www.bpsoft.com

I hope I could help, any more questions ?
0 Kudos
Message 2 of 3
(3,055 Views)
I noticed that you used single backslashes in your path and I wonder if that may be causing you some problem. Depending on how you use it, you often need to use double backslashes (\\) to indicate a directory. Otherwise the compiler thinks you're using an escape command. Also, you mentioned the use of GetProjectDirectory and MakePathname. They can be very useful. Here's a simple example that gets the current directory, and then appends a Help directory and sets a global string to hold the path of the help file as CurrentDir\Help\MyHelp.hlp:

g_szHelpFilePath[MAX_PATHNAME_LEN]; //Declared globally

char szHomeDir[MAX_PATHNAME_LEN]; // Declared locally

GetProjectDir (szHomeDir);

// You can use the Fmt() function:
Fmt(g_szHelpFilePath, "%s<%s\
\Help\\MyHelp.hlp", szHomeDir);

// Or use the MakePathname() function
nStatus = MakePathname (szHomeDir, "\\Help\\MyHelp.hlp", g_szHelpFilePath);

Hope this helps.
Message 3 of 3
(3,055 Views)