Esempio n. 1
0
        //发送config1
        public void sendConfig1Pack(Object o)
        {
            ArrayList       al      = (ArrayList)o;
            string          slaveId = Convert.ToString(al[0]);
            Gen2SlaveConfig g       = (Gen2SlaveConfig)al[1];
            Gen2SlaveInfo   gsi     = (Gen2SlaveInfo)al[2];

            if ((g.Sid == null || g.Sid.Equals("")) && (gsi.Sid != null && !gsi.Sid.Equals("")))
            {
                g.Sid = DataConverter.string2Hex(gsi.Sid).ToString();
            }
            if ((g.Covth == null || g.Covth.Equals("")) && (gsi.Covth != null && !gsi.Covth.Equals("")))
            {
                g.Covth = gsi.Covth.Replace("mV", String.Empty);
            }
            if ((g.Cuvth == null || g.Cuvth.Equals("")) && (gsi.Cuvth != null && !gsi.Cuvth.Equals("")))
            {
                g.Cuvth = gsi.Cuvth.Replace("mV", String.Empty);
            }
            if ((g.Foth == null || g.Foth.Equals("")) && (gsi.Foth != null && !gsi.Foth.Equals("")))
            {
                g.Foth = gsi.Foth.Replace("℃", String.Empty);
            }
            if ((g.Fcth == null || g.Fcth.Equals("")) && (gsi.Fcth != null && !gsi.Fcth.Equals("")))
            {
                g.Fcth = gsi.Fcth.Replace("℃", String.Empty);
            }
            if (!(DataConverter.canStirng2int(g.Sid) && DataConverter.canStirng2int(g.Covth) && DataConverter.canStirng2int(g.Cuvth) &&
                  DataConverter.canStirng2int(g.Foth) && DataConverter.canStirng2int(g.Fcth)))
            {
                flushVM(new Object[] { FunCode.SHOWINFO, "wrongdata" });
                return;
            }
            CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ();
            obj.Init();
            obj.RemoteFlag = 0; //数据帧
            obj.ExternFlag = 1; //扩展帧
            obj.SendType   = 0; //正常发送
            obj.ID         = uint.Parse("0C21" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber);
            byte[] b = new byte[8];
            b[1] = (byte)Convert.ToInt32(g.Sid);
            short d = (short)Convert.ToInt32(g.Covth);

            byte[] t = System.BitConverter.GetBytes(d);
            b[2]        = t[0];
            b[3]        = t[1];
            d           = (short)Convert.ToInt32(g.Cuvth);
            t           = System.BitConverter.GetBytes(d);
            b[4]        = t[0];
            b[5]        = t[1];
            b[6]        = (byte)(Convert.ToInt32(g.Foth) + 40);
            b[7]        = (byte)(Convert.ToInt32(g.Fcth) + 40);
            obj.Data    = b;
            obj.DataLen = 8;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
            flushVM(new Object[] { FunCode.SHOWINFO, "sendSuc" });
        }
Esempio n. 2
0
        //发送均衡控制指令
        public void sendBalancePack(Object o)
        {
            ArrayList       al      = (ArrayList)o;
            string          slaveId = Convert.ToString(al[0]);
            Gen2SlaveConfig g       = (Gen2SlaveConfig)al[1];

            CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ();
            obj.Init();
            obj.RemoteFlag = 0; //数据帧
            obj.ExternFlag = 1; //扩展帧
            obj.SendType   = 0; //正常发送
            obj.ID         = uint.Parse("1815" + "41" + slaveId, System.Globalization.NumberStyles.HexNumber);
            obj.Data       = g.getBalanceData();
            obj.DataLen    = 8;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
            flushVM(new Object[] { FunCode.SHOWINFO, "sendSuc" });
        }
