Beispiel #1
0
        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            USB2LIN_EX.LIN_EX_MSG[] msg     = new USB2LIN_EX.LIN_EX_MSG[2];
            USB2LIN_EX.LIN_EX_MSG[] echoMsg = new USB2LIN_EX.LIN_EX_MSG[4];

            /* 1st message is break message */
            msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
            msg[0].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_BK;
            msg[0].Timestamp = 10;

            /* 2nd message is the data message */
            msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
            msg[1].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_MW;
            msg[1].Data      = new Byte[8];
            msg[1].Timestamp = 10;
            msg[1].PID       = 0x97;
            msg[1].DataLen   = 8;
            msg[1].CheckType = USB2LIN_EX.LIN_EX_CHECK_EXT;

            /* load into the data */
            msg[1].Data[0] = 0x01;
            msg[1].Data[1] = autoMode;
            msg[1].Data[2] = 0x00;
            msg[1].Data[3] = 0x00;

            if (autoMode < 18)
            {
                autoMode++;
            }
            else
            {
                autoMode = 2;
            }

            // send out the message
            IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USB2LIN_EX.LIN_EX_MSG)) * echoMsg.Length);

            ret = USB2LIN_EX.LIN_EX_MasterSync(devHandle, linIdx, msg, pt, msg.Length);
            if (ret < USB2LIN_EX.LIN_EX_SUCCESS)
            {
                //f2.richTextBox1.AppendText("Lin message send failed! \n");
                //f2.richTextBox1.AppendText("Error code:" + ret.ToString());
                return;
            }
            else
            {
                //f2.richTextBox1.AppendText("Lin message send success! \n");
            }

            Marshal.FreeHGlobal(pt);
        }
Beispiel #2
0
        private void finalizeAmbLightClient()
        {
            /* clear the switch status to all off */
            USB2LIN_EX.LIN_EX_MSG[] msg     = new USB2LIN_EX.LIN_EX_MSG[2];
            USB2LIN_EX.LIN_EX_MSG[] echoMsg = new USB2LIN_EX.LIN_EX_MSG[4];

            Byte chksumVal = 0;

            if (isDeviceOpen)
            {
                /* 1st message is break message */
                msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
                msg[0].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_BK;
                msg[0].Timestamp = 10;

                /* 2nd message is the data message */
                msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
                msg[1].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_MW;
                msg[1].Data      = new Byte[8];
                msg[1].Timestamp = 10;
                msg[1].PID       = 0x17;
                msg[1].DataLen   = 8;
                msg[1].CheckType = USB2LIN_EX.LIN_EX_CHECK_EXT;

                msg[1].Data[0] = 0x00;
                msg[1].Data[1] = 0x00;
                msg[1].Data[2] = 0x00;
                msg[1].Data[3] = 0x00;
                msg[1].Data[4] = 0x00;
                msg[1].Data[5] = 0x00;
                msg[1].Data[6] = 0x00;
                msg[1].Data[7] = 0x00;

                // checksum calculation
                for (Byte i = 0; i < 8; i++)
                {
                    chksumVal = (Byte)(chksumVal + msg[1].Data[i]);
                }
                chksumVal    = (Byte)(255 - (chksumVal + 0x97));
                msg[1].Check = chksumVal;

                // send out the message
                IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USB2LIN_EX.LIN_EX_MSG)) * echoMsg.Length);

                ret = USB2LIN_EX.LIN_EX_MasterSync(devHandle, linIdx, msg, pt, msg.Length);
                if (ret < USB2LIN_EX.LIN_EX_SUCCESS)
                {
                    //f2.richTextBox1.AppendText("Lin message send failed! \n");
                    //f2.richTextBox1.AppendText("Error code:" + ret.ToString());
                    return;
                }
                else
                {
                    //f2.richTextBox1.AppendText("Lin message send success! \n");
                }

                Marshal.FreeHGlobal(pt);
            }
            else
            {
            }
        }
