public void ShowForm(CanData can)
        {
            _can = can;

            List<TextBox> textboxes = new List<TextBox>();
            textboxes.Add(Transmit_msg0);
            textboxes.Add(Transmit_msg1);
            textboxes.Add(Transmit_msg2);
            textboxes.Add(Transmit_msg3);
            textboxes.Add(Transmit_msg4);
            textboxes.Add(Transmit_msg5);
            textboxes.Add(Transmit_msg6);
            textboxes.Add(Transmit_msg7);

            Transmit_id.Text = String.Format("{0:X3}",_can.id);
            Transmit_dlc.Value = _can.dlc;
            TransmitInterfaceBox.SelectedItem = _can.hardware;
            for (int i = 0; i < _can.dlc; i++)
            {
                textboxes[i].Text = String.Format("{0:X2}", _can.msg[i]);
            }
            if (_can.flags == 2)
                Flag_Std.Checked = true;
            if (_can.flags == 4)
                Flag_Ext.Checked = true;
            if (_can.flags == 32)
                Flag_Err.Checked = true;
            if (_can.flags == 1)
                Flag_Rtr.Checked = true;
        }
        public static bool GenericLinReceive(CanData can)
        {
            Canlib.canStatus status;

            // status = Canlib.canRead(GenericCanBus.CAN_handle0, out can.id, can.msg, out can.dlc, out can.flags, out can.time);

            status = Canlib.canRead(can.handle, out can.id, can.msg, out can.dlc, out can.flags, out can.time);

            //Debug.WriteLine("InRead");
            //MainWindow.ErrorDisplayString(CommonUtils.DisplayMsg(can));

            if (status != Canlib.canStatus.canOK)
            {
                //Debug.WriteLine("CanReceive -- false");
                return false;
            }
            else
            {
                //Debug.WriteLine("CanReceive -- true");
                return true;
            }
        }
        // CAN Receive
        public static bool CanReceive(CanData can)
        {
            Byte ReturnError = 0;

            ECOMLibrary.SFFMessage RxMessage = new ECOMLibrary.SFFMessage();
            ECOMLibrary.EFFMessage ExMessage = new ECOMLibrary.EFFMessage();

            try
            {
                //ECOM library call to get a standard message
                ReturnError = ECOMLibrary.CANReceiveMessage((UInt32)BusInterface.ReturnHandle(can.hardware), ref RxMessage);
            }
            catch {
                ErrorLog.NewLogEntry("ECOM", Convert.ToString(ReturnError));
            }

            if (ReturnError == 0)
            {
                // Converts the ID low and ID high
                can.id = Convert.ToInt32(RxMessage.IDL + RxMessage.IDH);
                can.dlc = Convert.ToInt32(RxMessage.DataLength);
                can.time = Convert.ToInt64(RxMessage.TimeStamp);

                // Puts the individual bytes into the can.msg byte array
                if (can.dlc > 0)
                    can.msg[0] = RxMessage.data1;
                if (can.dlc > 1)
                    can.msg[1] = RxMessage.data2;
                if (can.dlc > 2)
                    can.msg[2] = RxMessage.data3;
                if (can.dlc > 3)
                    can.msg[3] = RxMessage.data4;
                if (can.dlc > 4)
                    can.msg[4] = RxMessage.data5;
                if (can.dlc > 5)
                    can.msg[5] = RxMessage.data6;
                if (can.dlc > 6)
                    can.msg[6] = RxMessage.data7;
                if (can.dlc > 7)
                    can.msg[7] = RxMessage.data8;

                // Revisions Needed -- Need to pull flag information
                can.flags = Convert.ToInt32(RxMessage.options);

                //MainWindow.ErrorDisplayString(Convert.ToString(can.flags));

                // For error testing
                // MainWindow.ErrorDisplayByteArray(can.msg);
                //MainWindow.ErrorDisplayString(Convert.ToString(can.dlc));
            }
            else
            {
                ReturnError = ECOMLibrary.CANReceiveMessageEx((UInt32)BusInterface.ReturnHandle(can.hardware), ref ExMessage);

                can.id = Convert.ToInt32(ExMessage.ID);
                can.dlc = Convert.ToInt32(ExMessage.DataLength);
                can.time = Convert.ToInt64(ExMessage.TimeStamp);

                // Puts the individual bytes into the can.msg byte array
                if (can.dlc > 0)
                    can.msg[0] = ExMessage.data1;
                if (can.dlc > 1)
                    can.msg[1] = ExMessage.data2;
                if (can.dlc > 2)
                    can.msg[2] = ExMessage.data3;
                if (can.dlc > 3)
                    can.msg[3] = ExMessage.data4;
                if (can.dlc > 4)
                    can.msg[4] = ExMessage.data5;
                if (can.dlc > 5)
                    can.msg[5] = ExMessage.data6;
                if (can.dlc > 6)
                    can.msg[6] = ExMessage.data7;
                if (can.dlc > 7)
                    can.msg[7] = ExMessage.data8;

                // Revisions Needed -- Need to pull flag information
                can.flags = Convert.ToInt32(ExMessage.options);

                // For error testing
               //  MainWindow.ErrorDisplayByteArray(can.msg);

            }

            if (ReturnError != 0)
                return false;
            else
                return true;
        }
        // CAN Receive
        public static bool CanReceive(CanData can)
        {
            string hardwareString0 = can.hardware.Replace(" ", "");
            string[] msgOutput = hardwareString0.Split(';');

            return false;
        }
 //************************************
 // CAN Transmit for a single transmission
 //************************************
 public static void CanTransmitSingle(CanData can)
 {
     string hardwareString0 = can.hardware.Replace(" ", "");
     string[] msgOutput = hardwareString0.Split(';');
 }
        // CAN Receive
        public static bool GenericCanReceive(CanData can)
        {
            string hardwareString0 = can.hardware.Replace(" ", "");
            string[] msgOutput = hardwareString0.Split(';');

            // Kvaser receive section
            if (msgOutput[2] == "Kvaser") {
                return KvaserCanBus.CanReceive(can);
            } else if (msgOutput[2] == "ECom") {
                return ECOMCanBus.CanReceive(can);
            }

            return false;
        }
        //************************************
        // CAN Transmit for a single transmission
        //************************************
        public static void GenericCanTransmitSingle(CanData can)
        {
            string hardwareString0 = can.hardware.Replace(" ", "");
            string[] msgOutput = hardwareString0.Split(';');

            if (msgOutput[2] == "Kvaser") {
                KvaserCanBus.CanTransmitSingle(can);
            } else if (msgOutput[2] == "ECom") {
                ECOMCanBus.CanTransmitSingle(can);
            } else if (msgOutput[2] == "Intrepid"){
                IntrepidCanBus.CanTransmitSingle(can);
            }
        }
 // Checks the flags on transmitted or recieved messages
 private static void CheckFlags(CanData can)
 {
     can.flagString = "";
 }
        //************************************
        // CAN Transmit for a single transmission
        //************************************
        public static void CanTransmitSingle(CanData can)
        {
            string hardwareString0 = can.hardware.Replace(" ", "");
            string[] msgOutput = hardwareString0.Split(';');

            can.handle = BusInterface.ReturnHandle(can.hardware);

            // Threading Part
            /*CanWrite writeCan = new CanWrite();

            // Starts the Kvaser threading
            Thread t2 = new Thread(delegate()
            {
                writeCan.KvaserWrite(can);
            });
            t2.Start();
                */

            // Non-threading write option
            Canlib.canWriteWait(can.handle, can.id, can.msg, can.dlc, can.flags, 1000);
            CheckFlags(can);
        }
        //*******************************************
        // The worker thread for the backgroundWorker
        //*******************************************
        private void backgroundWorkerRead_DoWork(object sender, DoWorkEventArgs e)
        {
            int count = 0;
            CanData receiveCan = new CanData();
            CanData transmitCan = new CanData();
            string[] arguments = (string[])e.Argument;

            // to get the receive interface
            receiveCan.hardware = arguments[0];
            receiveCan.format = arguments[1];

            // to get the transmit interface
            transmitCan.hardware = arguments[4];
            transmitCan.format = arguments[1];

            string CarFilter = arguments[2];
            int numericMSB = int.Parse(arguments[3]);
            string ifThenOutput = null;

            while (true)
            {
                if (GenericCanBus.GenericCanReceive(receiveCan) == true)
                {
                    count++; //counts the number of packets received
                    (sender as BackgroundWorker).ReportProgress(count, CommonUtils.ConvertMsgArray(receiveCan, CarFilter, numericMSB));

                    if (IfThenActive)
                    {
                        //   ifThenOutput = ifthenxml.UpdateIfThenMachine(receiveCan, CarFilter);

                        if (ifThenOutput != null)
                        {
                            CommonUtils.ConvertStringtoCAN(transmitCan, ifThenOutput);
                            GenericCanBus.GenericCanTransmitSingle(transmitCan);
                        }
                    }
                }

                // Higher sleep times may cause packet lose; more testing needed - CEE
                System.Threading.Thread.Sleep(80);

                if ((sender as BackgroundWorker).CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }

                //while (GenericCanBus.GenericCanReceive(receiveCan))
                //{
                //    count++; //counts the number of packets received
                //    (sender as BackgroundWorker).ReportProgress(count, CommonUtils.ConvertMsgArray(receiveCan, CarFilter, numericMSB));
                //    System.Threading.Thread.Sleep(220);
                //    if (IfThenActive)
                //    {
                //        //   ifThenOutput = ifthenxml.UpdateIfThenMachine(receiveCan, CarFilter);

                //        if (ifThenOutput != null)
                //        {
                //            CommonUtils.ConvertStringtoCAN(transmitCan, ifThenOutput);
                //            GenericCanBus.GenericCanTransmitSingle(transmitCan);
                //        }
                //    }
                //}

                //if ((sender as BackgroundWorker).CancellationPending)
                //{
                //    e.Cancel = true;
                //    //break;
                //}
        }
        // The worker thread for the backgroundWorker
        private void backgroundWorkerTester_DoWork_1(object sender, DoWorkEventArgs e)
        {
            //MainWindow.ErrorDisplayString("In Tester Present Loop");

            CanData can = new CanData();

            // TesterPresentID.Text, TesterPresentDLC.Text, TesterPresentMessage.Text, TransmitInterfaceBox.SelectedItem.ToString(), TimeBetween.Text
            string[] arguments = (string[])e.Argument;

            can.format = "hex";
            can.id = Convert.ToInt32(arguments[0], 16);
            can.dlc = Convert.ToInt32(arguments[1]);
            can.msg = CommonUtils.HexStringToByteArray(arguments[2]);
            can.hardware = arguments[3];

            while (true)
            {
                GenericCanBus.GenericCanTransmitSingle(can);
                System.Threading.Thread.Sleep(Convert.ToInt32(arguments[4]));

                if ((sender as BackgroundWorker).CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }
        }
        //*********************************************
        // Opens Packet Transmit Window for
        //Written by Parnian Najafi Borazjani
        //*********************************************
        private void TransmitFuzz_Click(object sender, EventArgs e)
        {
            CanData can = new CanData();
            string msgOutput = "";

            if (MonitorBox.SelectedIndices.Count > 0)
            {
                ListViewItem item = MonitorBox.SelectedItems[0];

                for (int x = 0; x < MonitorBox.Items.Count; x++)
                {
                    if (MonitorBox.Items[x].Selected)
                    {
                        msgOutput = MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.IdNo].Text + ";" + MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.DLC].Text + ";" + MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.Flags].Text + ";";

                        // Bases conversion of message on check box; needs revison to add error checking
                        if (Monitor_Hex.Checked == true)
                        {
                            can.format = "hex";
                            msgOutput += MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.Data].Text.Replace(" ", string.Empty);
                        }
                        else
                        {
                            can.format = "decimal";
                            msgOutput += MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.Data].Text;
                        }

                        // MessageBox.Show("Data to convert:" + msgOutput);
                        CommonUtils.ConvertStringtoCAN(can, msgOutput);

                        can.hardware = TransmitInterfaceBox.SelectedItem.ToString();

                        // Verbose Output
                        //if (VerboseTransmit.Checked == true)
                        //    MessageBox.Show(CommonUtils.DisplayMsg(can));
                        break;
                    }
                }
                TransmitPackets tp = new TransmitPackets();

                tp.ShowForm(can);
                tp.MdiParent = MainWindow.ActiveForm;
                tp.Show();
                MonitorBox.SelectedIndices.Clear();

                // Status Update
                //toolStripStatusLabel2.Text = CommonUtils.ErrorMsg("Transmit Message", can.status);
                //ErrorLog.NewLogEntry("CAN", "Transmit Message: " + can.status);
            }
        }
        //*********************************************
        // Transmission of the packets selected by the user
        //Written by Parnian Najafi Borazjani
        //*********************************************
        private void TransmitPackets2_Click(object sender, EventArgs e)
        {
            CanData can = new CanData();
            string msgOutput = "";

            if (MonitorBox.SelectedIndices.Count > 0)
            {
                ListViewItem item = MonitorBox.SelectedItems[0];

                for (int x = 0; x < MonitorBox.Items.Count; x++)
                {
                    if (MonitorBox.Items[x].Selected)
                    {
                        msgOutput = MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.IdNo].Text + ";" + MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.DLC].Text + ";" + MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.Flags].Text + ";";

                        // Bases conversion of message on check box; needs revison to add error checking
                        if (Monitor_Hex.Checked == true)
                        {
                            can.format = "hex";
                            msgOutput += MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.Data].Text.Replace(" ", string.Empty);
                        }
                        else
                        {
                            can.format = "decimal";
                            msgOutput += MonitorBox.Items[x].SubItems[(int)CommonUtils.BusFields.Data].Text;
                        }

                        // MessageBox.Show("Data to convert:" + msgOutput);
                        CommonUtils.ConvertStringtoCAN(can, msgOutput);

                        can.hardware = TransmitInterfaceBox.SelectedItem.ToString();

                        //bgTransmit.RunWorkerAsync(can);
                        GenericCanBus.GenericCanTransmitSingle(can);

                        // Verbose Output
                        if (VerboseTransmit.Checked == true)
                            MessageBox.Show(CommonUtils.DisplayMsg(can));
                    }
                }

                // Status Update
                toolStripStatusLabel2.Text = CommonUtils.ErrorMsg("Transmit Message", can.status);
                ErrorLog.NewLogEntry("CAN", "Transmit Message: " + can.status);
                FileLog.Log("CAN Transmit Message: " + can.status);
            }
        }
