LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CIN with simplest array?

ok i walk through PDF's, saw some examples but i still don't understand, how to work with the simplest arrays in CIN. Problem is: i want that Labview read data from CIN and fill the 1D array. For example in my C code array declared as "unsigned char *Array1[7]" and after that i specify Array1[0] =6; Array1[1] = 4; Array1[2] = 23; ......... Array[6] = 12; So i created a CIN block, and wired it to Array numeric indicator and created .c file that looks like:

==================
/* CIN source file */

#include "extcode.h"

/* Typedefs */

typedef struct {
    int32 dimSize;
    float64 Numeric[1];
    } TD1;
typedef TD1 **TD1Hdl;

MgErr CINRun(TD1Hdl Array);

MgErr CINRun(TD1Hdl Array)
    {

    /* Insert code here */

    return noErr;
    }
=================
Now, how to fill in this Labview array, with my values of "Array1" ?

2) Second question is, i have a program that reads data from PCIe board memory and returns it in pointer "ptr_to_pci_mem = (unsigned char *) mmap(NULL, PCI_MEM_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)pci_mem_addr);"

How can I read data from this memory mmaped pointer and fill Labview 1D array with those values ?
Please help, thank you in advance.
0 Kudos
Message 1 of 26
(3,692 Views)
???
0 Kudos
Message 2 of 26
(3,654 Views)


@bi wrote:
ok i walk through PDF's, saw some examples but i still don't understand, how to work with the simplest arrays in CIN. Problem is: i want that Labview read data from CIN and fill the 1D array. For example in my C code array declared as "unsigned char *Array1[7]" and after that i specify Array1[0] =6; Array1[1] = 4; Array1[2] = 23; ......... Array[6] = 12; So i created a CIN block, and wired it to Array numeric indicator and created .c file that looks like:

==================
/* CIN source file */

#include "extcode.h"

/* Typedefs */

typedef struct {
    int32 dimSize;
    float64 Numeric[1];
    } TD1;
typedef TD1 **TD1Hdl;

MgErr CINRun(TD1Hdl Array);

MgErr CINRun(TD1Hdl Array)
    {

    /* Insert code here */

    return noErr;
    }
=================
Now, how to fill in this Labview array, with my values of "Array1" ?

2) Second question is, i have a program that reads data from PCIe board memory and returns it in pointer "ptr_to_pci_mem = (unsigned char *) mmap(NULL, PCI_MEM_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)pci_mem_addr);"

How can I read data from this memory mmaped pointer and fill Labview 1D array with those values ?
Please help, thank you in advance.


Have you actually read the External Code Reference Manual? Do you understand basic memory mangement concepts of C? Based on your questions I doubt both and then things will get hairy anyhow eventually.

As to your actual problem:

#include "extcode.h"

unsigned char Array1[7] = {6, 4, 23, ..., 12};

/* Typedefs */

typedef struct {
    int32 dimSize;
    float64 Numeric[1];
    } TD1;
typedef TD1 **TD1Hdl;

MgErr CINRun(TD1Hdl Array);

MgErr CINRun(TD1Hdl Array)
{
    int32 i = 7;
    MgErr err = NumericArrayResize(fD, 1, &Array, i);

    if (err)
       return err;

    (*Array)->dimSize = i;

    for (; i; i--) {
       (*Array)->Numeric[i] = Array1[i];
   
    return noErr;
}

Please note that you create an array of type char but assigin it to a LabVIEW array of type double. Will work in principle but it's likely that this is not what you really want to implement in a real world scenario.

For the memory mapped pointer you can't pass that to LabVIEW directly. You will have to size a passed in array similar to what you can see above and then using MoveBlock() copy the data from the memory pointer into the LabVIEW array handle.

And don't be impatient! You haven't let even 24 hours go over it before asking ???

Rolf Kalbermatter


Message Edited by rolfk on 02-27-2008 10:27 AM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 26
(3,652 Views)
sorry, thanks for an example, but I got message while building CIN: " error: incompatible type for argument 3 of ‘NumericArrayResize’" and after running LabView crashes
0 Kudos
Message 4 of 26
(3,628 Views)
now program code looks like:

#include "extcode.h"

/* Typedefs */

typedef struct {
    int32 dimSize;
    int32 Numeric[1];
    } TD1;
typedef TD1 **TD1Hdl;

MgErr CINRun(TD1Hdl Array);

MgErr CINRun(TD1Hdl Array)
{
    int32 Array1[11] = {6, 4, 23, 44, 12, 32, 11, 21, 34, 33, 54};
   int32 i = 11;
   MgErr err = NumericArrayResize(fD, 1, &Array, i);

    if (err)
       return err;

    (*Array)->dimSize = i;

    for (i=10; i=0; i--) {
       (*Array)->Numeric[i] = Array1[i];
   }
    return noErr;
}

0 Kudos
Message 5 of 26
(3,619 Views)
after a bit of changing code, on LabView do not crash anymore, on the Block Diagram i see "#11" moves through the wire, but the Array dont fill with data
0 Kudos
Message 6 of 26
(3,618 Views)
I've modified code to:   MgErr err = NumericArrayResize(fD, 1, (UHandle*)*Array, i);
So now it works, but i got irregular data filled in Array, something like 1.E-106, 1.86... etc,
I've even tried to set all the types to "int32" but this did not help 🙂
0 Kudos
Message 7 of 26
(3,608 Views)


@bi wrote:
I've modified code to:   MgErr err = NumericArrayResize(fD, 1, (UHandle*)*Array, i);
So now it works, but i got irregular data filled in Array, something like 1.E-106, 1.86... etc,
I've even tried to set all the types to "int32" but this did not help 🙂


You changed the type def of the Handle in your C code to be an array of int32. The type you use in your C code of course should match the type you pass in from the LabVIEW diagram. You should make sure to also pass in an int32 array from the LabVIEW diagram and change the first parameter to NumericArrayResize from fD to iL.

Rolf Kalbermatter


Message Edited by rolfk on 02-28-2008 05:22 PM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 26
(3,606 Views)
Thank you! I forgot about that parameter, i will try!
0 Kudos
Message 9 of 26
(3,575 Views)
I've tried it and it also returns every time different incorrect data in array!
0 Kudos
Message 10 of 26
(3,561 Views)