Пример #1
0
        private void Work_Plc(object obj)
        {
            if (isWork)
            {
                return;
            }

            try
            {
                isWork = true;

                int trg_id = opc.GetValueInt(vari.plc.Add_Trigger);
                int ack_id = opc.GetValueInt(vari.plc.Add_Ack);

                if (trg_id == ack_id)
                {
                    return;
                }

                string data = opc.GetValueHex(vari.plc.Add_Data);

                Data_Proc(data);

                //ack_id <- trg_id
                opc.WriteOrder(vari.plc.Add_Ack, trg_id);
            }
            catch (Exception ex)
            {
                ProcException(ex, "Work_Plc", true);
            }
            finally
            {
                isWork = false;
            }
        }
Пример #2
0
        private void Work()
        {
            try
            {
                int    tgr_id = 0;
                int    ack_id = 0;
                string data;
                int    idx;
                int    ii = 0;
                char   head;
                int    cnt = 0;

                Random rnd = new Random();

                //plc 값 초기화
                _opc.WriteOrder(vari.plc.Add_Ack, 0);
                _opc.WriteOrder(vari.plc.Add_Trigger, 0);
                _opc.WriteOrder(vari.plc.Add_Data, 0);

                while (true)
                {
                    tgr_id = _opc.GetValueInt(vari.plc.Add_Trigger);
                    ack_id = _opc.GetValueInt(vari.plc.Add_Ack);



                    //같으면 다음 데이터 보낸다.
                    if (tgr_id == ack_id)
                    {
                        tgr_id++;
                        vari.iTestSeq++;
                        cnt++;

                        if (cnt > 99999)
                        {
                            cnt = 1;
                        }
                        if (tgr_id > 9999)
                        {
                            tgr_id = 1;
                        }
                        if (vari.iTestSeq > 9999)
                        {
                            vari.iTestSeq = 1;
                        }

                        //data를 만든다.
                        data  = $"A{cnt:D5}";
                        data += $"{vari.iTestSeq:D4}";
                        data += $"VIN{vari.iTestSeq:D14} ";

                        idx   = rnd.Next(1, 3);
                        data += cond_cartype[idx];

                        idx   = rnd.Next(0, 10);
                        data += idx == 1 ? cond_result[2] : cond_result[1];

                        ii++;

                        if (ii > 999)
                        {
                            ii = 1;
                        }

                        for (int x = 0; x < 25; x++)
                        {
                            head = Convert.ToChar(65 + x);

                            for (int y = 0; y < 3; y++)
                            {
                                switch (y)
                                {
                                case 0:
                                    data += $"{head}{ii:D3}";
                                    break;

                                case 1:
                                    data += $"{ii:D3}{head}";
                                    break;

                                default:
                                    idx   = rnd.Next(0, 10);
                                    data += idx == 1 ? cond_result[2] : cond_result[1];
                                    break;
                                }
                            }
                        }


                        _opc.WriteOrder(vari.plc.Add_Data, data);
                        _opc.WriteOrder(vari.plc.Add_Trigger, tgr_id);


                        Function.form.control.Invoke_Control_SetProperty(inpWorkCnt, "Value", iWorkCnt.ToString());
                        Function.form.control.Invoke_Control_SetProperty(inpSeq, "Value", $"{vari.iTestSeq:D4}");
                        Function.form.control.Invoke_Control_SetProperty(inpWorkCnt, "Value", $"{cnt} / {iWorkCnt}");
                    }

                    Function.form.control.Invoke_Control_SetProperty(inpID, "Value", $"{tgr_id:D4} / {ack_id:D4}");



                    if (iWorkCnt > 0 && iWorkCnt <= cnt)
                    {
                        btnRun_Click(null, null);
                        break;
                    }


                    if (bWorkCancel)
                    {
                        break;
                    }

                    Application.DoEvents();

                    Thread.Sleep(iInterval);
                }
            }
            catch
            {
            }
        }