Beispiel #3
0
        private void Button1_Click(object sender, EventArgs e)
        {
            Byte brightnessLevel = 0;
            Byte lightMode       = 0;
            Byte freeModeL       = 0;
            Byte freeModeT       = 0;
            Byte freeModeR       = 0;
            Byte chksumVal       = 0;

            // initialize the message object
            USB2LIN_EX.LIN_EX_MSG[] msg     = new USB2LIN_EX.LIN_EX_MSG[2];
            USB2LIN_EX.LIN_EX_MSG[] echoMsg = new USB2LIN_EX.LIN_EX_MSG[4];

            if (isDeviceOpen)
            {
                /* 1st message is break message */
                msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
                msg[0].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_BK;
                msg[0].Timestamp = 10;

                /* 2nd message is the data message */
                msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
                msg[1].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_MW;
                msg[1].Data      = new Byte[8];
                msg[1].Timestamp = 10;
                msg[1].PID       = 0x97;
                msg[1].DataLen   = 8;
                msg[1].CheckType = USB2LIN_EX.LIN_EX_CHECK_EXT;

                // load and pack the data
                lightMode = (Byte)comboBox1.SelectedIndex;
                if (lightMode < 17)
                {
                    lightMode = (Byte)(lightMode + 2);
                }
                else if (lightMode == 17)
                {
                    lightMode = (Byte)0xff;
                }
                else
                {
                    /* do nothing */
                }
                freeModeL = (byte)(comboBox2.SelectedIndex + 1);
                freeModeT = (byte)(comboBox3.SelectedIndex + 1);
                freeModeR = (byte)(comboBox4.SelectedIndex + 1);

                if (radioButton1.Checked)
                {
                    brightnessLevel = 3;
                }
                else if (radioButton2.Checked)
                {
                    brightnessLevel = 2;
                }
                else if (radioButton3.Checked)
                {
                    brightnessLevel = 1;
                }
                else
                {
                    brightnessLevel = 0;
                }

                msg[1].Data[0]  = ((Byte)(brightnessLevel << 4));
                msg[1].Data[0] |= 0x01;
                msg[1].Data[1]  = lightMode;
                msg[1].Data[2]  = freeModeR;
                msg[1].Data[2] |= (Byte)(freeModeL << 4);
                msg[1].Data[3]  = freeModeT;

                // checksum calculation
                //for(Byte i = 0; i < 8; i++)
                //{
                //    chksumVal = (Byte)(chksumVal + msg[1].Data[i]);
                //}
                //chksumVal = (Byte)(255 - (chksumVal + 0x97));
                //msg[1].Check = chksumVal;

                // send out the message
                IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USB2LIN_EX.LIN_EX_MSG)) * echoMsg.Length);

                ret = USB2LIN_EX.LIN_EX_MasterSync(devHandle, linIdx, msg, pt, msg.Length);
                if (ret < USB2LIN_EX.LIN_EX_SUCCESS)
                {
                    f2.richTextBox1.AppendText("Lin message send failed! \n");
                    f2.richTextBox1.AppendText("Error code:" + ret.ToString());
                    return;
                }
                else
                {
                    f2.richTextBox1.AppendText("Lin message send success! \n");
                }

                Marshal.FreeHGlobal(pt);
            }
            else
            {
            }
        }
Beispiel #4
0
        private void Button3_Click(object sender, EventArgs e)
        {
            USB2LIN_EX.LIN_EX_MSG[] msg     = new USB2LIN_EX.LIN_EX_MSG[2];
            USB2LIN_EX.LIN_EX_MSG[] echoMsg = new USB2LIN_EX.LIN_EX_MSG[4];

            // Start the asynchronous operation: auto led mode
            if (backgroundWorker1.IsBusy == false)
            {
                backgroundWorker1.RunWorkerAsync();
            }

            if (isAutoRun == false)
            {
                isAutoRun = true;
                aTimer.Start();

                /* 1st message is break message */
                msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
                msg[0].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_BK;
                msg[0].Timestamp = 10;

                /* 2nd message is the data message */
                msg[0]           = new USB2LIN_EX.LIN_EX_MSG();
                msg[1].MsgType   = USB2LIN_EX.LIN_EX_MSG_TYPE_MW;
                msg[1].Data      = new Byte[8];
                msg[1].Timestamp = 10;
                msg[1].PID       = 0x97;
                msg[1].DataLen   = 8;
                msg[1].CheckType = USB2LIN_EX.LIN_EX_CHECK_EXT;

                /* load into the data */
                msg[1].Data[0] = 0x01;
                msg[1].Data[1] = autoMode;
                msg[1].Data[2] = 0x00;
                msg[1].Data[3] = 0x00;

                autoMode++;

                // send out the message
                IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USB2LIN_EX.LIN_EX_MSG)) * echoMsg.Length);

                ret = USB2LIN_EX.LIN_EX_MasterSync(devHandle, linIdx, msg, pt, msg.Length);
                //if (ret < USB2LIN_EX.LIN_EX_SUCCESS)
                //{
                //    f2.richTextBox1.AppendText("Lin message send failed! \n");
                //    f2.richTextBox1.AppendText("Error code:" + ret.ToString());
                //    return;
                //}
                //else
                //{
                //    f2.richTextBox1.AppendText("Lin message send success! \n");
                //}

                Marshal.FreeHGlobal(pt);
            }
            else
            {
                isAutoRun = false;
                autoMode  = 2;
                aTimer.Stop();
                finalizeAmbLightClient();
            }
        }