Beispiel #1
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (m_bOpen == 1)
            {
                USB_CAN_device.CloseDevice();
                //USB_CAN_device.Config_CAN_Device(m_devtype, m_devind);
                //USB_CAN_device.OpenDevice();
                m_bOpen = 0;
            }
            else
            {
                m_devtype = m_arrdevtype[comboBox_devtype.SelectedIndex];
                m_devind  = (uint)comboBox_DevIndex.SelectedIndex;
                USB_CAN_device.Config_CAN_Device(m_devtype, m_devind);
                if (USB_CAN_device.OpenDevice() == 0)
                {
                    MessageBox.Show("打开设备失败,请检查设备类型和设备索引号是否正确", "错误",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                m_bOpen = 1;
                uint AccCode = System.Convert.ToUInt32("0x" + textBox_AccCode.Text, 16);
                uint AccMask = System.Convert.ToUInt32("0x" + textBox_AccMask.Text, 16);
                Byte Timing0 = System.Convert.ToByte("0x" + textBox_Time0.Text, 16);
                Byte Timing1 = System.Convert.ToByte("0x" + textBox_Time1.Text, 16);
                Byte Filter  = (Byte)(comboBox_Filter.SelectedIndex + 1);
                Byte Mode    = (Byte)comboBox_Mode.SelectedIndex;
                USB_CAN_device.Config_CAN_Param(AccCode, AccMask, Timing0, Timing1, Filter, Mode);
                if (comboBox_CANIndex.SelectedIndex == 0)
                {
                    m_canind_src = 0;
                    m_canind_dst = 1;
                }
                else
                {
                    m_canind_src = 1;
                    m_canind_dst = 0;
                }
                uint init_status_src, init_status_dst;
                init_status_src = USB_CAN_device.InitCAN(m_canind_src);
                init_status_dst = USB_CAN_device.InitCAN(m_canind_dst);
            }
            buttonConnect.Text = m_bOpen == 1?"断开":"连接";
            timer_rec.Enabled  = m_bOpen == 1?true:false;
        }
Beispiel #2
0
 public void Config_CAN_Device(USB_DEVICE_ID dev_id, uint dev_index)
 {
     m_devtype = (uint)dev_id;
     m_devind  = dev_index;
 }