Esempio n. 3
0
        public void sendRelay2Pack(Object o)
        {
            ArrayList       al      = (ArrayList)o;
            string          slaveId = Convert.ToString(al[0]);
            Gen2SlaveConfig g       = (Gen2SlaveConfig)al[1];

            CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ();
            obj.Init();
            obj.RemoteFlag = 0; //数据帧
            obj.ExternFlag = 1; //扩展帧
            obj.SendType   = 0; //正常发送
            obj.ID         = uint.Parse("181E" + slaveId + "41", System.Globalization.NumberStyles.HexNumber);
            //obj.Data = DataConverter.str2ASCII(g.TraceCode.Substring(0, 8));
            obj.DataLen = 8;

            byte[] b = new byte[8];
            //b[1] =(byte)( g.Realy2 == true ? 1 : 0);
            b[0] = (byte)((g.Realy2 == true ? 1 : 0) << 1 | 0x00);

            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int year   = currentTime.Year;
            int month  = currentTime.Month;
            int day    = currentTime.Day;
            int hour   = currentTime.Hour;
            int minute = currentTime.Minute;
            int second = currentTime.Second;

            b[1]     = DataConverter.strToHexByte((year - 2000).ToString())[0];
            b[2]     = DataConverter.strToHexByte(month.ToString())[0];
            b[3]     = DataConverter.strToHexByte(day.ToString())[0];
            b[4]     = DataConverter.strToHexByte(hour.ToString())[0];
            b[5]     = DataConverter.strToHexByte(minute.ToString())[0];
            b[6]     = DataConverter.strToHexByte(second.ToString())[0];
            b[7]     = (byte)Convert.ToInt32(g.CanLife);
            obj.Data = b;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
        }
Esempio n. 4
0
        //发送追溯码
        public void sendTraceCodePack(Object o)
        {
            ArrayList       al      = (ArrayList)o;
            string          slaveId = Convert.ToString(al[0]);
            Gen2SlaveConfig g       = (Gen2SlaveConfig)al[1];

            if (g.TraceCode == null || g.TraceCode.Length != 24)
            {
                flushVM(new Object[] { FunCode.SHOWINFO, "wrongdata" });
                return;
            }
            CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ();
            obj.Init();
            obj.RemoteFlag = 0; //数据帧
            obj.ExternFlag = 1; //扩展帧
            obj.SendType   = 0; //正常发送
            obj.ID         = uint.Parse("0C22" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber);
            obj.Data       = DataConverter.str2ASCII(g.TraceCode.Substring(0, 8));
            obj.DataLen    = 8;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
            Thread.Sleep(200);

            obj.ID      = uint.Parse("0C23" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber);
            obj.Data    = DataConverter.str2ASCII(g.TraceCode.Substring(8, 8));
            obj.DataLen = 8;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
            Thread.Sleep(200);

            obj.ID      = uint.Parse("0C25" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber);
            obj.Data    = DataConverter.str2ASCII(g.TraceCode.Substring(16, 8));
            obj.DataLen = 8;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
        }
