LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get CIN source code to compile because of extcode.h

I am an undergraduate doing physics research and I am quite new to both LabVIEW and C++.  I am using LabVIEW to generate an output file that contains information that a fitting program uses to make a fit.  One part of the LabVIEW program takes 8200 pieces of data and formats them in the correct way in the output file.  Unfortunately, it was taking several minutes to do this, and since I use this program about a hundred times each day it was becoming very inconvenient. 
 
So I wrote a program in C++ (Microsoft Visual C++ version 6.0) that puts this data in the output file correctly formatted and does so in a fraction of a second.  Now I would like to use a CIN to execute this program within LabVIEW.  I have two main questions:
 
1.  I have followed the steps in the "Using External Code in LabVIEW" manual through step 4.  I inserted my code, which compiles and functions properly by itself, into the /* Insert code here */ line of the .c file that was created from the CIN node, and left everything else as it is.  When I try to compile the CIN source code in Visual C++, it gives me this error: "fatal error C1083: Cannot open include file: 'extcode.h': No such file or directory  Error executing cl.exe."  Why am I getting this error?
 
2.  My C++ program doesn't require any interaction with the rest of the LabVIEW program.  Basically, it should open, write data to a file, and then close.  The rest of the LabVIEW program further modifies the file.  Is it possible to run it without any output connected to the CIN node?  If not, what changes do I have to make to my C++ code to output, say, just a string indicating the program is done running? 
 
Thank you,
Evan
0 Kudos
Message 1 of 6
(4,043 Views)

While I can't help you with the compiling error codes I will offer two comments. If you are not passing data to the CIN, if it is retrieving the data from an "unformatted" file and formatting it you could make it an executable and call it with the system exec function in LabVIEW. It does seem unusual that the LabVIEW program takes several minutes to perform this formatting and the C++ does it in a fraction of a second. I suspect that the LV could could benefit from some severe optimization that would bring down this formatting time to something you would find reasonable. If you can post the "formatting" code here a number of could look at it and either suggest ways to speed it up or as frequently happens, return the modified code. LabVIEW is a compiled language which has gotten pretty good at producing optimized machine code when it compiles (the first time it is run after making any changes for instance), but it won't optimize the source code (yet!)

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 6
(4,035 Views)

Here is the formatting code.  It executes very quickly if frames 3 and 4 of the stacked sequence structure are removed.  Frame 3 puts the data in an array and frame 4 formats it into rows with 8 pieces of data in each row.  "Channels in spectrum" is always equal to 8192.   This part of the program seemed pretty straightforward, and I'm not sure why it takes so long to run.  If there is a better way to do it, any help would be greatly appreciated. 

Evan

0 Kudos
Message 3 of 6
(4,027 Views)
Hi,
   I think we can speed this up a lot. I've only glanced at it, haven't time right this moment to "adjust" it, but see a number of areas that can be changed to speed it up a lot. First, what does the data that is being read from the file look like, "structurally"? How is the data arranged. I think that it may be able to read in using the read from spreadsheet, or at least the string to spreadsheet array functions, and then written to the file using a similar technique, which would be almost instantaneous, compared to what is currently happening. In sequence 4 you are writting one row at a time, opening the file writting and then closing, which is very time consuming. Show us what a file looks like (ideally zip a dat file, even if it isn't real data) and I think we can speed you on your way, entirely in "G" rather than C!
 
P.M.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 4 of 6
(4,019 Views)

Hi,

The data is arranged very simply with one piece of data on each line.  I've attached an example.

Thanks so much for your help.

0 Kudos
Message 5 of 6
(4,014 Views)
Your biggest problem is the constant reopening of the output file. I think if you would do that in C as well, your C code wouldn't be much faster as your LabVIEW vi. Out of personal preference I would actually never create a VI with such a large diagram, and I would get rid of the Sequence structure altogether. A While loop with a case structure inside would allow you to keep the file refnum in a shift register so that you open the output file only once only in the begin.

The biggest performance killer is in the frame where you reformat the input data into an 8 * 8192 data field to be written to the file. On every single output you open the file, write a single value and close it again. This is terribly slow. Opening it once only before the loop starts and just appending to the file will speed up things greatly.

Second you don't need to initiliaze an array and then use Replace Array in the frame before that. Just use autoindexing on loop boundery. And last but not least combining the two frames into one could allow you to completely forget about the two output array controls. That will save some memory and speed up things even more. And yes the entire operation in this case could be optimized even more by reading the file line by line and format everything into the output file as you go.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 6 of 6
(4,010 Views)