Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Console.SetOut(new TextBoxWriter(this.richTextBoxLog));
            plcForm2.MdiParent = this;
            this.panelPlc2.Controls.Clear();
            this.panelPlc2.Controls.Add(plcForm2);
            plcForm2.Dock = DockStyle.Fill;
            plcForm2.Show();

            rfidWQForm.MdiParent = this;
            this.panelWqrfid.Controls.Clear();
            this.panelWqrfid.Controls.Add(rfidWQForm);
            rfidWQForm.Dock = DockStyle.Fill;
            rfidWQForm.Show();

            rfidSgUrb3Form.MdiParent = this;
            this.panelSgUrb3.Controls.Clear();
            this.panelSgUrb3.Controls.Add(rfidSgUrb3Form);
            rfidSgUrb3Form.Dock = DockStyle.Fill;
            rfidSgUrb3Form.Show();


            // 隐藏不用 的tabpage
            //this.tabControl1.TabPages.Remove(this.tabPage1);
            // this.tabControl1.TabPages.Remove(this.tabPage3);
            this.tabControl1.TabPages.Remove(this.tabPage5);
            // this.comboBoxPlcObjList.SelectedIndex = 0;
            //  this.tabPage1.Enabled = false;
            this.comboBoxDatabitSel.Items.AddRange(new string[] { "32位整数", "64位整数" });
            this.comboBoxDatabitSel.SelectedIndex = 0;

            #region PLC相关
            this.cbxPlcCata.Items.AddRange(new string[] { "FX5U", "Q系列", "Fx3uNET模块" });
            this.cbxPlcCata.SelectedIndex = 0;
            plcRwObj2 = new PLCRwMCPro(EnumPlcCata.FX5U, 1000, 1000);
            plcRwObj2.eventLinkLost += PlcLostConnectHandler;
            plcRwIF = plcRwObj2;

            plcFx485 = new PlcRW485BD();
            plcFx485.StationNumber = 1;
            #endregion


            HFReaderIF readerIF = new HFReaderIF();
            rfidRW          = new SgrfidRW(1);
            rfidRW.ReaderIF = readerIF;
            this.comboBoxComports.Items.Clear();

            barcodeReader = new BarcodeRWHonevor(1);

            string[] ports = System.IO.Ports.SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                this.comboBoxComports.Items.Add(port);
                this.comboBoxFXComs.Items.Add(port);
                this.comboBoxBarcode.Items.Add(port);
                this.comboBoxAirdetect.Items.Add(port);
            }
            if (ports != null && ports.Count() > 0)
            {
                this.comboBoxComports.Text = ports[0];
                this.comboBoxFXComs.Text   = ports[0];
            }
            rfidWorkingThread = new Thread(new ThreadStart(SysWorkingProc));
            rfidWorkingThread.IsBackground = true;

            this.printer = new PrinterRW(1, "", 8000);
            string dbConn = string.Format("Data Source ={0}\\SQLEXPRESS;Initial Catalog=FangTAIZaojuA;User ID=sa;Password=123456;", this.textBoxPrinterIP.Text);

            this.printerDB = new PrinterRWdb(dbConn);

            //MES 测试初始化
            this.textBoxMESwsAddr.Text = "http://192.168.100.90:8188/soap/EventService?wsdl";
            this.comboBoxInterfaces.Items.AddRange(new string[] { "assembleDown", "assembleRepair" });
            this.comboBoxInterfaces.SelectedIndex = 0;
            this.comboBoxDTs.Items.AddRange(new string[] { "FT_MES_STEP_INFO", "FT_MES_STEP_INFO_DETAIL" });
            this.comboBoxDTs.SelectedIndex = 0;
            this.textBoxMesParams.Text     = "1002002100086L451607280194,L45";
            this.richTextBoxMesDBConn.Text = @"Data Source=(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.94)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PRQMESDB)
    )
  )