Exemple #14
0
 public static void GenericLinTransmit(CanData can)
 {
     can.status = Canlib.canWrite(can.handle, can.id, can.msg, can.dlc, can.flags);
 }
        // Not being used since single transmission does not need threading at this time
        /*public void KvaserWrite(CanData can)
        {
           // Canlib.canWrite(can.handle, can.id, can.msg, can.dlc, can.flags);
           // Canlib.canWriteSync(can.handle, 10000);
           Canlib.canWriteWait(can.handle, can.id, can.msg, can.dlc, can.flags,1000);
        }*/
        public void KvaserWriteMultiple(CanData can)
        {
            for (int x = 0; x < can.number; x++)
            {
                // MainWindow.ErrorDisplayString("can message: " + CommonUtils.DisplayMsg(can));
                can.status = Canlib.canWrite(can.handle, can.id, can.msg, can.dlc, can.flags);
                // MainWindow.ErrorDisplayString("can status: " + can.status);
                can.status1 = Canlib.canWriteSync(can.handle, 10000);
                //CheckFlags(can);
                System.Threading.Thread.Sleep(can.timeBtw);

                if (can.increment == true)
                    can.id++;
            }
        }
        // Checks the flags on transmitted or recieved messages
        private static void CheckFlags(CanData can)
        {
            can.flagString = "";

               if (can.hardware.IndexOf("Kvaser") != -1)
               {
               if ((can.flags & Canlib.canMSG_ERROR_FRAME) == Canlib.canMSG_ERROR_FRAME)
               {
                   can.errorFrame = true;
                   can.flagString += "E";
               }
               else if ((can.flags & Canlib.canMSG_EXT) == Canlib.canMSG_EXT)
                   can.flagString += "X";
               else if ((can.flags & Canlib.canMSG_RTR) == Canlib.canMSG_RTR)
                   can.flagString += "R";
               else if ((can.flags & Canlib.canMSG_TXACK) == Canlib.canMSG_TXACK)
                   can.flagString += "A";
               else if ((can.flags & Canlib.canMSG_WAKEUP) == Canlib.canMSG_WAKEUP)
                   can.flagString += "W";
               }
        }
        // CAN Transmit for multiple transmissions
        public static void CanTransmitMultiple(CanData can)
        {
            can.handle = BusInterface.ReturnHandle(can.hardware);
            ECOMCanWrite writeCan = new ECOMCanWrite();

            Thread t2 = new Thread(delegate()
            {
                writeCan.ECOMWriteMultiple(can);
            });
            t2.IsBackground = true;
            t2.Start();
        }
        //****************************
        // Transmit Settings Tab
        // Written by Parnian Najafi Borazjani
        //****************************
        private void TransmitPacket_Click(object sender, EventArgs e)
        {
            CanData can = new CanData();
            int number_messages = 1;
            string msgOutput = "";
            string flag;
            //if (Transmit_dlc.Value>8)
            //    MessageBox.Show("Messages can have a maximum of 8");
            // For the various flags
            // Need to implement an enumerated keyword to replace these numbers
            // These numbers are from the Kvaser library documentation and may not work on other CAN systems
            if (Flag_Ext.Checked == true)
                flag = "X";                     // Extended
            else if (Flag_Err.Checked == true)
                flag = "E";                     // Error
            else if (Flag_Rtr.Checked == true)
                flag = "R";                     // Remote
            else
                flag = "S";                     // Standard

            if (InputTests.IsStringNumeric(Transmit_NoMsg.Text) == true)
                number_messages = Convert.ToInt32(Transmit_NoMsg.Text);
            else
                MessageBox.Show("Error: Number of Messages is not Numeric", "Error", MessageBoxButtons.OK);

            msgOutput = Transmit_id.Text + ";" + Transmit_dlc.Text + ";" + flag + ";" + Transmit_msg0.Text + "-" + Transmit_msg1.Text + "-" + Transmit_msg2.Text + "-" + Transmit_msg3.Text + "-" + Transmit_msg4.Text + "-" + Transmit_msg5.Text + "-" + Transmit_msg6.Text + "-" + Transmit_msg7.Text;

            if (Transmit_Hex.Checked == true)
                can.format = "hex";
            else
                can.format = "decimal";

            CommonUtils.ConvertStringtoCAN(can, msgOutput);

            can.number = number_messages;
            can.timeBtw = 0;
            try
            {
                can.hardware = TransmitInterfaceBox.SelectedItem.ToString();

            if (IncrementIdentifier.Checked == true)
                    can.increment = true;

            GenericCanBus.GenericCanTransmitMultiple(can);
            //bgTransmit.RunWorkerAsync(can);

            toolStripStatusLabel2.Text = CommonUtils.ErrorMsg("Transmit Message", can.status);
            ErrorLog.NewLogEntry("CAN", "Transmit Message: " + can.status);

            if (VerboseTransmit.Checked == true)
                MessageBox.Show(CommonUtils.DisplayMsg(can));
            }
            catch
            {
                MessageBox.Show("No interface is turned on, please turn on the interfaces from \"Advanced Bus Control\" Window");
                this.Close();
                BusControl form = (BusControl)CommonUtils.GetOpenedForm<BusControl>();
                if (form == null)
                {
                    form = new BusControl();
                    form.Show();
                }
                else
                {
                    form.Select();
                }
            }
        }
        //************************************
        // CAN Transmit for a single transmission
        //************************************
        public static void CanTransmitSingle(CanData can)
        {
            // Implementation for Standard Message & Extended Message

            can.handle = BusInterface.ReturnHandle(can.hardware);
            //MainWindow.ErrorDisplayString("ECom Handle: " + Convert.ToString(can.handle));

            ECOMLibrary.SFFMessage txMessage = new ECOMLibrary.SFFMessage();
            ECOMLibrary.EFFMessage etxMessage = new ECOMLibrary.EFFMessage();

            // Pulls the top 3 bits for IDH and the bottom 8 bits for IDL
            txMessage.IDH = (byte)(can.id & 0x700);
            txMessage.IDL = (byte)(can.id & 0x0FF);
            // Converts the entire id into an unit for extended sending
            etxMessage.ID = (UInt32)can.id;

            txMessage.DataLength = (byte)can.dlc;
            etxMessage.DataLength = (byte)can.dlc;
            txMessage.options = (byte)can.flags;
            etxMessage.options = (byte)can.flags;

            // Puts the individual bytes into the can.msg byte array
            if (can.dlc > 0)
            {
                txMessage.data1 = can.msg[0];
                etxMessage.data1 = can.msg[0];
            }

            if (can.dlc > 1)
            {
                txMessage.data2 = can.msg[1];
                etxMessage.data2 = can.msg[1];
            }

            if (can.dlc > 2)
            {
                txMessage.data3 = can.msg[2];
                etxMessage.data3 = can.msg[2];
            }

            if (can.dlc > 3)
            {
                txMessage.data4 = can.msg[3];
                etxMessage.data4 = can.msg[3];
            }

            if (can.dlc > 4)
            {
                txMessage.data5 = can.msg[4];
                etxMessage.data5 = can.msg[4];
            }

            if (can.dlc > 5)
            {
                txMessage.data6 = can.msg[5];
                etxMessage.data6 = can.msg[5];
            }

            if (can.dlc > 6)
            {
                txMessage.data7 = can.msg[6];
                etxMessage.data7 = can.msg[6];
            }
            if (can.dlc > 7)
            {
                txMessage.data8 = can.msg[7];
                etxMessage.data8 = can.msg[7];
            }

            // Non-threading write option
            if (can.flags == 4)
                ECOMLibrary.CANTransmitMessageEx((UInt32)can.handle, ref etxMessage);
            else
                ECOMLibrary.CANTransmitMessage((UInt32)can.handle, ref txMessage);

            CheckFlags(can);
        }
        private void bgTransmit_DoWork(object sender, DoWorkEventArgs e)
        {
            CanData can = e.Argument as CanData;

            GenericCanBus.GenericCanTransmitMultiple(can);
        }
        public void ECOMWriteMultiple(CanData can)
        {
            for (int x = 0; x < can.number; x++)
            {
                can.handle = BusInterface.ReturnHandle(can.hardware);
                //MainWindow.ErrorDisplayString("ECom Handle: " + Convert.ToString(can.handle));

                ECOMLibrary.SFFMessage txMessage = new ECOMLibrary.SFFMessage();
                ECOMLibrary.EFFMessage etxMessage = new ECOMLibrary.EFFMessage();

                // Pulls the top 3 bits for IDH and the bottom 8 bits for IDL
                txMessage.IDH = (byte)(can.id & 0x700);
                txMessage.IDL = (byte)(can.id & 0x0FF);
                // Converts the entire id into an unit for extended sending
                etxMessage.ID = (UInt32)can.id;

                txMessage.DataLength = (byte)can.dlc;
                etxMessage.DataLength = (byte)can.dlc;
                txMessage.options = (byte)can.flags;
                etxMessage.options = (byte)can.flags;

                // Puts the individual bytes into the can.msg byte array
                if (can.dlc > 0)
                {
                    txMessage.data1 = can.msg[0];
                    etxMessage.data1 = can.msg[0];
                }

                if (can.dlc > 1)
                {
                    txMessage.data2 = can.msg[1];
                    etxMessage.data2 = can.msg[1];
                }

                if (can.dlc > 2)
                {
                    txMessage.data3 = can.msg[2];
                    etxMessage.data3 = can.msg[2];
                }

                if (can.dlc > 3)
                {
                    txMessage.data4 = can.msg[3];
                    etxMessage.data4 = can.msg[3];
                }

                if (can.dlc > 4)
                {
                    txMessage.data5 = can.msg[4];
                    etxMessage.data5 = can.msg[4];
                }

                if (can.dlc > 5)
                {
                    txMessage.data6 = can.msg[5];
                    etxMessage.data6 = can.msg[5];
                }

                if (can.dlc > 6)
                {
                    txMessage.data7 = can.msg[6];
                    etxMessage.data7 = can.msg[6];
                }

                if (can.dlc > 7)
                {
                    txMessage.data8 = can.msg[7];
                    etxMessage.data8 = can.msg[7];
                }

                if (can.flags == 4)
                    ECOMLibrary.CANTransmitMessageEx((UInt32)can.handle, ref etxMessage);
                else
                    ECOMLibrary.CANTransmitMessage((UInt32)can.handle, ref txMessage);

               System.Threading.Thread.Sleep(can.timeBtw);

               if (can.increment == true)
                    can.id++;
            }
        }
        // CAN Receive
        public static bool CanReceive(CanData can)
        {
            // string hardwareString0 = can.hardware.Replace(" ", "");
               // string[] msgOutput = hardwareString0.Split(';');

            // to pull the can.handle from the hardware selection
            can.handle = BusInterface.ReturnHandle(can.hardware);
            //MainWindow.ErrorDisplayString("can.handle: " + can.handle + " ; msg: " + msgOutput[3]);

            // Kvaser CAN Read
            Array.Clear(can.msg, 0, 8);
            can.status = Canlib.canRead(can.handle, out can.id, can.msg, out can.dlc, out can.flags, out can.time);
            // MainWindow.ErrorDisplayString("can.handle in receive: " + can.handle);
            CheckFlags(can);

            if (can.status != Canlib.canStatus.canOK)
                return false;
            else
                return true;
        }
 public static void GenericLinTransmit(CanData can)
 {
     can.status = Canlib.canWrite(can.handle, can.id, can.msg, can.dlc, can.flags);
 }
        //****************************
        // Transmit Settings Tab
        // Written by Parnian Najafi Borazjani
        //****************************
        private void TransmitPacket_Click(object sender, EventArgs e)
        {
            CanData can             = new CanData();
            int     number_messages = 1;
            string  msgOutput       = "";
            string  flag;

            //if (Transmit_dlc.Value>8)
            //    MessageBox.Show("Messages can have a maximum of 8");
            // For the various flags
            // Need to implement an enumerated keyword to replace these numbers
            // These numbers are from the Kvaser library documentation and may not work on other CAN systems
            if (Flag_Ext.Checked == true)
            {
                flag = "X";                     // Extended
            }
            else if (Flag_Err.Checked == true)
            {
                flag = "E";                     // Error
            }
            else if (Flag_Rtr.Checked == true)
            {
                flag = "R";                     // Remote
            }
            else
            {
                flag = "S";                     // Standard
            }
            if (InputTests.IsStringNumeric(Transmit_NoMsg.Text) == true)
            {
                number_messages = Convert.ToInt32(Transmit_NoMsg.Text);
            }
            else
            {
                MessageBox.Show("Error: Number of Messages is not Numeric", "Error", MessageBoxButtons.OK);
            }

            msgOutput = Transmit_id.Text + ";" + Transmit_dlc.Text + ";" + flag + ";" + Transmit_msg0.Text + "-" + Transmit_msg1.Text + "-" + Transmit_msg2.Text + "-" + Transmit_msg3.Text + "-" + Transmit_msg4.Text + "-" + Transmit_msg5.Text + "-" + Transmit_msg6.Text + "-" + Transmit_msg7.Text;

            if (Transmit_Hex.Checked == true)
            {
                can.format = "hex";
            }
            else
            {
                can.format = "decimal";
            }

            CommonUtils.ConvertStringtoCAN(can, msgOutput);

            can.number  = number_messages;
            can.timeBtw = 0;
            try
            {
                can.hardware = TransmitInterfaceBox.SelectedItem.ToString();

                if (IncrementIdentifier.Checked == true)
                {
                    can.increment = true;
                }

                GenericCanBus.GenericCanTransmitMultiple(can);
                //bgTransmit.RunWorkerAsync(can);

                toolStripStatusLabel2.Text = CommonUtils.ErrorMsg("Transmit Message", can.status);
                ErrorLog.NewLogEntry("CAN", "Transmit Message: " + can.status);

                if (VerboseTransmit.Checked == true)
                {
                    MessageBox.Show(CommonUtils.DisplayMsg(can));
                }
            }
            catch
            {
                MessageBox.Show("No interface is turned on, please turn on the interfaces from \"Advanced Bus Control\" Window");
                this.Close();
                BusControl form = (BusControl)CommonUtils.GetOpenedForm <BusControl>();
                if (form == null)
                {
                    form = new BusControl();
                    form.Show();
                }
                else
                {
                    form.Select();
                }
            }
        }