10-24-2022 03:58 AM
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.
My Question is:
How to create a proper input control for "data"
Thanks,
Have a nice day.
10-24-2022 04:20 AM
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();
}
10-24-2022 06:13 AM - edited 10-24-2022 06:14 AM
@aritajiushimei wrote:
- "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,
you could try to do the following:
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.
10-24-2022 06:17 AM
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.
10-24-2022 09:37 AM
Thank you very much for your reply.
is it like this? but still fail to connect.
10-24-2022 09:42 AM
thanks for reply.
and attached is the DLLs. it is for CAN frames.
would you help to check what is wrong with that.
10-24-2022 09:56 AM
This is what I tried to say:
10-24-2022 10:13 AM
Thank you, man.
Then next question is :
Do I need to set the value (C# code) into Control?
How? U8 cannot accept the string.
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;
10-24-2022 10:58 AM - edited 10-24-2022 11:30 AM
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:
Pay attention, though: I think your payload might be limited to 8 bytes. There is not enough code to tell.
10-24-2022 11:11 AM
I would try something like this