Example #1
0
        private string canreceive2(out Ecan.CAN_OBJ[] resultobj, int count)
        {
            string canresult = "";

            Ecan.CAN_ERR_INFO errinfo;
            int    workStationCount = count;
            int    size             = Marshal.SizeOf(typeof(Ecan.CAN_OBJ));
            IntPtr infosIntptr      = Marshal.AllocHGlobal(size * workStationCount);

            resultobj = new Ecan.CAN_OBJ[workStationCount];

            //    MessageBox.Show(count.ToString());

            Delay(40);
            if (Ecan.Receive2(4, 0, 0, infosIntptr, (ushort)count, 10) == Ecan.ECANStatus.STATUS_OK) /* MessageBox.Show(resultobj.ID.ToString("X"));*/ Delay{
                    (30);
            }
Example #2
0
        void Thread2_Test()
        {
            MessageBox.Show("start2");
            Ecan.CAN_OBJ[] recbusinfo2, recbusinfo3;
            Ecan.CAN_OBJ   sendbusinfo1 = new Ecan.CAN_OBJ();
            Ecan.CAN_OBJ   sendbusinfo2 = new Ecan.CAN_OBJ();
            string         ccdata       = "00";

            recbusinfo2           = new Ecan.CAN_OBJ[1];
            recbusinfo3           = new Ecan.CAN_OBJ[1];
            sendbusinfo1.SendType = 0; sendbusinfo1.data = new byte[8]; sendbusinfo1.Reserved = new byte[3]; sendbusinfo1.RemoteFlag = 0; sendbusinfo1.ExternFlag = 1;
            sendbusinfo1.DataLen  = Convert.ToByte(0);
            int tlen = sendbusinfo1.DataLen - 1, ican;

            for (ican = 0; ican <= tlen; ican++)
            {
                sendbusinfo1.data[ican] = Convert.ToByte(ccdata.Substring(0 + ican * 2, 2), 0X10);
            }
            sendbusinfo1.ID = Convert.ToUInt32("60C2110", 16);//1

            sendbusinfo2.SendType = 0; sendbusinfo2.data = new byte[8]; sendbusinfo2.Reserved = new byte[3]; sendbusinfo2.RemoteFlag = 0; sendbusinfo2.ExternFlag = 1;
            sendbusinfo2.DataLen  = Convert.ToByte(0);
            tlen = sendbusinfo2.DataLen - 1;

            for (ican = 0; ican <= tlen; ican++)
            {
                sendbusinfo2.data[ican] = Convert.ToByte(ccdata.Substring(0 + ican * 2, 2), 0X10);
            }
            sendbusinfo2.ID = Convert.ToUInt32("60C2110", 16);

            if (chart1.InvokeRequired == false)
            {
                Dictionary <string, CheckBox> checkboxList = new Dictionary <string, CheckBox>();
                List <int> txData2 = new List <int>(); // { 2011, 2012, 2013, 2014, 2015, 2016 };
                List <int> tyData2 = new List <int>();
                List <int> txData3 = new List <int>(); // { 2011, 2012, 2013, 2014, 2015, 2016 };
                List <int> tyData3 = new List <int>();
                List <int> txData  = new List <int>();
                List <int> tyData  = new List <int>();
                int        ibuf;
                foreach (Control item in this.Controls)
                {
                    if (item.GetType() == typeof(System.Windows.Forms.CheckBox) && item.Name.StartsWith("checkBox"))
                    {
                        checkboxList.Add(item.Name, (CheckBox)item);
                    }
                }
                do
                {
                    cansend2(sendbusinfo1, out recbusinfo2, 1);
                    cansend2(sendbusinfo2, out recbusinfo3, 1);
                    // this.chart1.DataSource = list;
                    // list.Add(new ChartTestData(i));
                    //list2.Add(new ChartTestData(i));
                    // { 9, 6, 7, 4, 5, 4 };

                    /*  for (ibuf = 1; ibuf < 9; ibuf++)
                     * {
                     * string actual_test = "checkBox" + ibuf.ToString();
                     * if ((ibuf % 2 != 0) && (ibuf != 7))
                     *    {
                     *    if (checkboxList[actual_test].Checked == true)
                     *    {
                     *        txData[ibuf - 1].Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                     *        tyData[ibuf - 1].Add(hextodec(recbusinfo2[0].data[ibuf].ToString("X2") + recbusinfo2[0].data[ibuf - 1].ToString("X2")));
                     *        chart1.Series[ibuf - 1].Points.DataBindXY(txData[ibuf - 1], tyData[ibuf - 1]);
                     *    }
                     *    }
                     *    if ((ibuf % 2 == 0) && (ibuf != 8))
                     *    {
                     *        txData[ibuf - 1].Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                     *        tyData[ibuf - 1].Add(hextodec(recbusinfo3[0].data[ibuf - 1].ToString("X2") + recbusinfo3[0].data[ibuf - 2].ToString("X2")));
                     *        chart1.Series[ibuf - 1].Points.DataBindXY(txData[ibuf - 1], tyData[ibuf - 1]);
                     *    }
                     *
                     * }
                     *
                     */
                    //    txData.Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                    //  tyData.Add(hextodec(recbusinfo2[0].data[1].ToString("X2") + recbusinfo2[0].data[0].ToString("X2")));

                    //  chart1.Series[1].Points.DataBindXY(txData, tyData);//1

                    //chart1.Series[1].Points.DataBind();

                    /*      txData2.Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                     *    tyData2.Add(hextodec(recbusinfo2[0].data[1].ToString("X2") + recbusinfo2[0].data[0].ToString("X2")));
                     *
                     *    chart1.Series[1].Points.DataBindXY(txData2, tyData2);//1
                     *
                     *    txData3.Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                     *       tyData3.Add(hextodec(recbusinfo3[0].data[1].ToString("X2") + recbusinfo3[0].data[0].ToString("X2")));
                     *
                     *      chart1.Series[0].Points.DataBindXY(txData3, tyData3);
                     */


                    Delay(1);
                } while (flag == true);
            }
            else
            {
                // MessageBox.Show("Mid2");
                mydelegate mytest = new mydelegate(Thread2_Test);
                chart1.BeginInvoke(mytest);
            }
        }
Example #3
0
        void Thread_Test()
        {
            //MessageBox.Show("start");
            Ecan.CAN_OBJ[] recbusinfo2, recbusinfo3;
            Ecan.CAN_OBJ   sendbusinfo1 = new Ecan.CAN_OBJ();
            Ecan.CAN_OBJ   sendbusinfo2 = new Ecan.CAN_OBJ();
            string         ccdata       = "00";

            recbusinfo2           = new Ecan.CAN_OBJ[1];
            recbusinfo3           = new Ecan.CAN_OBJ[1];
            sendbusinfo1.SendType = 0; sendbusinfo1.data = new byte[8]; sendbusinfo1.Reserved = new byte[3]; sendbusinfo1.RemoteFlag = 0; sendbusinfo1.ExternFlag = 1;
            sendbusinfo1.DataLen  = Convert.ToByte(0);
            int tlen = sendbusinfo1.DataLen - 1, ican;

            for (ican = 0; ican <= tlen; ican++)
            {
                sendbusinfo1.data[ican] = Convert.ToByte(ccdata.Substring(0 + ican * 2, 2), 0X10);
            }
            sendbusinfo1.ID = Convert.ToUInt32("60C2010", 16);


            sendbusinfo2.SendType = 0; sendbusinfo2.data = new byte[8]; sendbusinfo2.Reserved = new byte[3]; sendbusinfo2.RemoteFlag = 0; sendbusinfo2.ExternFlag = 1;
            sendbusinfo2.DataLen  = Convert.ToByte(0);
            tlen = sendbusinfo2.DataLen - 1;

            for (ican = 0; ican <= tlen; ican++)
            {
                sendbusinfo2.data[ican] = Convert.ToByte(ccdata.Substring(0 + ican * 2, 2), 0X10);
            }
            sendbusinfo2.ID = Convert.ToUInt32("60C2110", 16);

            int ibuf = 0;

            //MessageBox.Show("mid1");
            if (chart1.InvokeRequired == false)
            {
                Dictionary <string, CheckBox> checkboxList = new Dictionary <string, CheckBox>();
                foreach (Control item in this.Controls)
                {
                    if (item.GetType() == typeof(System.Windows.Forms.CheckBox) && item.Name.StartsWith("checkBox"))
                    {
                        checkboxList.Add(item.Name, (CheckBox)item);
                    }
                }
                // List<int> txData2 = new List<int>();// { 2011, 2012, 2013, 2014, 2015, 2016 };
                // List<int> tyData2 = new List<int>();
                //  List<int> txData3 = new List<int>();// { 2011, 2012, 2013, 2014, 2015, 2016 };
                //  List<int> tyData3 = new List<int>();
                DataTable[] dataTable = null;
                dataTable = new DataTable[8];
                Dictionary <string, DataRow> rowList = new Dictionary <string, DataRow>();
                DataRow    dataRow1    = null;
                DataRow    dataRow2    = null;
                DataRow[]  dataRowlist = new DataRow[8];
                DataRow    dataRow3    = null;
                DataRow    dataRow4    = null;
                DataRow    dataRow5    = null;
                DataRow    dataRow6    = null;
                DataColumn column      = null;
                DataRow    dataRow7    = null;
                DataRow    dataRow8    = null;
                rowList.Add("datarow1", dataRow1);
                rowList.Add("datarow2", dataRow2);
                rowList.Add("datarow3", dataRow3);
                rowList.Add("datarow4", dataRow4);
                rowList.Add("datarow5", dataRow5);
                rowList.Add("datarow6", dataRow6);
                rowList.Add("datarow7", dataRow7);
                rowList.Add("datarow8", dataRow8);


                for (int tabnum = 0; tabnum < 8; tabnum++)
                {
                    dataTable[tabnum] = new DataTable();
                    column            = new DataColumn("Time", typeof(int));
                    //  MessageBox.Show("col1"+ tabnum.ToString());
                    dataTable[tabnum].Columns.Add(column);
                    //  MessageBox.Show("acol1");
                    column = new DataColumn("Voltage", typeof(int));
                    //MessageBox.Show("col2"+ tabnum.ToString());
                    dataTable[tabnum].Columns.Add(column);
                }
                do
                {
                    cansend2(sendbusinfo1, out recbusinfo2, 1);
                    cansend2(sendbusinfo2, out recbusinfo3, 1);

                    /*  dataRow = dataTable.NewRow();
                     * dataRow["Time"] = int.Parse(sw.ElapsedMilliseconds.ToString());
                     *
                     *    dataRow["Voltage"] = hextodec(recbusinfo2[0].data[1].ToString("X2") + recbusinfo2[0].data[0].ToString("X2"));
                     *
                     * dataTable.Rows.Add(dataRow);
                     *
                     * chart1.Series[1].Points.DataBind(dataTable.AsEnumerable(), "Time", "Voltage", "");*/
                    for (ibuf = 1; ibuf < 9; ibuf++)
                    {
                        string actual_test = "checkBox" + ibuf.ToString();
                        if ((ibuf % 2 != 0) && (ibuf != 7))
                        {
                            if (checkboxList[actual_test].Checked == true)
                            {
                                dataRowlist[ibuf - 1]            = dataTable[ibuf - 1].NewRow();
                                dataRowlist[ibuf - 1]["Time"]    = int.Parse(sw.ElapsedMilliseconds.ToString());
                                dataRowlist[ibuf - 1]["Voltage"] = hextodec(recbusinfo2[0].data[ibuf].ToString("X2") + recbusinfo2[0].data[ibuf - 1].ToString("X2"));
                                dataTable[ibuf - 1].Rows.Add(dataRowlist[ibuf - 1]);
                                //   MessageBox.Show(ibuf.ToString());
                                chart1.Series[ibuf - 1].Points.DataBind(dataTable[ibuf - 1].AsEnumerable(), "Time", "Voltage", "");
                            }
                        }
                        if ((ibuf % 2 == 0) && (ibuf != 8))
                        {
                            if (checkboxList[actual_test].Checked == true)
                            {
                                dataRowlist[ibuf - 1]            = dataTable[ibuf - 1].NewRow();
                                dataRowlist[ibuf - 1]["Time"]    = int.Parse(sw.ElapsedMilliseconds.ToString());
                                dataRowlist[ibuf - 1]["Voltage"] = hextodec(recbusinfo3[0].data[ibuf - 1].ToString("X2") + recbusinfo3[0].data[ibuf - 2].ToString("X2"));
                                dataTable[ibuf - 1].Rows.Add(dataRowlist[ibuf - 1]);
                                // MessageBox.Show(ibuf.ToString());
                                chart1.Series[ibuf - 1].Points.DataBind(dataTable[ibuf - 1].AsEnumerable(), "Time", "Voltage", "");
                            }
                        }
                    }


                    //  txData.Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                    //    tyData.Add(hextodec(recbusinfo2[0].data[1].ToString("X2") + recbusinfo2[0].data[0].ToString("X2")));

                    //  chart1.Series[0].Points.DataBindXY(txData, tyData);


                    /*    txData[0].Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                     * tyData[0].Add(hextodec(recbusinfo2[0].data[1].ToString("X2") + recbusinfo2[0].data[0].ToString("X2")));
                     *
                     * chart1.Series[0].Points.DataBindXY(txData[0], tyData[0]);*/
                    //  txData3.Add(int.Parse(sw.ElapsedMilliseconds.ToString()));
                    // tyData3.Add(hextodec(recbusinfo3[0].data[1].ToString("X2") + recbusinfo3[0].data[0].ToString("X2")));
                    //chart1.Series[1].Points.DataBindXY(txData3, tyData3);



                    Delay(1);
                } while (flag == true);
            }
            else
            {
                // MessageBox.Show("Mid2");
                mydelegate mytest = new mydelegate(Thread_Test);
                chart1.BeginInvoke(mytest);
            }
        }