库伯勒立撤倍加福三合一拉线编码器配置工具
- 库伯勒编码器配置界面
- 立撤编码器配置界面
- 倍加福编码器配置界面
基于C#语言开发,快速配置,自动保存,支持多种CAN工具接入使用。
无需使用查看配置手册,即可能够快速有效的配置拉线编码器。
给安装、生产、调试带来便利。
软件下载地址:https://download.csdn.net/download/ahphong/87246828
库伯勒编码器配置界面
立撤编码器配置界面
倍加福编码器配置界面
部分核心代码
#region can初始化/// <summary>/// can初始化/// </summary>private void CAN_init(){List<Devtype> Devtype_List = new List<Devtype>();Devtype_List.Add(new Devtype { ID = 0, Name = "请选择CAN盒" });Devtype_List.Add(new Devtype { ID = 1, Name = "PCI5121" });Devtype_List.Add(new Devtype { ID = 2, Name = "PCI9810" });Devtype_List.Add(new Devtype { ID = 3, Name = "USBCAN1" });Devtype_List.Add(new Devtype { ID = 4, Name = "USBCAN2/USBCAN2A" });Devtype_List.Add(new Devtype { ID = 5, Name = "PCI9820" });Devtype_List.Add(new Devtype { ID = 6, Name = "CAN232" });Devtype_List.Add(new Devtype { ID = 7, Name = "PCI5110" });Devtype_List.Add(new Devtype { ID = 8, Name = "CANLITE" });Devtype_List.Add(new Devtype { ID = 9, Name = "ISA9620" });Devtype_List.Add(new Devtype { ID = 10, Name = "ISA5420" });Devtype_List.Add(new Devtype { ID = 11, Name = "PC104CAN" });Devtype_List.Add(new Devtype { ID = 12, Name = "CANETUDP" });Devtype_List.Add(new Devtype { ID = 13, Name = "DNP9810" });Devtype_List.Add(new Devtype { ID = 14, Name = "PCI9840" });Devtype_List.Add(new Devtype { ID = 15, Name = "PC104CAN2" });Devtype_List.Add(new Devtype { ID = 16, Name = "PCI9820I" });Devtype_List.Add(new Devtype { ID = 17, Name = "CANETTCP" });Devtype_List.Add(new Devtype { ID = 18, Name = "PEC9920" });Devtype_List.Add(new Devtype { ID = 19, Name = "PCI5010U" });Devtype_List.Add(new Devtype { ID = 20, Name = "USBCAN_E_U" });Devtype_List.Add(new Devtype { ID = 21, Name = "USBCAN_2E_U" });Devtype_List.Add(new Devtype { ID = 22, Name = "PCI5020U" });Devtype_List.Add(new Devtype { ID = 23, Name = "EG20T_CAN" });comboBox_devtype.ItemsSource = Devtype_List;comboBox_devtype.SelectedIndex = 21; //默认USBCAN_2E_UList<DevIndex> DevIndex_List = new List<DevIndex>();DevIndex_List.Add(new DevIndex { ID = 0, Name = "0" });DevIndex_List.Add(new DevIndex { ID = 1, Name = "1" });comboBox_DevIndex.ItemsSource = DevIndex_List;comboBox_DevIndex.SelectedIndex = 0; //默认0索引List<CANIndex> CANIndex_List = new List<CANIndex>();CANIndex_List.Add(new CANIndex { ID = 0, Name = "0" });CANIndex_List.Add(new CANIndex { ID = 1, Name = "1" });CANIndex_List.Add(new CANIndex { ID = 2, Name = "2" });CANIndex_List.Add(new CANIndex { ID = 3, Name = "3" });comboBox_CANIndex.ItemsSource = CANIndex_List;comboBox_CANIndex.SelectedIndex = 0; //默认0路canList<Filter> Filter_List = new List<Filter>();Filter_List.Add(new Filter { ID = 0, Name = "双滤波" });Filter_List.Add(new Filter { ID = 1, Name = "单滤波" });comboBox_Filter.ItemsSource = Filter_List;comboBox_Filter.SelectedIndex = 1;List<Mode> Mode_List = new List<Mode>();Mode_List.Add(new Mode { ID = 0, Name = "正常" });Mode_List.Add(new Mode { ID = 1, Name = "只听" });comboBox_Mode.ItemsSource = Mode_List;comboBox_Mode.SelectedIndex = 0;List<SendType> SendType_List = new List<SendType>();SendType_List.Add(new SendType { ID = 0, Name = "正常发送" });SendType_List.Add(new SendType { ID = 1, Name = "单次正常发送" });SendType_List.Add(new SendType { ID = 2, Name = "自发自收" });SendType_List.Add(new SendType { ID = 3, Name = "单次自发自收" });List<FrameFormat> FrameFormat_List = new List<FrameFormat>();FrameFormat_List.Add(new FrameFormat { ID = 0, Name = "正常发送" });FrameFormat_List.Add(new FrameFormat { ID = 1, Name = "单次正常发送" });List<FrameType> FrameType_List = new List<FrameType>();FrameType_List.Add(new FrameType { ID = 0, Name = "标准帧" });FrameType_List.Add(new FrameType { ID = 1, Name = "扩展帧" });List<e_u_baud> e_u_baud_List = new List<e_u_baud>();e_u_baud_List.Add(new e_u_baud { ID = 0, Name = "1000K" });e_u_baud_List.Add(new e_u_baud { ID = 1, Name = "800K" });e_u_baud_List.Add(new e_u_baud { ID = 2, Name = "500K" });e_u_baud_List.Add(new e_u_baud { ID = 3, Name = "250K" });e_u_baud_List.Add(new e_u_baud { ID = 4, Name = "125K" });e_u_baud_List.Add(new e_u_baud { ID = 5, Name = "100K" });comboBox_e_u_baud.ItemsSource = e_u_baud_List;comboBox_e_u_baud.SelectedIndex = 3;//250KbpsList<e_u_Filter> e_u_Filter_List = new List<e_u_Filter>();e_u_Filter_List.Add(new e_u_Filter { ID = 0, Name = "标准帧滤波" });e_u_Filter_List.Add(new e_u_Filter { ID = 1, Name = "扩展帧滤波" });e_u_Filter_List.Add(new e_u_Filter { ID = 2, Name = "禁能滤波" });comboBox_e_u_Filter.ItemsSource = e_u_Filter_List;comboBox_e_u_Filter.SelectedIndex = 2;//禁用List<e_u_startid> e_u_startid_List = new List<e_u_startid>();e_u_startid_List.Add(new e_u_startid { ID = 0, Name = "1" });textBox_e_u_startid.ItemsSource = e_u_startid_List;textBox_e_u_startid.SelectedIndex = 0;List<e_u_endid> e_u_endid_List = new List<e_u_endid>();e_u_endid_List.Add(new e_u_endid { ID = 0, Name = "FF" });textBox_e_u_endid.ItemsSource = e_u_endid_List;textBox_e_u_endid.SelectedIndex = 0;}#region 显示接收数据/// <summary>/// 显示接收数据/// </summary>unsafe private void ReceiveServer(){UInt32 res = new UInt32();res = VCI_GetReceiveNum(m_devtype, m_devind, m_canind);if (res == 0)return;IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VCI_CAN_OBJ)) * (Int32)res);res = VCI_Receive(m_devtype, m_devind, m_canind, pt, res, 100);String str = "";for (UInt32 i = 0; i < res; i++){VCI_CAN_OBJ obj = (VCI_CAN_OBJ)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(VCI_CAN_OBJ))), typeof(VCI_CAN_OBJ));str = "收到: ";str += "ID:0x" + System.Convert.ToString((Int32)obj.ID, 16);str += " 格式:";if (obj.RemoteFlag == 0)str += "数据帧 ";elsestr += "远程帧 ";if (obj.ExternFlag == 0)str += "标准帧 ";elsestr += "扩展帧 ";if (obj.RemoteFlag == 0){str += "数据:";byte len = (byte)(obj.DataLen % 9);byte j = 0;if (j++ < len)str += " " + obj.Data[0].ToString("X2");if (j++ < len)str += " " + obj.Data[1].ToString("X2");if (j++ < len)str += " " + obj.Data[2].ToString("X2");if (j++ < len)str += " " + obj.Data[3].ToString("X2");if (j++ < len)str += " " + obj.Data[4].ToString("X2");if (j++ < len)str += " " + obj.Data[5].ToString("X2");if (j++ < len)str += " " + obj.Data[6].ToString("X2");if (j++ < len)str += " " + obj.Data[7].ToString("X2");}System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{listBox_Info.Items.Add(str);listBox_Info_Count.Content = listBox_Info.Items.Count;listBox_Info.SelectedIndex = listBox_Info.Items.Count;listBox_Info.ScrollIntoView(listBox_Info.SelectedItem);}));if (listBox_Info.Items.Count >= 9999){try{System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{listBox_Info.Items.Clear();listBox_Info_Count.Content = 0;}));}catch{Dispatcher.Invoke(new Action(delegate{listBox_Info.Items.Clear();listBox_Info_Count.Content = 0;}));}}}Marshal.FreeHGlobal(pt);}#endregion#endregion#region 开启节点/// <summary>/// 开启节点/// </summary>/// <param name="sender"></param>/// <param name="e"></param>unsafe private void OpenCAN_Click(object sender, EventArgs e){if (m_bOpen == 0){Dispatcher.Invoke(new Action(delegate{MessageBox.Show("设备未连接,请先点击【连接并启动】按钮", this);}));return;}try{string FrameID = "01 00";System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{VCI_CAN_OBJ sendobj = new VCI_CAN_OBJ();sendobj.SendType = (byte)0;sendobj.RemoteFlag = (byte)0;sendobj.ExternFlag = (byte)0;sendobj.ID = System.Convert.ToUInt32("0x" + "00000000", 16);int len = (FrameID.Length + 1) / 3;sendobj.DataLen = System.Convert.ToByte(len);String strdata = FrameID;int i = -1;if (i++ < len - 1)sendobj.Data[0] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[1] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[2] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[3] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[4] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[5] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[6] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[7] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);int nTimeOut = 0;VCI_SetReference(m_devtype, m_devind, m_canind, 4, (byte*)&nTimeOut);if (VCI_Transmit(m_devtype, m_devind, m_canind, ref sendobj, 1) == 0){Dispatcher.Invoke(new Action(delegate{MessageBox.Show("节点开启失败", this);}));return;}}));}catch { }}#endregion
#region 发送数据VCI_CAN_OBJ sendobj = new VCI_CAN_OBJ();/// <summary>/// CAN发送数据,CANID、FrameData数据/// </summary>/// <param name="CANID"></param>/// <param name="FrameData"></param>unsafe private void CANSendMessage(string CANID, String FrameData){if (m_bOpen == 0){Dispatcher.Invoke(new Action(delegate{MessageBox.Show("设备未连接,请先点击【连接并启动】按钮", this);}));return;}try{sendobj.SendType = (byte)0;sendobj.RemoteFlag = (byte)0;sendobj.ExternFlag = (byte)0;sendobj.ID = System.Convert.ToUInt32("0x" + CANID, 16);int len = (FrameData.Length + 1) / 3;sendobj.DataLen = System.Convert.ToByte(len);String strdata = FrameData;int i = -1;System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{if (i++ < len - 1)sendobj.Data[0] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[1] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[2] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[3] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[4] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[5] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[6] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);if (i++ < len - 1)sendobj.Data[7] = System.Convert.ToByte("0x" + strdata.Substring(i * 3, 2), 16);int nTimeOut = 0;VCI_SetReference(m_devtype, m_devind, m_canind, 4, (byte*)&nTimeOut);if (VCI_Transmit(m_devtype, m_devind, m_canind, ref sendobj, 1) == 0){Thread.Sleep(SleppTime);}}));if (ShowSendMsg){SHOWCANID = CANID;System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{listBox_Send.Items.Add(DateTime.Now.ToString(" HH:mm:ss") + " 发送: " + SHOWCANID + " " + FrameData);listBox_Send_Count.Content = listBox_Send.Items.Count;listBox_Send.SelectedIndex = listBox_Send.Items.Count;listBox_Send.ScrollIntoView(listBox_Send.SelectedItem);listBox_Send.ScrollIntoView(listBox_Send.SelectedIndex);}));}if (listBox_Send.Items.Count >= 9999){listBox_Send.Items.Clear();listBox_Send_Count.Content = 0;}}catch{}}#endregion