使用ZLG USBCAN-E-U,通过C#实现通讯:

1、建一个CANDevice实体类,传递一些参数,并且保存一些设备的型号、ID,以及波特率等参数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;

namespace ZLGUSBCAN
{
    [Serializable]
    public class CardType
    {
        public string TyPeName { get; set; }
        public uint TypeId { get; set; }
    }
    [Serializable]
    public class BoudRoute
    {
        public string RateName { get; set; }
        public UInt32 RateValue { get; set; }
    }

    [Serializable]
    public class CANDevice
    {        
        //private readonly uint devType;
        //private readonly uint devID;
        //private readonly uint canID;
        //private readonly uint baudRate;
        //private readonly uint sendTimeout;

        public uint DevType { get; set; }
        public uint DevID { get; set; }
        public uint CANID { get; set; }
        public uint BoudRate { get; set; }
        public uint SendTimeout { get; set; }
        //CAN参数
        public uint AccCode { get; set; }
        public uint AccMask { get; set; }
        public uint Reserved { get; set; }
        public byte Filter { get; set; }
        public byte Timing0 { get; set; }
        public byte Timing1 { get; set; }
        public byte Mode { get; set; }
        public List<CardType> CardTypeList { get; set; }
        public List<BoudRoute> BoudRateList { get; set; }

        public CANDevice(uint devType, uint devID, uint boudRate, uint sendTimeout, uint canID = 0)
        {
            this.DevType = devType;
            this.DevID = devID;
            this.CANID = canID;
            this.BoudRate = boudRate;
            this.SendTimeout = sendTimeout;

        }

        public CANDevice()
        {
            this.CardTypeList = new List<CardType>();           
            this.CardTypeList.Add(new CardType { TyPeName = "VCI_USBCAN_E_U", TypeId = 20 });
            this.CardTypeList.Add(new CardType { TyPeName = "VCI_USBCAN_2E_U", TypeId = 21 });

            this.BoudRateList = new List<BoudRoute>();
            this.BoudRateList.Add(new BoudRoute { RateName = "1000Kbps", RateValue = 0x060003 });
            this.BoudRateList.Add(new BoudRoute { RateName = "800Kbps", RateValue = 0x060004 });
            this.BoudRateList.Add(new BoudRoute { RateName = "500Kbps", RateValue = 0x060007 });
            this.BoudRateList.Add(new BoudRoute { RateName = "250Kbps", RateValue = 0x1C0008 });
            this.BoudRateList.Add(new BoudRoute { RateName = "125Kbps", RateValue = 0x1C0011 });
            this.BoudRateList.Add(new BoudRoute { RateName = "100Kbps", RateValue = 0x160023 });
            this.BoudRateList.Add(new BoudRoute { RateName = "50Kbps", RateValue = 0x1C002C });
            this.BoudRateList.Add(new BoudRoute { RateName = "20Kbps", RateValue = 0x1600B3 });
            this.BoudRateList.Add(new BoudRoute { RateName = "10Kbps", RateValue = 0x1C00E0 });
            this.BoudRateList.Add(new BoudRoute { RateName = "5Kbps", RateValue = 0x1C01C1 });           
        }   
    }
}
View Code

相关文章:

  • 2021-08-13
  • 2021-05-28
  • 2021-12-24
  • 2021-09-11
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-01-07
  • 2021-12-04
  • 2022-12-23
  • 2022-01-12
相关资源
相似解决方案