Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

SorceCode for VC#2005 using NICAN Frame API

I try to use NICAN Frame API by VC#2005.
 
I am writing the code by using DLLIMPORT.
 
But It doesn't operate still well.
 
Please show me sample code !!
 
Especially, the usage of the function that there is a pointer in the argument is not understood.
 
Thanks

0 Kudos
Message 1 of 3
(6,510 Views)
Hi urushi,

Unfortunately, the NI-CAN is not supported in C#.
So, an official sample code is not provided by National Instruments.

Perhaps another user can provide an unofficial solution to fit your needs.

Wish you the best.

Noriyo Sakurada | National Instruments |
0 Kudos
Message 2 of 3
(6,477 Views)

I havent looked at the NI Frame API so here is some code for softing CANusb.dll.

Sorry this is old code in C++

In c# you would replace the pointer with an IntPnt and mark your code as unmaneaged (or is that unsafe)

 

The idear with this code was to to use a c# rapper around the C++ code as a stanalone assembly.

 

[DllImport("CANusb.dll")]
 extern "C" int INIPC_initialize_board(canpc_ressources_s * rs);
 [DllImport("CANusb.dll")]
 extern "C" int CANPC_reset_board(void);
 [DllImport("CANusb.dll")]
 extern "C" int CANPC_reset_chip(void);
 [DllImport("CANusb.dll")]
 extern "C" int CANPC_initialize_chip(int nPrescaler,int nSyncJumpWidth,int nTimeSegment1,int nTimeSegment2,int nSampleMode);

Structures

  #pragma pack(push,1)
  [StructLayoutAttribute(LayoutKind::Sequential)]
  __value struct  canInitParams
  {
   unsigned long  Ident;
   int            DataLength;
   int            RecOverrun_flag;
   int            RCV_fifo_lost_msg;
   unsigned char  RCV_data __nogc[8];
   int            AckOverrun_flag;
   int            XMT_ack_fifo_lost_acks;
   int            XMT_rmt_fifo_lost_remotes;
   int            Bus_state;
   int            Error_state;
   int            Can;
   unsigned long  Time;
  };
  #pragma pack(pop)

 

Colin

Delphi Diesel Systems

0 Kudos
Message 3 of 3
(6,349 Views)