;User Id=prqminda1;Password=prqminda1;Connection Timeout=5;";
//            this.richTextBoxMesDBConn.Text =  @"Data Source=(DESCRIPTION =
//    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.94)(PORT = 1521))
//    (CONNECT_DATA =
//      (SERVER = DEDICATED)
//      (SERVICE_NAME = PRQMESDB)
//    )
//  )
//;User Id=prqminda1;Password=prqminda1;"; //这个也可以放到Web.Config中。

            //气密
            airDetecter = new AirDetectFL295CRW(1, "");
        }
Exemple #2
0
        public bool ParseCommdev(XElement commDevRoot, ref string reStr)
        {
            try
            {
                //1 PLC
                plcRWs = new List <IPlcRW>();
                XElement plcRoot = commDevRoot.Element("PLCCfg");
                IEnumerable <XElement> plcXES = plcRoot.Elements("PLC");
                int plcSum = plcXES.Count();
                foreach (XElement plcXE in plcXES)
                {
                    string connStr = plcXE.Value.ToString();
                    int    db1Len = 100, db2Len = 100;
                    db1Len = int.Parse(plcXE.Attribute("db1Len").Value.ToString());
                    db2Len = int.Parse(plcXE.Attribute("db2Len").Value.ToString());
                    int         plcID   = int.Parse(plcXE.Attribute("id").Value.ToString());
                    EnumPlcCata plcCata = EnumPlcCata.FX5U;
                    if (plcXE.Attribute("cata") != null)
                    {
                        string strPlcCata = plcXE.Attribute("cata").Value.ToString();
                        plcCata = (EnumPlcCata)Enum.Parse(typeof(EnumPlcCata), strPlcCata);
                    }
                    if (SysCfg.SysCfgModel.SimMode)
                    {
                        PlcRWSim plcRW = new PlcRWSim();
                        plcRW.PlcID   = plcID;
                        plcRW.PlcRole = plcXE.Attribute("role").Value.ToString();
                        plcRWs.Add(plcRW);
                    }
                    else
                    {
                        PLCRwMCPro plcRW = new PLCRwMCPro(plcCata, db1Len, db2Len);
                        plcRW.PlcRole = plcXE.Attribute("role").Value.ToString();
                        // PLCRwMCPro2 plcRW = new PLCRwMCPro2(db1Len, db2Len);
                        plcRW.ConnStr = plcXE.Value.ToString();
                        plcRW.PlcID   = plcID;
                        plcRWs.Add(plcRW);
                    }
                }

                //2 rfid
                XElement rfidRootXE            = commDevRoot.Element("RfidCfg");
                IEnumerable <XElement> rfidXES = rfidRootXE.Elements("RFID");
                this.rfidRWs = new List <IrfidRW>();
                foreach (XElement rfidXE in rfidXES)
                {
                    byte     id           = byte.Parse(rfidXE.Attribute("id").Value.ToString());
                    string   addr         = rfidXE.Attribute("CommAddr").Value.ToString();
                    string[] strAddrArray = addr.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    string   ip           = strAddrArray[0];
                    ushort   port         = ushort.Parse(strAddrArray[1]);
                    //WqwlRfidRW rfidRW = new WqwlRfidRW(EnumTag.TagEPCC1G2, id, ip, port);
                    WqRfidUdp rfidRW = new WqRfidUdp(EnumTag.TagEPCC1G2, id, ip, port, (uint)(9000 + id));


                    //SygoleHFReaderIF.HFReaderIF readerIF = new SygoleHFReaderIF.HFReaderIF();
                    //SgrfidRW rfidRW = new SgrfidRW(id);
                    //rfidRW.ReaderIF = readerIF;
                    //rfidRW.ReaderIF.ComPort = commPort;
                    rfidRWs.Add(rfidRW);
                }

                //3 条码枪
                XElement barcoderRootXE         = commDevRoot.Element("BarScannerCfg");
                IEnumerable <XElement> barcodes = barcoderRootXE.Elements("BarScanner");
                barcodeRWList = new List <IBarcodeRW>();
                foreach (XElement barcodeXE in barcodes)
                {
                    byte   id       = byte.Parse(barcodeXE.Attribute("id").Value.ToString());
                    string commPort = barcodeXE.Attribute("CommAddr").Value.ToString();
                    if (SysCfg.SysCfgModel.SimMode)
                    {
                        BarcodeRWSim barSim = new BarcodeRWSim(id);
                        barSim.Role = barcodeXE.Attribute("role").Value.ToString();
                        barcodeRWList.Add(barSim);
                    }
                    else
                    {
                        BarcodeRWHonevor barcodeReader = new BarcodeRWHonevor(id);
                        barcodeReader.TriggerMode = EnumTriggerMode.序命令触发;
                        barcodeReader.Role        = barcodeXE.Attribute("role").Value.ToString();
                        //System.IO.Ports.SerialPort comPort = new System.IO.Ports.SerialPort(commPort);
                        //comPort.BaudRate = 115200;
                        //comPort.DataBits = 8;
                        //comPort.StopBits = System.IO.Ports.StopBits.One;
                        //comPort.Parity = System.IO.Ports.Parity.None;
                        barcodeReader.ComPortObj.PortName = commPort;
                        barcodeReader.ComPortObj.BaudRate = 115200;
                        barcodeReader.ComPortObj.DataBits = 8;
                        barcodeReader.ComPortObj.StopBits = System.IO.Ports.StopBits.One;
                        barcodeReader.ComPortObj.Parity   = System.IO.Ports.Parity.None;
                        barcodeRWList.Add(barcodeReader);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                reStr = "通信设备配置解析失败,发生系统异常:" + ex.ToString();
                return(false);
            }
        }
Exemple #3
0
        private bool ParseCommDevCfg(XElement commDevRoot, ref string reStr)
        {
            try
            {
                //1 PLC
                XElement plcXE = commDevRoot.Element("PLCCfg");
                string   addr  = plcXE.Element("PLCAddr").Value.ToString();
                plcRWList = new List <IPlcRW>();
                if (plcXE.Element("PLCVendor").Value.ToString() == "三菱Q")
                {
                    PLCRwMCPro plcObj = new PLCRwMCPro(EnumPlcCata.Qn, SysCfgModel.DB1Len, SysCfgModel.DB2Len);
                    plcObj.NetProto      = EnumNetProto.TCP;// EnumNetProto.UDP;
                    plcObj.PlcID         = 1;
                    plcObj.ConnStr       = addr;
                    plcObj.StationNumber = 1;
                    this.plcRWList.Add(plcObj);
                }
                else
                {
                    reStr = "不可识别的PLC型号";
                    return(false);
                }

                //2 rfid
                XElement rfidRootXE            = commDevRoot.Element("SgRfidCfg");
                IEnumerable <XElement> rfidXES = rfidRootXE.Elements("RFID");
                rfidList = new List <IrfidRW>();
                bool tcpComm = false;
                if (rfidRootXE.Attribute("CommType").Value.ToString() == "TCPIP")
                {
                    tcpComm = true;
                }
                foreach (XElement rfidXE in rfidXES)
                {
                    byte   id       = byte.Parse(rfidXE.Attribute("id").Value.ToString());
                    string commAddr = rfidXE.Attribute("CommAddr").Value.ToString();
                    SygoleHFReaderIF.HFReaderIF readerIF = new SygoleHFReaderIF.HFReaderIF();
                    SgrfidRW rfidRW = new SgrfidRW(id);

                    rfidRW.ReaderIF = readerIF;
                    if (tcpComm)
                    {
                        rfidRW.ReaderIF.commType   = SygoleHFReaderIF.EnumCommType.TCPNET;
                        rfidRW.ReaderIF.readerIP   = commAddr;
                        rfidRW.ReaderIF.readerPort = 3001;
                    }
                    else
                    {
                        rfidRW.ReaderIF.ComPort = commAddr;
                    }

                    rfidList.Add(rfidRW);
                }

                //3 条码枪
                XElement barcoderRootXE         = commDevRoot.Element("BarScannerCfg");
                IEnumerable <XElement> barcodes = barcoderRootXE.Elements("BarScanner");
                foreach (XElement barcodeXE in barcodes)
                {
                    byte             id            = byte.Parse(barcodeXE.Attribute("id").Value.ToString());
                    string           commPort      = barcodeXE.Attribute("CommAddr").Value.ToString();
                    BarcodeRWHonevor barcodeReader = new BarcodeRWHonevor(id);
                    SerialPort       comPort       = new SerialPort(commPort);
                    comPort.BaudRate         = 115200;
                    comPort.DataBits         = 8;
                    comPort.StopBits         = StopBits.One;
                    comPort.Parity           = Parity.None;
                    barcodeReader.ComPortObj = comPort;
                    barcodeRWList.Add(barcodeReader);
                }

                //4 气密仪
                XElement airdetectRootXE          = commDevRoot.Element("AircheckMachineCfg");
                IEnumerable <XElement> airdetects = airdetectRootXE.Elements("AircheckMachine");
                airDetectList = new List <IAirlossDetectDev>();
                foreach (XElement airdetectXE in airdetects)
                {
                    byte              id          = byte.Parse(airdetectXE.Attribute("id").Value.ToString());
                    string            commPort    = airdetectXE.Attribute("CommAddr").Value.ToString();
                    AirDetectFL295CRW airdetectRW = new AirDetectFL295CRW(id, commPort);
                    airDetectList.Add(airdetectRW);
                }
                //5 打标机
                XElement printerRootXE          = commDevRoot.Element("LabelPrinterCfg");
                IEnumerable <XElement> printers = printerRootXE.Elements("LabelPrinter");
                this.printerList = new List <IPrinterInfoDev>();
                foreach (XElement printerXE in printers)
                {
                    byte        id           = byte.Parse(printerXE.Attribute("id").Value.ToString());
                    string      ip           = printerXE.Attribute("ip").Value.ToString();
                    string      db           = printerXE.Attribute("dbName").Value.ToString();
                    short       port         = short.Parse(printerXE.Attribute("port").Value.ToString());
                    string      userName     = printerXE.Attribute("user").Value.ToString();
                    string      pswd         = printerXE.Attribute("pswd").Value.ToString();
                    PrinterRW   printerRW    = new PrinterRW(id, ip, port);
                    string      printerDBStr = string.Format("Data Source ={0};Initial Catalog={1};User ID={2};Password={3};", ip, db, userName, pswd);
                    PrinterRWdb printerRWDb  = new PrinterRWdb(printerDBStr);
                    this.printerList.Add(printerRWDb);
                    //this.printerList.Add(printerRW);
                }
                return(true);
            }
            catch (Exception ex)
            {
                reStr = ex.ToString();
                return(false);
            }
        }
Exemple #4
0
        private bool ParseCommDevCfg(XElement commDevRoot, ref string reStr)
        {
            try
            {
                //1 PLC
                XElement plcRoot = commDevRoot.Element("PLCCfg");

                plcRWs = new List <IPlcRW>();
                IEnumerable <XElement> plcXES = plcRoot.Elements("PLC");
                foreach (XElement plcXE in plcXES)
                {
                    string connStr = plcXE.Value.ToString();
                    int    db1Len = 100, db2Len = 100;
                    db1Len = int.Parse(plcXE.Attribute("db1Len").Value.ToString());
                    db2Len = int.Parse(plcXE.Attribute("db2Len").Value.ToString());
                    int         plcID   = int.Parse(plcXE.Attribute("id").Value.ToString());
                    EnumPlcCata plcCata = EnumPlcCata.FX5U;
                    if (plcXE.Attribute("cata") != null)
                    {
                        string strPlcCata = plcXE.Attribute("cata").Value.ToString();
                        plcCata = (EnumPlcCata)Enum.Parse(typeof(EnumPlcCata), strPlcCata);
                    }

                    PLCRwMCPro plcRW = new PLCRwMCPro(plcCata, db1Len, db2Len);
                    // PLCRwMCPro2 plcRW = new PLCRwMCPro2(db1Len, db2Len);
                    plcRW.ConnStr = plcXE.Value.ToString();
                    plcRW.PlcID   = plcID;
                    plcRWs.Add(plcRW);
                }
                //2 rfid
                XElement rfidRootXE            = commDevRoot.Element("RfidCfg");
                IEnumerable <XElement> rfidXES = rfidRootXE.Elements("RFID");
                this.rfidRWs = new List <IrfidRW>();
                foreach (XElement rfidXE in rfidXES)
                {
                    byte     id           = byte.Parse(rfidXE.Attribute("id").Value.ToString());
                    string   addr         = rfidXE.Attribute("CommAddr").Value.ToString();
                    string[] strAddrArray = addr.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    string   ip           = strAddrArray[0];
                    ushort   port         = ushort.Parse(strAddrArray[1]);
                    //WqwlRfidRW rfidRW = new WqwlRfidRW(EnumTag.TagEPCC1G2, id, ip, port);
                    WqRfidUdp rfidRW = new WqRfidUdp(EnumTag.TagEPCC1G2, id, ip, port, (uint)(9000 + id));

                    //rfidRW.HostIP = "192.168.1.251";
                    // rfidRW.HostPort = (uint)(9000+id);
                    //SygoleHFReaderIF.HFReaderIF readerIF = new SygoleHFReaderIF.HFReaderIF();
                    //SgrfidRW rfidRW = new SgrfidRW(id);
                    //rfidRW.ReaderIF = readerIF;
                    //rfidRW.ReaderIF.ComPort = commPort;
                    rfidRWs.Add(rfidRW);
                }

                //3 条码枪
                XElement barcoderRootXE         = commDevRoot.Element("BarScannerCfg");
                IEnumerable <XElement> barcodes = barcoderRootXE.Elements("BarScanner");
                barcodeRWList = new List <IBarcodeRW>();
                foreach (XElement barcodeXE in barcodes)
                {
                    byte             id            = byte.Parse(barcodeXE.Attribute("id").Value.ToString());
                    string           commPort      = barcodeXE.Attribute("CommAddr").Value.ToString();
                    BarcodeRWHonevor barcodeReader = new BarcodeRWHonevor(id);
                    barcodeReader.TriggerMode = EnumTriggerMode.序命令触发;
                    //System.IO.Ports.SerialPort comPort = new System.IO.Ports.SerialPort(commPort);
                    //comPort.BaudRate = 115200;
                    //comPort.DataBits = 8;
                    //comPort.StopBits = System.IO.Ports.StopBits.One;
                    //comPort.Parity = System.IO.Ports.Parity.None;
                    barcodeReader.ComPortObj.PortName = commPort;
                    barcodeReader.ComPortObj.BaudRate = 115200;
                    barcodeReader.ComPortObj.DataBits = 8;
                    barcodeReader.ComPortObj.StopBits = System.IO.Ports.StopBits.One;
                    barcodeReader.ComPortObj.Parity   = System.IO.Ports.Parity.None;
                    barcodeRWList.Add(barcodeReader);
                }
                //4 杭可装载服务器
                XElement hkFillSvcXECfg = commDevRoot.Element("HKFillServerCfg");
                string   hkSvcIP        = "127.0.0.1";
                int      hkSvcPort      = 13535;
                if (hkFillSvcXECfg != null)
                {
                    foreach (XElement hkXE in hkFillSvcXECfg.Elements("HkServer"))
                    {
                        int hkID = int.Parse(hkXE.Attribute("id").Value.ToString());
                        hkSvcIP   = hkXE.Attribute("ip").Value.ToString();
                        hkSvcPort = int.Parse(hkXE.Attribute("port").Value.ToString());
                        HKAccess hk = new HKAccess(hkID, hkSvcIP, hkSvcPort);
                        hk.RecvTimeOut = 5000;
                        hkAccessList.Add(hk);
                    }
                }

                string ocvDBConn = hkFillSvcXECfg.Element("HkOCVDB").Attribute("conn").Value.ToString(); // "Data Source = 192.168.100.20;Initial Catalog=SRANCH;User ID=L_Guest;Password=Guest@123;";
                ocvAccess = new OcvAccess(ocvDBConn, 36);

                CommDevConnect();


                return(true);
            }
            catch (Exception ex)
            {
                reStr = ex.ToString();
                return(false);
            }
        }