示例#1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            HelperTools.AppendCustomPrivatePath();
            Application.Run(new Form1());
        }
示例#2
0
        private void button_Send_Click(object sender, EventArgs e)
        {
            if (m_bOpen == 0)
            {
                return;
            }

            var id         = System.Convert.ToUInt32("0x" + textBox_ID.Text, 16);
            var sendType   = (SendMode)comboBox_SendType.SelectedIndex;
            var remoteFlag = comboBox_FrameFormat.SelectedIndex; // 是否为远程帧?
            var externFlag = comboBox_FrameType.SelectedIndex;   // 是否为扩展帧?
            var sendTimers = uint.Parse(textBox1.Text);
            var data       = HelperTools.SplitHexText(textBox_Data.Text);

            var sendobj = new VCI_CAN_OBJ[sendTimers];

            for (int j = 0; j < sendTimers; j++)
            {
                sendobj[j].SendType   = sendType;
                sendobj[j].RemoteFlag = (byte)remoteFlag;
                sendobj[j].ExternFlag = (byte)externFlag;
                sendobj[j].ID         = id;
                sendobj[j].DataLen    = System.Convert.ToByte(data.Length % 9);
                sendobj[j].Data       = data;
            }

            var sw = new Stopwatch();

            sw.Start();
            var res = VciNativeMethods.VCI_Transmit(m_devtype, m_devind, m_canind, sendobj, sendTimers);

            if (res == 0)
            {
                MessageBox.Show("发送失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            sw.Stop();
            Console.WriteLine("发送耗时 = {0} 秒", sw.Elapsed.TotalSeconds);
        }