Esempio n. 5
0
        //发送config2
        public void sendConfig2Pack(Object o)
        {
            ArrayList       al      = (ArrayList)o;
            string          slaveId = Convert.ToString(al[0]);
            Gen2SlaveConfig g       = (Gen2SlaveConfig)al[1];
            Gen2SlaveInfo   gsi     = (Gen2SlaveInfo)al[2];

            if ((g.Bcnt_a == null || g.Bcnt_a.Equals("")) && (gsi.Bcnt_A != null && !gsi.Bcnt_A.Equals("")))
            {
                g.Bcnt_a = gsi.Bcnt_A;
            }
            if ((g.Bcnt_b == null || g.Bcnt_b.Equals("")) && (gsi.Bcnt_B != null && !gsi.Bcnt_B.Equals("")))
            {
                g.Bcnt_b = gsi.Bcnt_B;
            }
            if ((g.Bcnt_c == null || g.Bcnt_c.Equals("")) && (gsi.Bcnt_C != null && !gsi.Bcnt_C.Equals("")))
            {
                g.Bcnt_c = gsi.Bcnt_C;
            }
            if ((g.Bcnt_d == null || g.Bcnt_d.Equals("")) && (gsi.Bcnt_D != null && !gsi.Bcnt_D.Equals("")))
            {
                g.Bcnt_d = gsi.Bcnt_D;
            }
            if ((g.Bcnt_e == null || g.Bcnt_e.Equals("")) && (gsi.Bcnt_E != null && !gsi.Bcnt_E.Equals("")))
            {
                g.Bcnt_e = gsi.Bcnt_E;
            }
            if ((g.Bcnt_f == null || g.Bcnt_f.Equals("")) && (gsi.Bcnt_F != null && !gsi.Bcnt_F.Equals("")))
            {
                g.Bcnt_f = gsi.Bcnt_F;
            }
            if ((g.MaxCharge == null || g.MaxCharge.Equals("")) && (gsi.MaxChargeCur != null && !gsi.MaxChargeCur.Equals("")))
            {
                g.MaxCharge = gsi.MaxChargeCur.Replace("A", String.Empty);
            }
            if (!(DataConverter.canStirng2int(g.Bcnt_a) && DataConverter.canStirng2int(g.Bcnt_b) && DataConverter.canStirng2int(g.Bcnt_c) &&
                  DataConverter.canStirng2int(g.Bcnt_d) && DataConverter.canStirng2int(g.Bcnt_e) && DataConverter.canStirng2int(g.Bcnt_f) && DataConverter.canStirng2double(g.MaxCharge)))
            {
                flushVM(new Object[] { FunCode.SHOWINFO, "wrongdata" });
                return;
            }
            CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ();
            obj.Init();
            obj.RemoteFlag = 0; //数据帧
            obj.ExternFlag = 1; //扩展帧
            obj.SendType   = 0; //正常发送
            obj.ID         = uint.Parse("0C24" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber);
            byte[] b = new byte[8];
            b[0] = (byte)Convert.ToInt32(g.Bcnt_a);
            b[1] = (byte)Convert.ToInt32(g.Bcnt_b);
            b[2] = (byte)Convert.ToInt32(g.Bcnt_c);
            b[3] = (byte)Convert.ToInt32(g.Bcnt_d);
            b[4] = (byte)Convert.ToInt32(g.Bcnt_e);
            b[5] = (byte)Convert.ToInt32(g.Bcnt_f);
            short d = (short)(Convert.ToInt32(g.MaxCharge) * 10);

            byte[] t = System.BitConverter.GetBytes(d);
            b[6]        = t[0];
            b[7]        = t[1];
            obj.Data    = b;
            obj.DataLen = 8;
            // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"));
            CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1);
            flushVM(new Object[] { FunCode.SHOWINFO, "sendSuc" });
        }
