01-11-2007 01:40 PM
We are working with the PXI-8423 CAN bus card, and so far have been using nctInitStart and a CAN database file when starting our application. We would like to use nctCreateMessage so that the application is entirely self contained but are having trouble wrapping the method in C#. I have also not found an example of anyone that has wrapped this in C#.
We are getting the following error when we try to call nctCreateMsg: "NI-CAN: (Hex 0xBFF62207) You passed NULL for a required pointer. Solutions: Consult the Programmer Reference to ensure that you pass valid pointers to the function."
We have tried a lot of things to figure out the problem, but there are a lot of parameters for this method, and the error message is vague. I have attached the code that has led to this error, any help you can offer would be appreciated.
Thank You
01-12-2007 02:17 PM
01-12-2007 02:21 PM
01-12-2007 03:17 PM - edited 01-12-2007 03:17 PM
Yes, I have already seen the CAN Hardware and Software Manual. I believe that the trouble is with the Marshaling of data from C# code, which I attached, not the method or use of the method itself.
I also made a mistake with the card number it is actually PXI-8464, the PXI-8423 is another card we are using for serial communications as you pointed out.
Thanks
Message Edited by SpaceVector on 01-12-2007 03:18 PM
01-16-2007 12:05 PM
//cppCreateMessage(ncTypeMessageConfig MessageConfig, u32 NumberOfChannels, ncTypeChannelConfig* ChannelConfigList, i32 Interface, i32 Mode, f64 SampleRate, ncTypeTaskRef* TaskRef)
[DllImport("nican.dll")]
protected static extern int nctCreateMessage(MessageConfig messageConfig, int numberOfChannels, [In, Out] ChannelConfig[] ChannelConfigList, int pInterface, int mode, double sampleRate, ref IntPtr taskId);01-17-2007 09:18 AM - edited 01-17-2007 09:18 AM
Message Edited by YuGen on 01-17-2007 09:19 AM
01-17-2007 01:28 PM
Below is what I think is the C# equivalent to what you posted for the struct, which I tried but got the same error message (I did remember to call Initialize before passing it in). The only other parameter I think it may be talking about is the TaskRef, which is null when the method is called. I don't think that the TaskRef is the issue though because it is an out parameter, and we are temporarily using InitStart and we are passing null in for that TaskRef as well, and that method works fine.
Thanks for you suggestion, if anyone has any other ideas about what the error might be that would be appreciated.
public
struct ChannelConfig{
public int startBits;
public int numBits;
public int dataType;
public int byteOrder;
public double scalingFactor;
public double scalingOffset;
public double maxValue;
public double minValue;
public double defaultValue;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=64)]
public byte[] unit;
public void Initialize()
{
unit = new byte[64];
}
}
01-17-2007 02:16 PM - edited 01-17-2007 02:16 PM
Message Edited by YuGen on 01-17-2007 02:21 PM
04-23-2021 09:12 AM - edited 04-23-2021 09:14 AM
thanks for the code Yugen, I was having some problems porting and existing vb6 program to vb.net