void m_CAN_ErrorReceivedEvent(CAN sender, CANErrorReceivedEventArgs args) { //this._PostDone = new PostMessagesDoneEventHandler(this.OnPostMessagesFinished); //this._PostDone(m_numMessagesSent); this._ErrorReceived = new ErrorReceivedEventHandler(this.OnErrorReceived); this._ErrorReceived(sender, args); }
//public CAN GetCAN //{ // get { return m_CAN; } //} /// <summary> /// Initializes CAN. /// </summary> /// <param name="bitRate">The desired bitrate, if known. Otherwise, use the other overload to calculate a bitrate. See GHI's website. Go to Support::Documents::CAN for more info.</param> /// <param name="receiveBufferSize">Specifies the receive buffer size (number of internally buffered CAN messages). Defaulted to 100.</param> /// <param name="channel">The CAN channel to use.</param> public void InitializeCAN(uint bitRate, int receiveBufferSize, CAN.Channel channel = CAN.Channel.Channel_1) { m_CAN = new CAN(channel, bitRate, receiveBufferSize = 100); m_CAN.DataReceivedEvent += new CANDataReceivedEventHandler(m_CAN_DataReceivedEvent); m_CAN.ErrorReceivedEvent += new CANErrorReceivedEventHandler(m_CAN_ErrorReceivedEvent); }
/// <summary> /// Initializes CAN. /// </summary> /// <param name="T1">See GHI's website. Go to Support::Documents::CAN for calculation.</param> /// <param name="T2">See GHI's website. Go to Support::Documents::CAN for calculation.</param> /// <param name="BRP">See GHI's website. Go to Support::Documents::CAN for calculation.</param> /// <param name="receiveBufferSize">Specifies the receive buffer size (number of internally buffered CAN messages). Defaulted to 100.</param> /// <param name="channel">The CAN channel to use.</param> public void InitializeCAN(int T1, int T2, int BRP, int receiveBufferSize = 100, CAN.Channel channel = CAN.Channel.Channel_1) { m_CAN = new CAN(channel, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)), receiveBufferSize); m_CAN.DataReceivedEvent += new CANDataReceivedEventHandler(m_CAN_DataReceivedEvent); m_CAN.ErrorReceivedEvent += new CANErrorReceivedEventHandler(m_CAN_ErrorReceivedEvent); }
public CCanAppli() { // Initialisation du CAN. UInt32 bitRate = (UInt32)((8 - 1) << 20) | (UInt32)((15 - 1) << 16) | (UInt32)((12 - 1) << 0); //Channel1 m_busCan = new CAN(CAN.Channel.Channel_1, bitRate, 100); // m_tabWaitDONE = new WaitHandle[] { new AutoResetEvent(false), new AutoResetEvent(false), new AutoResetEvent(false) }; m_waitACK = new AutoResetEvent(false); // Tableau de data reçu. m_dataRecus[0] = new CAN.Message(); // Initialisation de l'evenement permetant de detecter une erreur CAN. m_busCan.ErrorReceivedEvent += new CANErrorReceivedEventHandler(m_busCan_ErrorReceivedEvent); // Initialisation de l'evenement permetant de detecter une reponse. m_busCan.DataReceivedEvent += new CANDataReceivedEventHandler(m_busCan_DataReceivedEvent); mutex = new Object(); }
public ModbusAdapterContext(DeviceBase canDevice, File modbusDevice) { CanDevice = new CAN(); CanDevice.NetworkId = canDevice.Network.NetworkId; CanDevice.NodeId = canDevice.NodeId; ModbusDevice = new Modbus(); ModbusDevice.FileNumber = modbusDevice.Number; }
/// <summary> /// Sends the data received event /// </summary> /// <param name="sender">Sending module</param> /// <param name="args">Data args</param> protected virtual void OnDataReceived(CAN sender, CANDataReceivedEventArgs args) { if (this.DataReceived == null) { this.DataReceived = new DataReceivedEventHandler(this.OnDataReceived); } this.DataReceived(sender, args); }
unsafe private void SendData() { if (!isOpen) { return; } CAN cAN = new CAN(); cAN.IsRemote = (byte)cbo_FrameFormat.SelectedIndex; cAN.IsExtern = (byte)cbo_FrameType.SelectedIndex; cAN.ID = Convert.ToUInt32("0x" + txt_ID.Text, 16); int len = (txt_Data.Text.Length + 1) / 3; cAN.DataLength = Convert.ToByte(len); String strdata = txt_Data.Text; int i = -1; if (i++ < len - 1) { cAN.Data[0] = this.ConvertHexStringToByte(strdata, i); } Debug.WriteLine($"i={i}"); if (i++ < len - 1) { cAN.Data[1] = this.ConvertHexStringToByte(strdata, i); } if (i++ < len - 1) { cAN.Data[2] = this.ConvertHexStringToByte(strdata, i); } if (i++ < len - 1) { cAN.Data[3] = this.ConvertHexStringToByte(strdata, i); } if (i++ < len - 1) { cAN.Data[4] = this.ConvertHexStringToByte(strdata, i); } if (i++ < len - 1) { cAN.Data[5] = this.ConvertHexStringToByte(strdata, i); } if (i++ < len - 1) { cAN.Data[6] = this.ConvertHexStringToByte(strdata, i); } if (i++ < len - 1) { cAN.Data[7] = this.ConvertHexStringToByte(strdata, i); } if (VCI_Transmit(deviceType, deviceId, canId, ref cAN, 1) == 0) { MessageBox.Show("发送失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void UpdateChannel(Channel channel, object paras) { List <DataGridViewRow> mappingRows = FindMappingRows(channel); foreach (DataGridViewRow row in mappingRows) { row.Cells[0].Value = channel.IsStarted ? "启动" : "复位"; row.Cells[1].Value = CAN.FindCANModeKey(channel.Mode); row.Cells[2].Value = channel.ChannelName; row.Cells[3].Value = channel.ChannelIndex; row.Cells[4].Value = channel.BaudRate; } }
public void AddDevice(Device device, object paras) { for (uint channelIndex = 0; channelIndex < device.CANNum; channelIndex++) { Channel channel = device.GetChannel(channelIndex); int index = dgvChannels.Rows.Add(); dgvChannels.Rows[index].Visible = false; dgvChannels.Rows[index].Tag = channel; dgvChannels.Rows[index].Cells[0].Value = channel.IsStarted ? "启动" : "复位"; dgvChannels.Rows[index].Cells[1].Value = CAN.FindCANModeKey(channel.Mode); dgvChannels.Rows[index].Cells[2].Value = channel.ChannelName; dgvChannels.Rows[index].Cells[3].Value = channel.ChannelIndex; dgvChannels.Rows[index].Cells[4].Value = channel.BaudRate; } }
public CsmDataFrame(CAN.DataFrame CanDataFram) { Address = (ushort)(CanDataFram.ID >> 3 & 0x1F); if ((CanDataFram.ID & 0x07) != 1) { this._type = (FrameType)(CanDataFram.ID & 0x07); } else { throw new Exception(string.Format("帧类型错误!\nID:{0}\nData:{1}", CanDataFram.ID.ToString(),BitConverter.ToString(CanDataFram.Date))); } Data = CanDataFram.Date; _prority = (FramePrority)(CanDataFram.ID>>8 & 0x1); _feature = (FrameFeature)(CanDataFram.ID>>9 &0x1); _direction = (FrameDirection)(CanDataFram.ID>>10 &0x1); }
private void save_Click(object sender, EventArgs e) { try { #region CheckInput if (String.IsNullOrEmpty(combChannel.Text.Trim())) { MessageBox.Show("Channel can't be empty!"); return; } if (String.IsNullOrEmpty(combBaudRate.Text)) { MessageBox.Show("PortName can't be empty!"); return; } #endregion string path = Application.StartupPath + "\\SysConfig"; var item = list.Where(c => c.Channel == combChannel.Text).FirstOrDefault(); if (item != null) { item.Baudrate = combBaudRate.Text.Trim(); } else { CAN can = new CAN(); can.Channel = String.IsNullOrEmpty(combChannel.Text.Trim()) ? "" : combChannel.Text.Trim(); can.Baudrate = combBaudRate.Text.Trim(); list.Add(can); } string json = JsonConvert.SerializeObject(list, Formatting.Indented); JsonOperate.SaveJson(path, "CAN.json", json); LoadInfo(); } catch (Exception ex) { logger.Error(ex, ex.Message); } }
private bool ConfigCAN() { INIT_CONFIG config = channel.Config; CAN_MODE mode = (CAN_MODE)Enum.ToObject(typeof(CAN_MODE), this.cbxCANMode.SelectedIndex); int baudRate = Convert.ToInt32(cbxCANBaudRate.SelectedItem); if (m_IsConfigured && mode == channel.Mode && baudRate == channel.BaudRate) { // already configured, no need to update return(true); } CAN.ConfigMode(mode, ref config); CAN.ConfigBaudRate(baudRate, ref config); if (channel.InitCAN(baudRate, ref config) != (uint)CAN_RESULT.SUCCESSFUL) { m_IsConfigured = false; return(false); } m_IsConfigured = true; return(true); }
static extern UInt32 VCI_Receive(UInt32 deviceType, UInt32 deviceID, UInt32 CANInd, ref CAN pReceive, UInt32 Len, Int32 WaitTime);
/// <summary> /// Sends the error event. /// </summary> /// <param name="sender">Sending module</param> /// <param name="args">Error arguments</param> protected virtual void OnErrorReceived(CAN sender, CANErrorReceivedEventArgs args) { this.ErrorReceived(sender, args); }
void m_busCan_ErrorReceivedEvent(CAN sender, CANErrorReceivedEventArgs args) { //erreur erreur = IDerreur.ErrorReceived; }
void m_busCan_DataReceivedEvent(CAN sender, CANDataReceivedEventArgs args) { // Récupération de la réponse dans un tableau. sender.GetMessages(m_dataRecus, 0, m_dataRecus.Length); AutoResetEvent evtDONE = (AutoResetEvent)m_tabWaitDONE[0]; AutoResetEvent evtSTOP = (AutoResetEvent)m_tabWaitDONE[1]; AutoResetEvent evtBLOCAGE = (AutoResetEvent)m_tabWaitDONE[2]; AutoResetEvent evtACK = (AutoResetEvent)m_waitACK; // Etude de la commande reçus. switch(m_dataRecus[0].ArbID) { case (uint)IDcommande.WStopACK: evtACK.Set(); break; case (uint)IDcommande.WStopDONE: evtSTOP.Set(); break; case (uint)IDcommande.WBlocageDONE: evtBLOCAGE.Set(); break; case (uint)IDcommande.WSetStartPositionACK : evtACK.Set(); break; case (uint)IDcommande.WSetStartPositionDONE : evtDONE.Set(); break; case (uint)IDcommande.WSetSpeedACK : evtACK.Set(); break; case (uint)IDcommande.WSetSpeedDONE : evtDONE.Set(); break; case (uint)IDcommande.WGoToACK: evtACK.Set(); break; case (uint)IDcommande.WGoToDONE: evtDONE.Set(); break; case (uint)IDcommande.WGoTo2ACK: evtACK.Set(); break; case (uint)IDcommande.WGoTo2DONE: evtDONE.Set(); break; case (uint)IDcommande.WRotateACK: evtACK.Set(); break; case (uint)IDcommande.WRotateDONE : evtDONE.Set(); break; case (uint)IDcommande.WGetPositionACK: evtACK.Set(); break; case (uint)IDcommande.WGetPositionDONE : evtDONE.Set(); break; case (uint)IDcommande.WGetCodeurACK: evtACK.Set(); break; case (uint)IDcommande.WGetCodeurDONE: evtDONE.Set(); break; case (uint)IDcommande.SOuvrirPinceACK: evtACK.Set(); break; case (uint)IDcommande.SOuvrirPinceDONE : evtDONE.Set(); break; case (uint)IDcommande.SFermerPinceACK: evtACK.Set(); break; case (uint)IDcommande.SFermerPinceDONE : evtDONE.Set(); break; case (uint)IDcommande.SBrasAllezEnACK: evtACK.Set(); break; case (uint)IDcommande.SBrasAllezEnDONE : evtDONE.Set(); break; case (uint)IDcommande.SAscenseurAllezEnACK: evtACK.Set(); break; case (uint)IDcommande.SAscenseurAllezEnDONE : evtDONE.Set(); break; case (uint)IDcommande.SGonflerBallonACK: evtACK.Set(); break; case (uint)IDcommande.SGonflerBallonDONE : evtDONE.Set(); break; case (uint)IDcommande.SArreterGonflageACK: evtACK.Set(); break; case (uint)IDcommande.SArreterGonflageDONE : evtDONE.Set(); break; case (uint)IDcommande.SLectureMusiqueACK: evtACK.Set(); break; case (uint)IDcommande.SLectureMusiqueDONE : evtDONE.Set(); break; case (uint)IDcommande.SPauseMusiqueACK: evtACK.Set(); break; case (uint)IDcommande.SPauseMusiqueDONE : evtDONE.Set(); break; } }
public MainWindow() { can = new CAN(); CanStat = can.InitCANtransmitter(); InitializeComponent(); }
static extern UInt32 VCI_Transmit(UInt32 deviceType, UInt32 deviceID, UInt32 CANInd, ref CAN pSend, UInt32 Len);
void m_CAN_DataReceivedEvent(CAN sender, CANDataReceivedEventArgs args) { this._DataReceived = new DataReceivedEventHandler(this.OnDataReceived); this._DataReceived(sender, args); }