Esempio n. 6
0
        //获取从机编号
        private void RunSendFrame(Object i)
        {
            //if (!connectstate)
            //{
            //    Application.Current.Dispatcher.Invoke((Action)delegate
            //    {
            //        ModernDialog.ShowMessage((string)page.Resources["plsconnectdevice"], (string)page.Resources["tips"], MessageBoxButton.OK);
            //    });
            //    return;
            //}
            switch (Convert.ToInt32(i))
            {
            case 0:
                //获取从机编号
                new Thread(new ThreadStart(gen2Service.getSalveId)).Start();
                break;

            case 1:
                Button btn = page.FindName("shishi") as Button;
                if (!isShishi)
                {
                    if (startShishiThread != null)
                    {
                        startShishiThread.Abort();
                        startShishiThread = null;
                    }
                    isShishi = true;
                    btn.SetResourceReference(ContentControl.ContentProperty, "startshishi");
                }
                else
                {
                    if (SlaveId == null)
                    {
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                        });
                        return;
                    }
                    startShishiThread = new Thread(new ParameterizedThreadStart(gen2Service.startShishi));
                    startShishiThread.Start(SlaveId);
                    isShishi = false;
                    btn.SetResourceReference(ContentControl.ContentProperty, "closeshishi");
                }
                break;

            case 2:
                //读取配置信息
                if (SlaveId == null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                    });
                    return;
                }
                new Thread(new ParameterizedThreadStart(gen2Service.getConfig)).Start(SlaveId);
                //startShishiThread.Start(SlaveId);
                break;

            case 3:
                //发送配置信息1
                if (SlaveId == null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                    });
                    return;
                }
                ArrayList al = new ArrayList();
                al.Add(SlaveId);
                al.Add(Gen2SlaveConfig);
                al.Add(Gen2SlaveInfo);
                new Thread(new ParameterizedThreadStart(gen2Service.sendConfig1Pack)).Start(al);

                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    ModernDialog.ShowMessage((string)page.Resources["sendSuc"], (string)page.Resources["tips"], MessageBoxButton.OK);
                });
                //startShishiThread.Start(al);
                break;

            case 4:
                //发送配置信息2
                if (SlaveId == null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                    });
                    return;
                }
                ArrayList al2 = new ArrayList();
                al2.Add(SlaveId);
                al2.Add(Gen2SlaveConfig);
                al2.Add(Gen2SlaveInfo);
                new Thread(new ParameterizedThreadStart(gen2Service.sendConfig2Pack)).Start(al2);
                //startShishiThread.Start(al2);
                break;

            case 5:
                //发送追溯码
                if (SlaveId == null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                    });
                    return;
                }
                ArrayList al3 = new ArrayList();
                al3.Add(SlaveId);
                al3.Add(Gen2SlaveConfig);
                new Thread(new ParameterizedThreadStart(gen2Service.sendTraceCodePack)).Start(al3);
                //startShishiThread.Start(al3);

                break;

            case 6:
                //发送Relay2,can_life及时间控制信息
                if (SlaveId == null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                    });
                    return;
                }
                ArrayList al4 = new ArrayList();
                al4.Add(SlaveId);
                al4.Add(Gen2SlaveConfig);
                new Thread(new ParameterizedThreadStart(gen2Service.sendRelay2Pack)).Start(al4);
                break;

            case 7:
                //读取追溯码
                Button btn2 = page.FindName("readTraceCode") as Button;
                if (!isReadingTraceCode)
                {
                    if (startReadTraceCodeThread != null)
                    {
                        startReadTraceCodeThread.Abort();
                        startReadTraceCodeThread = null;
                    }
                    isReadingTraceCode = true;
                    btn2.SetResourceReference(ContentControl.ContentProperty, "read2");
                }

                else
                {
                    if (SlaveId == null)
                    {
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                        });
                        return;
                    }
                    startReadTraceCodeThread = new Thread(new ParameterizedThreadStart(gen2Service.getTraceCode));
                    startReadTraceCodeThread.Start(SlaveId);
                    isReadingTraceCode = false;
                    btn2.SetResourceReference(ContentControl.ContentProperty, "stop");
                }
                break;

            case 8:
                //发送均衡控制指令
                if (SlaveId == null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ModernDialog.ShowMessage((string)page.Resources["plsGetIdFirst"], (string)page.Resources["tips"], MessageBoxButton.OK);
                    });
                    return;
                }
                ArrayList al5 = new ArrayList();
                al5.Add(SlaveId);
                al5.Add(Gen2SlaveConfig);
                new Thread(new ParameterizedThreadStart(gen2Service.sendBalancePack)).Start(al5);
                break;

            case 9:
                //全选或者全不选
                CheckBox cb = page.FindName("balanceAll") as CheckBox;
                if (cb.IsChecked == true)
                {
                    Gen2SlaveConfig.setAll(true);
                }
                else
                {
                    Gen2SlaveConfig.setAll(false);
                }
                break;

            case 10:
                //读取配置信息
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect = false;    //该值确定是否可以选择多个文件
                dialog.Title       = "请选择文件夹";
                dialog.Filter      = "所有文件(*.*)|*.*";
                dialog.ShowDialog();
                String readPath = dialog.FileName;
                if (readPath == "")
                {
                    return;
                }
                Gen2SlaveConfig = Serializer.DeserializeFromFileByXml <Gen2SlaveConfig>(readPath);
                break;

            case 11:
                //存储配置信息
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "";
                sfd.InitialDirectory = @"C:\";
                sfd.Filter           = "文本文件| *.txt";
                sfd.ShowDialog();
                string savePath = sfd.FileName;
                // Console.WriteLine(path);
                if (savePath == "")
                {
                    return;
                }
                //List<Gen2SlaveConfig> l = new List<Gen2SlaveConfig>();
                //l.Add(Gen2SlaveConfig);
                //序列化
                Serializer.SerializeToFileByXml <Gen2SlaveConfig>(gen2SlaveConfig, Path.GetDirectoryName(savePath), Path.GetFileName(savePath));
                break;
            }
        }
