LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview can not create a control for the "data" Input of DLL

Hi All,

 

When I try to transfer text code into LabVIEW code, there is an issue for the CAN_FrameStream.dll(C# Assembly) input.

 

As you can see from the Picture:

In No1, it is the original text code to call the function "NI_CanFrameStream" in DLL. and it is successful to run, but sometimes is jammed error.

So, In No2, I try to update this code with LabVIEW. to hope to eliminate the error.

  1. 1st step, use Contractor Node to load CAN_FrameStream.dll, 
  2. Create the inputs according to the parameter setting before.
  3. "data" input seems to be a 1D Array in text code, but it failed to connect in LabVIEW, it indicates the input of this DLL is .NET reference handle.

aritajiushimei_0-1666600842074.png

aritajiushimei_1-1666601863605.png

 

My Question is:

How to create a proper input control for "data" 

 

Thanks,

Have a nice day.

 

0 Kudos
Message 1 of 14
(2,425 Views)

The Function of Text Code in C#:

 

try
{
int selectInterface = this.GetIntegerVariable("Argument0", "Select Interface");
UInt32 BaudRate = UInt32.Parse(this.GetStringVariable("Argument1", "Baud Rate"));
System.Array data = this.GetArrayVariable("Argument2", "Data");
UInt32 identifier = UInt32.Parse(this.GetStringVariable("Argument3", "Identifier"));
int NumberOfFrames = this.GetIntegerVariable("Argument4", "Number Of Frames");
bool HexDisplay = this.GetBooleanVariable("Argument5", "Hex Display");
int CANTimeout = this.GetIntegerVariable("Argument6", "Time out");

CAN__32frame[] DataArray = new CAN__32frame[2];
byte[] bytesToSendFID = new byte[8];

int i = 0;
foreach (int str in data)
{
bytesToSendFID[i] = byte.Parse(str.ToString());
i++;
}


byte[] bytesToSendFlowControl = new byte[8]
{
48, 0, 0, 0, 0, 0, 0, 0
};

DataArray[0].identifier = identifier;
DataArray[1].identifier = identifier;

DataArray[0].payload = bytesToSendFID;
DataArray[1].payload = bytesToSendFlowControl;

DataArray[0].type = 0;
DataArray[1].type = 0;

DataArray[0].echo__63 = false;
DataArray[1].echo__63 = false;

DataArray[0].extended__63 = false;
DataArray[1].extended__63 = false;

CAN_FrameStream.LabVIEWExports.CAN_FrameStream(selectInterface, BaudRate, CANTimeout, NumberOfFrames, true, DataArray, out Frames);

FramesRead = Frames.GetLength(0);

List<string> frameList = new List<string>();

for (int x = 0; x < FramesRead; x++)
{

if (Frames[x, 2].ToString().Contains("71E"))
{
frameList.Add(Frames[x, 1].ToString());
}

}

FramesRead = frameList.Count;

FramesToReturn = frameList.Select(e => e.ToString()).ToArray();

 

}

0 Kudos
Message 2 of 14
(2,420 Views)

@aritajiushimei wrote:
  1. "data" input seems to be a 1D Array in text code, but it failed to connect in LabVIEW, it indicates the input of this DLL is .NET reference handle.

I'm not an expert, so this is a guess, based on the code you sent.

 

It seems to me that this is not all the relevant code, but it looks like data  is an array (of two elements) of CAN__32frame. I don't think LabVIEW has a dedicated control for that.

 

 

My Question is:

How to create a proper input control for "data" 

 

 


Since you were able to get the array,

LLindenbauer_0-1666609136116.png

you could try to do the following:

 

  • Make the "data" control into a constant.
  • Reduce the array into a scalar element.
  • Use a property node on the element to set the properties (identifier, payload, type, echo__63, extended__63, ...)
  • Repeat that for the second element of the array.
  • Then bundle them together and use that as input.

I guess that the properties are all basic data types, so you can probably have controls for them. If they are not, the process can probably repeated.

0 Kudos
Message 3 of 14
(2,374 Views)

Hi 

 

I have an idea but I am not 100% sure if it solves your problem.

 

I would try to use the right mouse button ion the "Data" input of your .NET call and create a constant.

Then use your wire of the output form the "to .NET type" vi.

Wire it to a "to more sepcific class" and use the constant as an input for the target class.

 

then wire the result into the data input of the .NET call.

 

Hope this works. 

Gernot Hanel
IONICON Analytik Gesellschaft m.b.H.
0 Kudos
Message 4 of 14
(2,370 Views)

Thank you very much for your reply.

is it like this? but still fail to connect.

aritajiushimei_0-1666621974342.png

 

 

0 Kudos
Message 5 of 14
(2,340 Views)

thanks for reply.

and attached is the DLLs. it is for CAN frames.

would you help to check what is wrong with that.

 

Download All
0 Kudos
Message 6 of 14
(2,335 Views)

This is what I tried to say:

LLindenbauer_1-1666622947390.png

 

 

0 Kudos
Message 7 of 14
(2,325 Views)

Thank you, man.

Then next question is :

Do I need to set the value (C# code) into Control?

How? U8 cannot accept the string.

aritajiushimei_0-1666624297466.png

DataArray[0].identifier = identifier;
DataArray[1].identifier = identifier;

DataArray[0].payload = bytesToSendFID;
DataArray[1].payload = bytesToSendFlowControl;

DataArray[0].type = 0;
DataArray[1].type = 0;

DataArray[0].echo__63 = false;
DataArray[1].echo__63 = false;

DataArray[0].extended__63 = false;
DataArray[1].extended__63 = false;

 

0 Kudos
Message 8 of 14
(2,318 Views)
System.Array data = this.GetArrayVariable("Argument2", "Data");
foreach (int str in data) {bytesToSendFID[i] = byte.Parse(str.ToString());i++;}
byte[] bytesToSendFlowControl = new byte[8] {48, 0, 0, 0, 0, 0, 0, 0};

DataArray[0].payload = bytesToSendFID;
DataArray[1].payload = bytesToSendFlowControl;

 


@aritajiushimei wrote:

Thank you, man.

Then next question is :

Do I need to set the value (C# code) into Control?

How? U8 cannot accept the string.

 


A string is a bit like an array of U8 - which is an array of byte. See above for how the byte arrays are formed. One is converted from a System.Array that comes from this.GetArrayVariable("Argument2", "Data"); and is converted to bytes. The other one is {48, 0, 0, 0, 0, 0, 0, 0};

 

LabVIEW has a function "String to Byte Array" that does roughly the same conversion.

 

Like this:

 

LLindenbauer_0-1666628563133.png

 

Pay attention, though: I think your payload might be limited to 8 bytes. There is not enough code to tell.

 

0 Kudos
Message 9 of 14
(2,294 Views)

I would try something like this

 

nottilie_0-1666627853749.png

 

Gernot Hanel
IONICON Analytik Gesellschaft m.b.H.
0 Kudos
Message 10 of 14
(2,287 Views)