• 大小: 352KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2024-01-14
  • 语言: C#
  • 标签: CAN  通信  C#  周立功  

资源简介

周立功CAN盒驱动使用范例,包括设置、接受、发送等各种常用操作

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

//1.ZLGCAN系列接口卡信息的数据类型。
public struct VCI_BOARD_INFO 

public UInt16 hw_Version;
    public UInt16 fw_Version;
    public UInt16 dr_Version;
    public UInt16 in_Version;
    public UInt16 irq_Num;
    public byte can_Num;
    [MarshalAs(UnmanagedType.ByValArray SizeConst=20)] public byte []str_Serial_Num;
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 40)]
    public byte[] str_hw_Type;
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 8)]
    public byte[] Reserved;
}

//2.定义CAN信息帧的数据类型。
public struct VCI_CAN_OBJ 
{
    public UInt32 ID;
    public UInt32 TimeStamp;
    public byte TimeFlag;
    public byte SendType;
    public byte RemoteFlag;//是否是远程帧
    public byte ExternFlag;//是否是扩展帧
    public byte DataLen;
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 8)]
    public byte[] Data;
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 3)]
    public byte[] Reserved;

    public void Init()
    {
        Data = new byte[8];
        Reserved = new byte[3];
    }
}

//3.定义CAN控制器状态的数据类型。
public struct VCI_CAN_STATUS 
{
    public byte ErrInterrupt;
    public byte regMode;
    public byte regStatus;
    public byte regALCapture;
    public byte regECCapture;
    public byte regEWLimit;
    public byte regRECounter;
    public byte regTECounter;
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 4)]
    public byte[] Reserved;
}

//4.定义错误信息的数据类型。
public struct VCI_ERR_INFO 
{
    public UInt32 ErrCode;
    public byte Passive_ErrData1;
    public byte Passive_ErrData2;
    public byte Passive_ErrData3;
    public byte ArLost_ErrData;
}

//5.定义初始化CAN的数据类型
public struct VCI_INIT_CONFIG 
{
    public UInt32 AccCode;
    public UInt32 AccMask;
    public UInt32 Reserved;
    public byte Filter;
    public byte Timing0;
    public byte Timing1;
    public byte Mode;
}

public struct CHGDESIPANDPORT 
{
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 10)]
    public byte[] szpwd;
    [MarshalAs(UnmanagedType.ByValArray SizeConst = 20)]
    public byte[] szdesip;
    public Int32 desport;

    public void Init()
    {
        szpwd = new byte[10];
        szdesip = new byte[20];
    }
}


namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport(“controlcan.dll“)]
        static extern UInt32 VCI_OpenDevice(UInt32 DeviceType UInt32 DeviceInd UInt32 Reserved);
        [DllImport(“controlcan.dll“)]
        static extern UInt32 VCI_CloseDevice(UInt32 DeviceType UInt32 DeviceInd);
        [DllImport(“controlcan.dll“)]
        static extern UInt32 VCI_InitCAN(UInt32 DeviceType UInt32 DeviceInd UInt32 CANInd ref VCI_INIT_CONFIG pInitConfig);
        [DllImport(“controlcan.dll“)]
   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      53248  2005-07-01 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\ControlCAN.dll

     文件      53248  2004-12-10 14:52  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\CAN232.dll

     文件     163840  2007-08-03 14:22  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\CANETE.dll

     文件     212992  2008-06-16 09:41  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\CANET_TCP.dll

     文件      40960  2003-12-18 09:49  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\gisadll.dll

     文件      40960  2003-10-23 09:28  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\gpcidll.dll

     文件      45056  2003-12-18 09:50  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\isa5420.dll

     文件        291  2008-05-31 11:08  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\kerneldll.ini

     文件      45056  2005-06-16 12:32  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\PC104C2.dll

     文件      57344  2004-10-09 14:36  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\PC104CAN.dll

     文件      53248  2003-12-17 09:09  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\PCI5121.dll

     文件      36864  2008-08-28 10:36  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\kerneldlls\usbcan.dll

     文件      32768  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.exe

     文件      36352  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.pdb

     文件       5632  2005-11-11 22:25  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe

     文件      12268  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Form1.cs

     文件      24079  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Form1.Designer.cs

     文件       6011  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Form1.resx

     文件        842  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.csproj.GenerateResource.Cache

     文件      32768  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.exe

     文件        180  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.Form1.resources

     文件      36352  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.pdb

     文件        180  2006-07-25 11:43  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.Properties.Resources.resources

     文件        352  2007-11-20 10:13  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\obj\WindowsApplication1.csproj.FileList.txt

     文件        478  2006-07-25 09:53  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Program.cs

     文件       1192  2006-07-25 09:53  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Properties\AssemblyInfo.cs

     文件       2892  2006-07-25 09:53  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Properties\Resources.Designer.cs

     文件       5612  2006-07-25 09:53  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Properties\Resources.resx

     文件       1102  2006-07-25 09:53  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Properties\Settings.Designer.cs

     文件        249  2006-07-25 09:53  c#例子(vs2005)\WindowsApplication1\WindowsApplication1\Properties\Settings.settings

............此处省略18个文件信息

评论

共有 条评论