Esempio n. 7
0
        private void Init()
        {
            ConsoleManager.Show();//打开信息打印窗口

            gen2Service.changeViewForGen2VM += changeView;

            gen2SlaveInfo   = new Gen2SlaveInfo();
            gen2SlaveConfig = new Gen2SlaveConfig();

            ConnectCanCommand  = new DelegateCommand <Button>(RunConnectCanCommand);
            RunFun             = new DelegateCommand <Object>(RunSendFrame);
            CbI18nClickCommand = new DelegateCommand <ComboBox>(RunCbI18nClickCommand);//国际化选框

            categoryI18nList.Add(new CategoryInfo()
            {
                Name = "English", Value = "en_US", sourceName = "English"
            });
            categoryI18nList.Add(new CategoryInfo()
            {
                Name = "中文", Value = "zh_CN", sourceName = "Chinese"
            });
            XmlDocument       xmlDoc   = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;//忽略文档里面的注释
            //XmlReader reader = XmlReader.Create("../../Config/Config.xml", settings);
            XmlReader reader = XmlReader.Create("Config/Config.xml", settings);

            xmlDoc.Load(reader);
            // 得到根节点bookstore
            XmlNode xn = xmlDoc.SelectSingleNode("appSettings");
            // 得到根节点的所有子节点
            XmlNodeList xnl = xn.ChildNodes;

            foreach (XmlNode x in xnl)
            {
                if (x.Name.Equals("i18n"))
                {
                    selectI18n = int.Parse(x.InnerText);
                    break;
                }
            }
            reader.Close();
            ResourceDictionary langRd = Application.LoadComponent(new Uri("i18n/" + CategoryI18nList[selectI18n].sourceName + ".xaml", UriKind.Relative)) as ResourceDictionary;

            page.Resources.MergedDictionaries.Add(langRd);

            //初始CAN通道
            canChannelList.Add("CAN0");
            canChannelList.Add("CAN1");
            //初始化波特率
            canBaudRateList.Add(new BaudRateModel()
            {
                Baudratename = "100Kbps", Time0 = 0x04, Time1 = 0x1C
            });
            canBaudRateList.Add(new BaudRateModel()
            {
                Baudratename = "125Kbps", Time0 = 0x03, Time1 = 0x1C
            });
            canBaudRateList.Add(new BaudRateModel()
            {
                Baudratename = "200Kbps", Time0 = 0x81, Time1 = 0xFA
            });
            canBaudRateList.Add(new BaudRateModel()
            {
                Baudratename = "250Kbps", Time0 = 0x01, Time1 = 0x1C
            });
            canBaudRateList.Add(new BaudRateModel()
            {
                Baudratename = "500Kbps", Time0 = 0x00, Time1 = 0x1C
            });
            canBaudRateList.Add(new BaudRateModel()
            {
                Baudratename = "1Mbps", Time0 = 0x00, Time1 = 0x14
            });

            InitView();
        }