public override void Start(int bitrate) { this.SetBitrate(bitrate); this.FDevice.PerformBlocking(() => { NativeFunctions.ThrowIfError( NativeFunctions.StartCAN( this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex) , this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex); NativeFunctions.ThrowIfError( NativeFunctions.ResetCAN( this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex) , this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex); }); }
public override void Stop() { this.FDevice.PerformBlocking(() => { NativeFunctions.ThrowIfError( NativeFunctions.ResetCAN( this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex) , this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex); }); }
public override void SetBitrate(int value) { var initConfig = new NativeFunctions.INIT_CONFIG(); initConfig.AccCode = 0; initConfig.AccMask = 0xffffff; initConfig.Filter = 0; switch (value) { case 1000000: initConfig.Timing0 = 0; initConfig.Timing1 = 0x14; break; case 800000: initConfig.Timing0 = 0; initConfig.Timing1 = 0x16; break; case 666000: initConfig.Timing0 = 0x80; initConfig.Timing1 = 0xb6; break; case 500000: initConfig.Timing0 = 0; initConfig.Timing1 = 0x1c; break; case 400000: initConfig.Timing0 = 0x80; initConfig.Timing1 = 0xfa; break; case 250000: initConfig.Timing0 = 0x01; initConfig.Timing1 = 0x1c; break; case 200000: initConfig.Timing0 = 0x81; initConfig.Timing1 = 0xfa; break; case 125000: initConfig.Timing0 = 0x03; initConfig.Timing1 = 0x1c; break; case 100000: initConfig.Timing0 = 0x04; initConfig.Timing1 = 0x1c; break; case 80000: initConfig.Timing0 = 0x83; initConfig.Timing1 = 0xff; break; case 50000: initConfig.Timing0 = 0x09; initConfig.Timing1 = 0x1c; break; default: throw (new Exception("Bitrate not supported")); } initConfig.Mode = 0; this.FDevice.PerformBlocking(() => { NativeFunctions.ThrowIfError( NativeFunctions.InitCAN( this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex , ref initConfig) , this.FDevice.DeviceType , this.FDevice.DeviceIndex , this.FChannelIndex);; }); }