02-06-2016 01:09 AM
Dear Sir,
I try to program XNET (CAN & LIN) with C#.
I found the example for the ANSI-C.
I try to conver this example to C#, but it's very difficult to me.
Some body already have .Net Wrapper for XNET API? and can share ?
Thanks,
Hiawath
02-11-2016 03:35 AM
Hi Hiawath,
There's currently no support for our customers willing to use XNET with a .NET programming language. As per the example in C and the use of P/Invoke, you can create a C# wrapper for your needs, yet we cannot really assist you in doing this.
A useful document to get started:
- http://www.codeproject.com/Articles/403285/P-Invoke-Tutorial-Basics-Part
You can also share you experience with your local sales representative in case he can figure out a better way out for you.
--Eric
Eric M. - Senior Software Engineer
Certified LabVIEW Architect - Certified LabVIEW Embedded Systems Developer - Certified LabWindows™/CVI Developer
Neosoft Technologies inc.
03-06-2016 03:13 AM
Dear Sir,
I try to wrapper for the "nixnet.dll" and worked very well for the "nxCreateSession" and "nxWriteSignalSinglePoint".
But I can't get the data from " nxReadSignalSinglePoint" , even though compile OK,
Can you see "nxReadSignalSinglePoint" and advice ?
Thanks,
Andrew.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
public const string DLL_NAME = "nixnet.dll";
static IntPtr g_SessionRef;
static IntPtr g_SessionRef2;
[DllImport(DLL_NAME, EntryPoint = "nxCreateSession", CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 CreateSession(string DatabaseName, string ClusterName, string List, string Interface,
UInt32 Mode, out IntPtr SessionRef);
//nxStatus_t _NXFUNC nxCreateSession(
// const char* DatabaseName,
// const char* ClusterName,
// const char* List,
// const char* Interface,
// u32 Mode,
// nxSessionRef_t* SessionRef);
[DllImport(DLL_NAME, EntryPoint = "nxReadSignalSinglePoint", CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 ReadSignalSinglePoint(IntPtr SessionRef, out IntPtr ReadValueBuffer,
UInt32 SizeOfValueBuffer, out IntPtr TimestampBuffer, UInt32 SizeOfTimestampBuffer);
//nxStatus_t _NXFUNC nxReadSignalSinglePoint (
// nxSessionRef_t SessionRef,
// f64* ValueBuffer,
// u32 SizeOfValueBuffer,
// nxTimestamp_t* TimestampBuffer,
// u32 SizeOfTimestampBuffer);
[DllImport(DLL_NAME, EntryPoint = "nxWriteSignalSinglePoint", CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 WriteSignalSinglePoint(IntPtr SessionRef, double[] ValueBuffer, UInt32 SizeOfValueBuffer);
//nxStatus_t _NXFUNC nxWriteSignalSinglePoint(
// nxSessionRef_t SessionRef,
// f64* ValueBuffer,
// u32 SizeOfValueBuffer);
static void Main(string[] args)
{
string l_pSelectedInterface = "LIN2";
string l_pSignalArray = "";
string l_pSignalArray2 = "";
string l_pSelectedDatabase = "IG";
string l_pSelectedCluster = "Cluster";
string l_pSelectedSignal1 = "LH_HeaterSWLEDHigh";
string l_pSelectedSignal2 = "LH_HeaterSWLEDMid";
string l_pSelectedSignal5 = "LH_HeaterSWLEDLow";
string l_pSelectedSignal3 = "LH_HeaterSW";
int g_Status = 0;
double[] ValueBuffer = new double[2];
IntPtr ReadValueBuffer = IntPtr.Zero;
IntPtr TimestampBuffer = IntPtr.Zero;
/// for read from LIN
l_pSignalArray = l_pSelectedSignal1;
l_pSignalArray += ",";
l_pSignalArray += l_pSelectedSignal2;
l_pSignalArray += ",";
l_pSignalArray += l_pSelectedSignal5;
// for writing to LIN
l_pSignalArray2 = l_pSelectedSignal3;
l_pSignalArray2 += ",";
l_pSignalArray2 += l_pSelectedSignal5;
/// for read from LIN
g_Status = CreateSession(l_pSelectedDatabase, l_pSelectedCluster, l_pSignalArray,
l_pSelectedInterface, 0, out g_SessionRef);
// for writing to LIN
g_Status = CreateSession(l_pSelectedDatabase, l_pSelectedCluster, l_pSignalArray2,
l_pSelectedInterface, 3, out g_SessionRef2);
//
ValueBuffer[0] = 0x01;
ValueBuffer[1] = 0x00;
// write
g_Status = WriteSignalSinglePoint(g_SessionRef2, ValueBuffer, 16);
///////////////////// read
g_Status = ReadSignalSinglePoint(g_SessionRef, out ReadValueBuffer, 24, out TimestampBuffer, 24);
return;
}
}
}
03-07-2016 07:04 AM
I don't know .NET, but looking at your code, you are marking "ReadValueBuffer" as an 'IntPtr'. This is actually a double-precision floating point value.
[DllImport(DLL_NAME, EntryPoint = "nxReadSignalSinglePoint", CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 ReadSignalSinglePoint(IntPtr SessionRef, out IntPtr ReadValueBuffer,
UInt32 SizeOfValueBuffer, out IntPtr TimestampBuffer, UInt32 SizeOfTimestampBuffer);
I don't know if this helps.
09-15-2016 01:55 PM
hummm,, its 2016 and no support for .NET framework? I wonder if NI is pushing customers to competitors for in-vehicle CAN (ValueCAN, Vector CANTech, etc) for not being able to interface to new development environment. Afterall, Measurment Sudio uses WPF. If I have the hardware; why do I need to shling another $1k for development environement that I can get for free from Microsoft. Its not rocket science; only CAN messages.
06-21-2017 03:59 PM
Any luck? I am also looking for C# code for LIN2.0.