LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array problems with Labview CIN

This is a little portion of a huge vi. What I need to do is:

Big Picture: Use Serial Communications and build a data string from a whole lot of boolean values and float values.

Small Picture: Set an array element equal to a computed value (var name is "byte").

For some reason when I write my CIN it either doesnt change the value or it crashes. I have included my vi and .c file. Can someone let me know what I am doing wrong? The reason I need this is I have about 200 bool and 100 float values I need converted into a byte array, I thought it'd be easier to do in C rather than have 10000000 wires and blocks in Labview. I plan on daisy chaining a lot of these CIN's to build my array. If this is a bad idea let me know, but more importantly my question is:

Question 1: How do I set an array element equal to a value(uInt8)?
Question 2: Why does this program crash?
Question 3: The array size at the end needs to be 172 elements(uInt8) do I set this at the beginning with init array or what?

Comment: The way Labview passes your array to a function is not very intuitive and not well documented, I have looked all over the "Using External Code in LabVIEW" and can't answer my questions. Maybe I just missed it. I appreciate anyone who has taken the time to read this and would like to thank in advance those of you that reply.

Cason
SwRI

VS .Net 2003
Win XP
Labview 7

Cason Clagg
SwRI
LabView 7.1, Windows XP
Message 1 of 3
(2,823 Views)
I have a few remarks to your post:

1) For serial (or TCP/IP, GPIB, etc, even USB since VISA 3.1) communication of any kind it is almost never ever necessary to use CINs or other external code in LabVIEW. LabVIEW has all the bit manipulation tools on board you might possibly need. Your particular function you try to solve in your CIN is simply done for you by the LabVIEW function Boolean Array To Number in the Boolean function palette.

2) Creating CINs is highly discouraged nowadays. Creating DLLs instead and linking them into LabVIEW with the Call Library Node is not anymore difficult and in fact better supported by NI nowadays. It gives you much more choice of your development platform/IDE for the external code, usually is a more commonly known
target to create and has less LabVIEW specific difficulties to get started with and also to get it working. CINs are slowly fading away and the version of LabVIEW where support to create CINs will not anymore be available at least out of the box is probably not that far away (although I would advise NI to not remove runtime support of CINs for the next few years).

3) If you pass in an array to be worked on in the CIN you either must create a big enough array on the LabVIEW diagram with "Initialize Array" for instance or use functions like NumericArrayResize() in the C code to make sure the handle is large enough to access the [*count] element in the embedded pointer.

4) While it may seem not very clear what a handle is and how it works at first the declarations you get in your C code together with a good understanding of how C compilers work, are really all that is necessary to understand what happens. While there exist some LabVIEW manuals and tutorials to tell you some of the basics of these things, it can not be the intention to teach you every aspect of C in them. If you want to write DLLs (or CINs which is really not anymore different) you should understand those basics and if you don't, learn them from a book or course which is specifically meant to teach you about C programming concepts.

I have used a German book "C Programmieren, Ein Kurs zum Selbststudium mit Musterloesungen" by Guido Krueger from Addison-Wesley as well as "Teach Yourself C" by Herbert Schildt from Osborne McGraw-Hill mostly for the C programming part and use "C, A reference Manual" by Samual P. Harbison and Guy L.Steele Jr. from Prentice Hall regularly as a reference, if I need to look up things like operator precedence and ANSI C function semantics.

There are certainly other English books for a good introduction into C programming, which also explain more advanced techniques like pointers and all kind of pointer operations/arithmetic etc. Which book might be the best for you depends a lot on your style of learning. Some prefer reference manuals where they can easily lookup things when they arise, others prefer a paced step by step course to work through. I think that Addison-Wesley, Prentice Hall and McGraw-Hill have usually guite good and useful books about programming topics, which doesn't say that there are no others, but these are the ones I have regularly come across in the past when looking for programming books of all kinds.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 3
(2,811 Views)
I figured out the problem. Lots of small mistakes all over the place, I don't even recall what they were.

Thanks

Cason Clagg
SwRI
LabView 7.1, Windows XP
Message 3 of 3
(2,795 Views)