예제 #1
0
 private void 扫码BClick(object sender, RoutedEventArgs e)
 {
     try
     {
         ScanB.GetBarCode(AddMessage);
     }
     catch
     { }
 }
예제 #2
0
        void Run()
        {
            Stopwatch sw = new Stopwatch();

            while (true)
            {
                sw.Restart();
                System.Threading.Thread.Sleep(10);
                try
                {
                    #region IO
                    bool[] M2764 = Fx5u_2.ReadMultiM("M2764", 32);
                    Fx5u.SetMultiM("M2564", M2764);
                    #endregion
                    #region 扫码
                    //扫码(载具)【A轨道】
                    if (Fx5u_2.ReadM("M2797"))
                    {
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            AddMessage("轨道A扫码");
                        }));
                        Fx5u_2.SetM("M2797", false);
                        Fx5u_2.SetMultiM("M2597", new bool[4] {
                            false, false, false, false
                        });
                        ScanA.GetBarCode(ScanAGetBarcodeCallback);
                    }
                    //扫码(载具)【B轨道】
                    if (Fx5u_2.ReadM("M2802"))
                    {
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            AddMessage("轨道B扫码");
                        }));
                        Fx5u_2.SetM("M2802", false);
                        Fx5u_2.SetMultiM("M2602", new bool[4] {
                            false, false, false, false
                        });
                        ScanB.GetBarCode(ScanBGetBarcodeCallback);
                    }
                    #endregion
                    #region 大数据读取
                    //读报警
                    M300 = Fx5u_2.ReadMultiM("M1100", (ushort)AlarmList.Count);
                    //读三色灯状态
                    LampColor = Fx5u_2.ReadW("D200");
                    #endregion
                }
                catch
                { }
                SWms = sw.ElapsedMilliseconds;
            }
        }
예제 #3
0
        public void ScanAction(object p)
        {
            switch (p.ToString())
            {
            case "0":
                ScanA.GetBarCode(ScanActionCallback1);
                break;

            case "1":
                ScanB.GetBarCode(ScanActionCallback2);
                break;

            default:
                break;
            }
        }
예제 #4
0
        public void PlcRun()
        {
            bool   first    = true;
            bool   scanFlag = false;
            Random rd       = new Random();

            while (true)
            {
                System.Threading.Thread.Sleep(10);
                if (Xinjie == null)
                {
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    try
                    {
                        PLCConnect = Xinjie.ReadM(24576);
                        if (PLCConnect)
                        {
                            PlcIn = Xinjie.ReadMultiMCoil(1500);
                            Xinjie.WritMultiMCoil(1800, PlcOut);
                            Xinjie.WriteW(150, rd.Next(0, 999).ToString());
                            dd8170     = Xinjie.ReadD(16554);
                            dd4208     = Xinjie.ReadD(4208);
                            RotalAngle = (dd8170 - dd4208) / 91776 * 360;

                            //扫码
                            if (scanFlag != PlcIn[0])
                            {
                                scanFlag = PlcIn[0];
                                if (scanFlag)
                                {
                                    Abarcode_f = false;
                                    Bbarcode_f = false;
                                    PlcOut[0]  = false;
                                    PlcOut[1]  = false;
                                    PlcOut[2]  = false;
                                    Xinjie.WritMultiMCoil(1800, PlcOut);
                                    ScanA.GetBarCode(ScanActionCallback1);
                                    ScanB.GetBarCode(ScanActionCallback2);
                                    TrigerTimes++;
                                    Inifile.INIWriteValue(ParameterIniPath, "Times", "TrigerTimes", TrigerTimes.ToString());
                                }
                                else
                                {
                                    PlcOut[0] = false;
                                }
                            }
                            if (Abarcode_f && Bbarcode_f)
                            {
                                Abarcode_f = false;
                                Bbarcode_f = false;
                                PlcOut[0]  = true;
                                PlcOut[1]  = Abarcode_s;
                                PlcOut[2]  = Bbarcode_s;
                                if (Abarcode_s && Bbarcode_s)
                                {
                                    ScanTimes++;
                                    Inifile.INIWriteValue(ParameterIniPath, "Times", "ScanTimes", ScanTimes.ToString());
                                }
                                RecordItem recordItem = new RecordItem();
                                recordItem.日期        = GetBanciDate();
                                recordItem.班次        = GetBanci();
                                recordItem.机台号       = JiTaiHao;
                                recordItem.产品barcode = Abarcode;
                                recordItem.机台穴号      = Bbarcode;
                                lock (LockObject)
                                {
                                    recordItemList.Add(recordItem);
                                }
                                if (Directory.Exists("D:\\" + GetBanciDate() + GetBanci()))
                                {
                                    string filename = "D:\\" + GetBanciDate() + GetBanci() + "\\" + GetBanciDate() + GetBanci() + ".csv";
                                    if (File.Exists(filename))
                                    {
                                        string[] heads = { "日期", "班次", "机台号", "机台穴号", "产品barcode" };
                                        Csvfile.AddNewLine(filename, heads);
                                    }
                                    string[] count = { recordItem.日期, recordItem.班次, recordItem.机台号, recordItem.机台穴号, recordItem.产品barcode };
                                    Csvfile.AddNewLine(filename, count);
                                }
                            }
                        }
                        else
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                MsgText = AddMessage("PLC断线,重新连接...");
                            }
                            Xinjie.ModbusDisConnect();
                            System.Threading.Thread.Sleep(1000);
                            Xinjie.ModbusInit(PLCPortCom, 19200, System.IO.Ports.Parity.Even, 8, System.IO.Ports.StopBits.One);
                            Xinjie.ModbusConnect();
                        }
                    }
                    catch (Exception ex)
                    {
                        MsgText    = AddMessage(ex.Message);
                        PLCConnect = false;
                    }
                }
            }
        }