Exemplo n.º 1
0
        private void DoWrite()
        {
            while (ThreadFlag)
            {
                if (WriteValues.Count == 0)
                {
                    Thread.Sleep(100);
                    continue;
                }


                object[]           values     = WriteValues.Dequeue();
                Opc.Da.ItemValue[] valueArray = new Opc.Da.ItemValue[1];
                valueArray[0]          = new Opc.Da.ItemValue();
                valueArray[0].ItemName = values[0].ToString();
                valueArray[0].Value    = values[1];
                Opc.IdentifiedResult[] writeresult = opcserver.Write(valueArray);
                if (!writeresult[0].ResultID.Succeeded())
                {
                    EnqueueLog("点[" + values[0].ToString() + "]写数据时失败:" + writeresult[0].ResultID.ToString());
                    //LogClass.Logs.Enqueue("点[" + values[0].ToString() + "]写数据时失败:" + writeresult[0].ResultID.ToString());
                }
                else
                {
                    //EnqueueLog("点[" + values[0].ToString() + "]=[" + values[1].ToString() + "]写数据时成功:" + writeresult[0].ResultID.ToString());
                    //LogClass.Logs.Enqueue("点[" + values[0].ToString() + "]=[" + values[1].ToString() + "]写数据时成功:" + writeresult[0].ResultID.ToString());
                }

                Thread.Sleep(100);
            }
        }
Exemplo n.º 2
0
        private bool Write(string groupname, Dictionary <string, object> codeValue)
        {
            if (string.IsNullOrEmpty(groupname))
            {
                FrmMain.logOpt.Write($"!项目为空");
                return(false);
            }
            try {
                if (!groups.Keys.Contains(groupname))
                {
                    clsSetting.loger.Error($"!{groupname}未添加订阅!");
                    return(false);
                }
                var group      = groups[groupname];
                var itemvalues = new List <Opc.Da.ItemValue>();
                foreach (KeyValuePair <string, object> kv in codeValue)
                {
                    var iv = new Opc.Da.ItemValue(group.Items.First(item => item.ItemName == kv.Key));
                    iv.Value = kv.Value;
                    itemvalues.Add(iv);
                }

                var rt = group.Write(itemvalues.ToArray());
                return(ParseResult(rt, (x) => { FrmMain.logOpt.Write(x); }));
            } catch (Exception ex) {
                FrmMain.logOpt.Write($"!组写入失败: {groupname}, {ex}");
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 返回结果用ParseResult函数解析。
        /// 应当替代write函数。
        /// </summary>
        /// <param name="code"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool Write(string code, object value)
        {
            if (string.IsNullOrEmpty(code))
            {
                FrmMain.logOpt.Write($"!项目 {code} 为空!");
                return(false);
            }

            try {
                if (!groups.Keys.Contains(code))
                {
                    yidascan.FrmMain.logOpt.Write("!{code}未添加订阅!");
                    return(false);
                }

                var key = (Opc.ItemIdentifier)groups[code].Items[0];
                var iv  = new Opc.Da.ItemValue(key)
                {
                    Value = value
                };
                var rt = groups[code].Write(new Opc.Da.ItemValue[] { iv });

                return(ParseResult(rt, (x) => { FrmMain.logOpt.Write(x); }));
            } catch (Exception ex) {
                FrmMain.logOpt.Write($"!{code}写入失败: {ex}");
                return(false);
            }
        }
 public void FrontRepairReleasePallet()
 {
     PLCWrapper plc = new PLCWrapper(opcURL);
     
     Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
     writeValues[0] = new Opc.Da.ItemValue();
     writeValues[0].ItemName = frontRepairTesterReleasePallet;
     writeValues[0].Value = 1;
     var t = plc.WriteTags(writeValues);
 }
Exemplo n.º 5
0
 public override Opc.Da.ItemValue[] GetInitializeTags(long jobId, int cartNum, int recipe1, int recipe2)
 {
     Opc.Da.ItemValue[] plcWriteTags = new Opc.Da.ItemValue[5];
     plcWriteTags[0] = GetItemValue<string>(GetFullTagName(jobIdTag), "" + jobId);
     plcWriteTags[1] = GetItemValue<int>(GetFullTagName(cartNumTag), cartNum);
     plcWriteTags[2] = GetItemValue<int>(GetFullTagName(cartPresentTag), 1);
     plcWriteTags[3] = GetItemValue<int>(GetFullTagName(recipe1Tag), recipe1);
     plcWriteTags[4] = GetItemValue<int>(GetFullTagName(recipe2Tag), recipe2);
     return plcWriteTags;
 }
Exemplo n.º 6
0
        public Opc.Da.ItemValue[] produceValuesToWrite(Opc.Da.Item[] itemsToWrite, double[] valuesToWrite)
        {
            Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[itemsToWrite.Length];

            for (int index = 0; index < itemsToWrite.Length; index++)
            {
                writeValues[index] = new Opc.Da.ItemValue();
                writeValues[index].ServerHandle = itemsToWrite[index].ServerHandle;
                writeValues[index].Value        = valuesToWrite[index];
            }

            return(writeValues);
        }
Exemplo n.º 7
0
        private void ConfirmFaultReset_On_OPC()
        {
            Opc.Da.Item[] OPC_Fault_On = new Opc.Da.Item[1];
            OPC_Fault_On[0]          = new Opc.Da.Item();
            OPC_Fault_On[0].ItemName = Spotweld_Tag_Name + "HMI_PB_Alarm_Reset";
            OPC_Fault_On             = Fault_On_Write.AddItems(OPC_Fault_On);

            Opc.Da.ItemValue[] OPC_ResetValue_On = new Opc.Da.ItemValue[1];
            OPC_ResetValue_On[0] = new Opc.Da.ItemValue();
            OPC_ResetValue_On[0].ServerHandle = Fault_On_Write.Items[0].ServerHandle;
            OPC_ResetValue_On[0].Value        = 0;

            Opc.IRequest OPCRequest;
            Fault_On_Write.Write(OPC_ResetValue_On, 123, new Opc.Da.WriteCompleteEventHandler(WriteCompleteCallback), out OPCRequest);
        }
        // Set the Fault Value in the PLC back to 0
        private void ConfirmFaultReset_Off_OPC(object sender, EventArgs e)
        {
            Opc.Da.Item[] OPC_Fault_Off = new Opc.Da.Item[1];
            OPC_Fault_Off[0]          = new Opc.Da.Item();
            OPC_Fault_Off[0].ItemName = Spotweld_Tag_Name + "Fault";
            OPC_Fault_Off             = Fault_Off_Write.AddItems(OPC_Fault_Off);

            Opc.Da.ItemValue[] OPC_ResetValue_Off = new Opc.Da.ItemValue[1];
            OPC_ResetValue_Off[0] = new Opc.Da.ItemValue();
            OPC_ResetValue_Off[0].ServerHandle = Fault_Off_Write.Items[0].ServerHandle;
            OPC_ResetValue_Off[0].Value        = 0;

            Opc.IRequest OPCRequest;
            Fault_Off_Write.Write(OPC_ResetValue_Off, 123, new Opc.Da.WriteCompleteEventHandler(WriteCompleteCallback), out OPCRequest);
        }
Exemplo n.º 9
0
 public override Opc.Da.ItemValue[] GetResetTags()
 {
     Opc.Da.ItemValue[] plcWriteTags = new Opc.Da.ItemValue[11];
     plcWriteTags[0] = GetItemValue<string>(GetFullTagName(jobIdTag), "0");
     plcWriteTags[1] = GetItemValue<int>(GetFullTagName(cartNumTag), 0);
     plcWriteTags[2] = GetItemValue<int>(GetFullTagName(cartPresentTag), 0);
     plcWriteTags[3] = GetItemValue<int>(GetFullTagName(drvFailedTag), 0);
     plcWriteTags[4] = GetItemValue<int>(GetFullTagName(drvPassedTag), 0);
     plcWriteTags[5] = GetItemValue<int>(GetFullTagName(pasFailedTag), 0);
     plcWriteTags[6] = GetItemValue<int>(GetFullTagName(pasPassedTag), 0);
     plcWriteTags[7] = GetItemValue<int>(GetFullTagName(recipe1Tag), 0);
     plcWriteTags[8] = GetItemValue<int>(GetFullTagName(recipe2Tag), 0);
     plcWriteTags[9] = GetItemValue<int>(GetFullTagName(dataReadyAckTag), 0);
     plcWriteTags[10] = GetItemValue<int>(GetFullTagName(dataReadyTag), 0);
     return plcWriteTags;
 }
Exemplo n.º 10
0
        public void InitializeFrontTorqueRecipe([FromBody]PLCTorqueRequest req)
        {
            PLCFactory factory = new PLCFactory(opcURL);
            Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[3];
            writeValues[0] = new Opc.Da.ItemValue();
            writeValues[0].ItemName = "[ShippingConveyor]Front_Line_Repairs.PSet_Request";
            writeValues[0].Value = req.Pset;

            writeValues[1] = new Opc.Da.ItemValue();
            writeValues[1].ItemName = "[ShippingConveyor]Front_Line_Repairs.Torque_Count_Request";
            writeValues[1].Value = req.TorqueCount;

            writeValues[2] = new Opc.Da.ItemValue();
            writeValues[2].ItemName = "[ShippingConveyor]Front_Line_Repairs.PF_Box_Request";
            writeValues[2].Value = req.FocusBoxNum;
            factory.WriteTags(writeValues);
        }
Exemplo n.º 11
0
        public void ResetRepairRUTester(int lineId)
        {
            if (lineId == 1)
            {
                #region Reset Front Line RU Tester
                Opc.Da.ItemValue[] ruWriteValues = new Opc.Da.ItemValue[9];
                ruWriteValues[0] = new Opc.Da.ItemValue();
                ruWriteValues[0].ItemName = frontRURepairTesterJobId;
                ruWriteValues[0].Value = "0";

                ruWriteValues[1] = new Opc.Da.ItemValue();
                ruWriteValues[1].ItemName = frontRURepairTesterCartNum;
                ruWriteValues[1].Value = 0;

                ruWriteValues[2] = new Opc.Da.ItemValue();
                ruWriteValues[2].ItemName = frontRURepairTesterCartPresent;
                ruWriteValues[2].Value = 0;

                ruWriteValues[3] = new Opc.Da.ItemValue();
                ruWriteValues[3].ItemName = frontRURepairTesterDrvFailed;
                ruWriteValues[3].Value = 0;

                ruWriteValues[4] = new Opc.Da.ItemValue();
                ruWriteValues[4].ItemName = frontRURepairTesterDrvPassed;
                ruWriteValues[4].Value = 0;

                ruWriteValues[5] = new Opc.Da.ItemValue();
                ruWriteValues[5].ItemName = frontRURepairTesterPasFailed;
                ruWriteValues[5].Value = 0;

                ruWriteValues[6] = new Opc.Da.ItemValue();
                ruWriteValues[6].ItemName = frontRURepairTesterPasPassed;
                ruWriteValues[6].Value = 0;

                ruWriteValues[7] = new Opc.Da.ItemValue();
                ruWriteValues[7].ItemName = frontRURepairTesterRecipe1;
                ruWriteValues[7].Value = 0;

                ruWriteValues[8] = new Opc.Da.ItemValue();
                ruWriteValues[8].ItemName = frontRURepairTesterRecipe2;
                ruWriteValues[8].Value = 0;

                ruPLCRepairTester.WriteTags(ruWriteValues);
                #endregion
            }
        }
Exemplo n.º 12
0
        public void EnableTearDownByFocusBox(int lineId, string focusBox)
        {
            ResetTorqueBox(lineId);
            if (focusBox == "FB603")
            {
                PLCFactory factory = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[2];
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = frontPSetRequest;
                writeValues[0].Value = 23;

                writeValues[1] = new Opc.Da.ItemValue();
                writeValues[1].ItemName = frontPFBoxRequest;
                writeValues[1].Value = 603;
                factory.WriteTags(writeValues);
            }
            else if (focusBox == "FB601")
            {
                PLCFactory factory = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[2];
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = rearPSetRequest;
                writeValues[0].Value = 15;

                writeValues[1] = new Opc.Da.ItemValue();
                writeValues[1].ItemName = rearPFBoxRequest;
                writeValues[1].Value = 601;
                factory.WriteTags(writeValues);
            }
            else if (focusBox == "FB602")
            {
                PLCFactory factory = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[2];
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = rearPSetRequest;
                writeValues[0].Value = 15;

                writeValues[1] = new Opc.Da.ItemValue();
                writeValues[1].ItemName = rearPFBoxRequest;
                writeValues[1].Value = 602;
                factory.WriteTags(writeValues);
            }
        }
Exemplo n.º 13
0
        public void ResetTorqueBox(int lineId)
        {
            PLCFactory factory = new PLCFactory(opcURL);
            Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];

            if (lineId == 1)
            {
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = frontResetTorque;
                writeValues[0].Value = 1;
            }
            else
            {
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = rearResetTorque;
                writeValues[0].Value = 1;
            }
            factory.WriteTags(writeValues);
        }
Exemplo n.º 14
0
        ///// <summary>
        ///// PLC Item 값을 읽는다.
        ///// </summary>
        ///// <param name="strItem">ItemName</param>
        ///// <returns></returns>
        //public int Item_Read(string strItem)
        //{

        //	try
        //	{
        //		Opc.Da.Item item = OpcGrp.Items[strItem];


        //		OPCItem Item = OpcGrp.OPCItems.Item(ItemName);
        //		object objValue = Item.Value;
        //		return Convert.ToInt16(objValue.ToString(), 10);
        //	}
        //	catch (System.Runtime.InteropServices.ExternalException ex)
        //	{   //activex이기 때문에 에러 발생이 제대로 되지 않아 몇가지만...
        //		throw ComException(ex, ItemName.ToString());
        //	}
        //	catch (Exception ex)
        //	{
        //		throw ex;
        //	}
        //}



        /// <summary>
        /// Plc Item에 값을 쓴다..
        /// </summary>
        /// <param name="strItem">ItemName</param>
        /// <param name="lngValue">Writing Value</param>
        void Item_Write(string strItem, int intValue)
        {
            try
            {
                bool             isWork = false;
                Opc.Da.ItemValue iv     = new Opc.Da.ItemValue();


                foreach (Opc.Da.Item i in OpcGrp.Items)
                {
                    if (i.ItemName.Equals(strItem))
                    {
                        iv.ServerHandle = i.ServerHandle;
                        isWork          = true;
                        break;
                    }
                }

                if (!isWork)
                {
                    //등록 안된 item을 쓸려고 했음
                    throw new Exception($"등록안된 ITEM[{strItem}에 값 변경을 시도 하였습니다. Item등록 하여 주십시요.");
                }

                iv.Value = intValue;

                OpcGrp.Write(new Opc.Da.ItemValue[] { iv });

                string strChanged = string.Format("[{0}] WorteValue : {1}", strItem, intValue);
                WroteAddressValue(strChanged, null, null);
            }
            catch (System.Runtime.InteropServices.ExternalException ex)
            {               //activex이기 때문에 에러 발생이 제대로 되지 않아 몇가지만...
                throw ComException(ex, strItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Zápis na OPC server v jiném threadu
        /// </summary>
        private void threadZapisWork()
        {
            try
            {
                List <Opc.Da.ItemValue> ItemWs = new List <Opc.Da.ItemValue>();

                foreach (Opc.Da.Item item in groupZapis.Items)
                {
                    ItemW itemW = itemsZapis[item.ItemName];
                    if ((WriteAll && (itemW.WriteMode != WMode.Assigned)) || itemW.ShouldWrite) //Výběr ItemW, které budou zapsány na OPC server
                    {
                        Opc.Da.ItemValue itemVal = new Opc.Da.ItemValue();
                        itemVal.ServerHandle = item.ServerHandle;         //Identifikace proměnné pro OPC server
                        itemVal.Value        = itemW.GetWValueToClient(); //Hodnota proměnné
                        ItemWs.Add(itemVal);
                    }
                }

                if (ItemWs.Count > 0) //Test, zda je co zapisovat
                {
                    Opc.Da.ItemValue[] writeValues = ItemWs.ToArray();
                    groupZapis.Write(writeValues);
                }
                fireWriteDoneEvents();
                timerWriteTimeout.Stop();
                writeAll = false;
                if (this.run)
                {
                    restarted = false;
                    timerReadFromOpc.Start();
                }
            }
            catch (Exception ex)
            {
                writeAll = true;
                chybaKomunikace("Nepodařilo se zapsat hodnotu na OPC server. " + ex.Message);
            }
        }
Exemplo n.º 16
0
        public void InitializeRepairTester([FromBody]TestRepairRequirement req)
        {
            if (req.Group == "Front")
            {
                PLCFactory factory = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = "[FrontRepairTester]RepairTester.BuildCode";
                writeValues[0].Value = 0;
                factory.WriteTags(writeValues);

                PLCFactory factory2 = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues2 = new Opc.Da.ItemValue[1];
                writeValues2[0] = new Opc.Da.ItemValue();
                writeValues2[0].ItemName = "[FrontRepairTester]RepairTester.BuildCode";
                writeValues2[0].Value = req.BuildCode;
                factory2.WriteTags(writeValues2);
            }
            else
            {
                
            }
        }
Exemplo n.º 17
0
 public void TorqueCompletePLCAck(int lineId)
 {
     if (lineId == 1)
     {
         PLCFactory factory = new PLCFactory(opcURL);
         Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[3];
         writeValues[0] = new Opc.Da.ItemValue();
         writeValues[0].ItemName = frontTorquesCompleteAck;
         writeValues[0].Value = 1;
         factory.WriteTags(writeValues);
     }
     else
     {
         PLCFactory factory = new PLCFactory(opcURL);
         Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[3];
         writeValues[0] = new Opc.Da.ItemValue();
         writeValues[0].ItemName = rearTorquesCompleteAck;
         writeValues[0].Value = 1;
         factory.WriteTags(writeValues);
     }
 }
Exemplo n.º 18
0
        public void EnableTorqueRecipe([FromBody]TorqueRepair trqRepair, int lineId)
        {
            var plcController = int.Parse(Regex.Match(trqRepair.ControllerName, @"\d+").Value);

            ReworkDataContext db = new ReworkDataContext();

            if (lineId == 1)
            {
                PLCFactory factory = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[3];
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = frontPSetRequest;
                writeValues[0].Value = trqRepair.Pset;

                writeValues[1] = new Opc.Da.ItemValue();
                writeValues[1].ItemName = frontTorqueRequest;
                writeValues[1].Value = trqRepair.TorquesRequired;

                writeValues[2] = new Opc.Da.ItemValue();
                writeValues[2].ItemName = frontPFBoxRequest;
                writeValues[2].Value = plcController;
                factory.WriteTags(writeValues);
            }
            else
            {
                PLCFactory factory = new PLCFactory(opcURL);
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[3];
                writeValues[0] = new Opc.Da.ItemValue();
                writeValues[0].ItemName = rearPSetRequest;
                writeValues[0].Value = trqRepair.Pset;

                writeValues[1] = new Opc.Da.ItemValue();
                writeValues[1].ItemName = rearTorqueRequest;
                writeValues[1].Value = trqRepair.TorquesRequired;

                writeValues[2] = new Opc.Da.ItemValue();
                writeValues[2].ItemName = rearPFBoxRequest;
                writeValues[2].Value = plcController;
                factory.WriteTags(writeValues);
            }
        }
Exemplo n.º 19
0
        public void RepairTestMESComplete(string readtag, string writetag)
        {
            PLCFactory factory = new PLCFactory(opcURL);
            Opc.Da.Item[] tags = new Opc.Da.Item[1];
            tags[0] = new Opc.Da.Item();
            tags[0].ItemName = readtag;

            var results = factory.ReadTags(tags);
            var result = Convert.ToInt32(results[0].Value.ToString());

            PLCFactory factory2 = new PLCFactory(opcURL);
            Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
            writeValues[0] = new Opc.Da.ItemValue();
            writeValues[0].ItemName = writetag;
            writeValues[0].Value = result;
            factory2.WriteTags(writeValues);
        }
Exemplo n.º 20
0
        // --------------------------------------------------------------------------
        public bool WriteVar <T>(string RefNameIn, T Value)
        {
            if (!Connected)
            {
                return(false);
            }

            try
            {
                //Remove all existing items from the group
                groupWrite.RemoveItems(groupWrite.Items);

                //Create the item to write:
                Opc.Da.Item[] itemToAdd = new Opc.Da.Item[1];
                itemToAdd[0]          = new Opc.Da.Item();
                itemToAdd[0].ItemName = OPCWriteVars[RefNameIn].FullName;

                //create the item that contains the value to write
                Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
                writeValues[0] = new Opc.Da.ItemValue(itemToAdd[0]);

                groupWrite.AddItems(itemToAdd);
                writeValues[0].ServerHandle = groupWrite.Items[groupWrite.Items.Length - 1].ServerHandle;

                //set the value to write
                switch (OPCWriteVars[RefNameIn].VarType)
                {
                case OPCVarType.BOOL:
                    writeValues[0].Value = Convert.ToBoolean(Value);
                    break;

                case OPCVarType.SINT:
                    writeValues[0].Value = Convert.ToSByte(Value);
                    break;

                case OPCVarType.INT:
                    writeValues[0].Value = Convert.ToInt16(Value);
                    break;

                case OPCVarType.DINT:
                    writeValues[0].Value = Convert.ToInt32(Value);
                    break;

                case OPCVarType.REAL:
                    writeValues[0].Value = Convert.ToSingle(Value);
                    break;

                case OPCVarType.STRING:
                    writeValues[0].Value = Convert.ToString(Value);
                    break;
                }

                //write
                groupWrite.Write(writeValues);

                return(true);
            }
            catch
            {
                ComError("Write to OPC variable failed");
                return(false);
            }
        }
Exemplo n.º 21
0
        public void SendRepairRUTesterData(List<TestRepairRequirement> req, int lineId)
        {
            if (lineId == 1)
            {
                #region Send Front Line RU Tester Data
                var drv = req.Where(r => r.TestId == 1).FirstOrDefault();
                var pas = req.Where(r => r.TestId == 2).FirstOrDefault();

                if (drv != null && pas != null)
                {
                    var jobId = drv.JobId;
                    var palletId = drv.PalletId;

                    var recipe1 = drv.BuildCode + 65536;
                    var recipe2 = pas.BuildCode + 65536;

                    Opc.Da.ItemValue[] ruWriteValues = new Opc.Da.ItemValue[5];
                    ruWriteValues[0] = new Opc.Da.ItemValue();
                    ruWriteValues[0].ItemName = frontRURepairTesterJobId;
                    ruWriteValues[0].Value = "" + jobId;

                    ruWriteValues[1] = new Opc.Da.ItemValue();
                    ruWriteValues[1].ItemName = frontRURepairTesterCartNum;
                    ruWriteValues[1].Value = palletId;

                    ruWriteValues[2] = new Opc.Da.ItemValue();
                    ruWriteValues[2].ItemName = frontRURepairTesterCartPresent;
                    ruWriteValues[2].Value = 1;

                    ruWriteValues[3] = new Opc.Da.ItemValue();
                    ruWriteValues[3].ItemName = frontRURepairTesterRecipe1;
                    ruWriteValues[3].Value = recipe1;

                    ruWriteValues[4] = new Opc.Da.ItemValue();
                    ruWriteValues[4].ItemName = frontRURepairTesterRecipe2;
                    ruWriteValues[4].Value = recipe2;

                    ruPLCRepairTester.WriteTags(ruWriteValues);
                }
                #endregion
            }
        }
Exemplo n.º 22
0
 public void WritePLCTag(PLCItem item)
 {
     PLCFactory factory = new PLCFactory(opcURL);
     Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
     writeValues[0] = new Opc.Da.ItemValue();
     writeValues[0].ItemName = item.TagName;
     writeValues[0].Value = item.TagValue;
     factory.WriteTags(writeValues);
 }
Exemplo n.º 23
0
 public void SendRepairRUAcknowledgment(int lineId)
 {
     if (lineId == 1)
     {
         #region Ack Front Line RU Tester
         Opc.Da.ItemValue[] ruTags = new Opc.Da.ItemValue[1];
         ruTags[0] = new Opc.Da.ItemValue();
         ruTags[0].ItemName = frontRURepairTesterDataReadyAck;
         ruTags[0].Value = 1;
         ruPLCRepairTester.WriteTags(ruTags);
         #endregion
     }
 }
Exemplo n.º 24
0
 public override Opc.Da.ItemValue[]  GetAcknowledgmentTags()
 {
     Opc.Da.ItemValue[] plcWriteTags = new Opc.Da.ItemValue[1];
     plcWriteTags[0] = GetItemValue<int>(GetFullTagName(dataReadyAckTag), 1);
     return plcWriteTags;
 }
Exemplo n.º 25
0
        public void InitializeRepairTest([FromBody]TestRepairRequirement req, string tag)
        {
            PLCFactory factory = new PLCFactory(opcURL);
            Opc.Da.ItemValue[] writeValues = new Opc.Da.ItemValue[1];
            writeValues[0] = new Opc.Da.ItemValue();
            writeValues[0].ItemName = tag;
            writeValues[0].Value = 0;
            factory.WriteTags(writeValues);

            PLCFactory factory2 = new PLCFactory(opcURL);
            Opc.Da.ItemValue[] writeValues2 = new Opc.Da.ItemValue[1];
            writeValues2[0] = new Opc.Da.ItemValue();
            writeValues2[0].ItemName = tag;
            writeValues2[0].Value = req.BuildCode;
            factory2.WriteTags(writeValues2);
        }
Exemplo n.º 26
0
        public async Task<List<TestRepairRequirement>> InitializeRepairTester([FromBody]List<TestRepairRequirement> req, int lineId, int testerMode, int testId)
       {
            PLCWrapper plc = new PLCWrapper(opcURL);
            CancellationTokenSource cts = new CancellationTokenSource();
            var timeout = 1000000;

            var requestedTest = req.Where(r => r.TestId == testId).FirstOrDefault();

            if (lineId == 1) //front line
            {
                if (requestedTest != null)
                {
                    //if RU OR tester mode is in RT/RU InTouch Mode
                    if (((requestedTest.BuildCode & (int)Math.Pow(2, 17)) == Math.Pow(2, 17)) || testerMode == 2)
                    {
                        if (requestedTest.TestId == 3) //FAM Tester
                        {
                            Tester inTouchFamTester = new InTouchTester(opcRUURL, frtRepairFamTesterTopic);
                            inTouchFamTester.ResetTester();

                            Tester inTouchRepairTester = new InTouchTester(opcRUURL, frtRepairTesterTopic);
                            inTouchRepairTester.ResetTester();

                            await Task.Delay(2000);
                            inTouchFamTester.InitializeTester(requestedTest.JobId, requestedTest.PalletId, requestedTest.BuildCode, requestedTest.BuildCode);

                            var result = await inTouchFamTester.WaitForResponse(requestedTest);
                            requestedTest = result;
                            
                        }
                        else if (requestedTest.TestId == 1 || requestedTest.TestId == 2)
                        {
                            //check if fam is done
                            if (req.Where(r => r.TestId == 3).Any())
                            {
                                var famTest = req.Where(r => r.TestId == 3).FirstOrDefault();
                                if (!famTest.Repaired)
                                    throw new HttpResponseException(
                                        HttpErrorResponse.GetHttpErrorResponse(
                                        HttpStatusCode.RequestTimeout, "FAM Test Required", string.Format("FAM Test Required")));
                            }

                            var drv = req.Where(r => r.TestId == 1).FirstOrDefault();
                            var pas = req.Where(r => r.TestId == 2).FirstOrDefault();

                            if (drv != null && pas != null)
                            {
                                Tester inTouchTester = new InTouchTester(opcRUURL, frtRepairTesterTopic);
                                inTouchTester.ResetTester();

                                await Task.Delay(2000);

                                inTouchTester.InitializeTester(requestedTest.JobId, requestedTest.PalletId, drv.BuildCode, pas.BuildCode);
                                var result = await inTouchTester.WaitForResponse(requestedTest);
                                if (result.Repaired)
                                {
                                    var allfrtTest = req.Where(r => r.TestId == 1 || r.TestId == 2).ToList();
                                    foreach (var t in allfrtTest)
                                    {
                                        t.Repaired = true;
                                        t.Dtm = DateTime.Now;
                                        t.TestResult = new TestRepairResult {
                                            TestResult = 1,
                                            TestStatus = 1,
                                            TestResultDetails = new List<TestRepairResultDetail>()
                                        };
                                    }

                                    Tester inTouchFamTester = new InTouchTester(opcRUURL, frtRepairFamTesterTopic);
                                    inTouchFamTester.ResetTester();
                                }
                            }
                            
                        }
                    }
                    else //RT LEGACY CODE
                    {
                        #region RT Tester Legacy Code
                        Opc.Da.ItemValue[] writeValues2 = new Opc.Da.ItemValue[1];
                        writeValues2[0] = new Opc.Da.ItemValue();
                        writeValues2[0].ItemName = frontRepairTesterBuildCode;
                        writeValues2[0].Value = requestedTest.BuildCode;
                        plc.WriteTags(writeValues2);

                        PLCFactory waitFactory = new PLCFactory(opcURL);
                        Opc.Da.Item[] tags = new Opc.Da.Item[1];
                        tags[0] = new Opc.Da.Item();
                        tags[0].ItemName = frontRepairTesterDataReady;

                        var task = waitFactory.WaitReadTags(tags, cts.Token);

                        if (await Task.WhenAny(task, Task.Delay(timeout, cts.Token)) == task)
                        {
                            var result = await task;

                            if (result.Status == 1)
                            {
                                //Read Result and Status Tags
                                Opc.Da.Item[] readResultTags = new Opc.Da.Item[2];
                                readResultTags[0] = new Opc.Da.Item();
                                readResultTags[0].ItemName = frontRepairTesterResult;
                                readResultTags[1] = new Opc.Da.Item();
                                readResultTags[1].ItemName = frontRepairTesterStatus;

                                var results = plc.ReadTags(readResultTags);

                                int testResult = Convert.ToInt32(results[0].Value.ToString());
                                int testStatus = Convert.ToInt32(results[1].Value.ToString());

                                //passed
                                if (testResult == testStatus)
                                    requestedTest.Repaired = true;
                                else
                                    requestedTest.Repaired = false;

                                requestedTest.TestResult = new TestRepairResult
                                {
                                    TestResult = testResult,
                                    TestStatus = testStatus,
                                    TestResultDetails = GetTestRepairResult(requestedTest, testResult, testStatus),
                                };

                                //Ack PLC
                                Opc.Da.Item[] requestIDTags = new Opc.Da.Item[1];
                                requestIDTags[0] = new Opc.Da.Item();
                                requestIDTags[0].ItemName = frontRepairTesterRequestID;

                                var requestIDTagsResults = plc.ReadTags(requestIDTags);
                                var requestIDTagsResult = Convert.ToInt32(requestIDTagsResults[0].Value.ToString());

                                Opc.Da.ItemValue[] responseIDTags = new Opc.Da.ItemValue[1];
                                responseIDTags[0] = new Opc.Da.ItemValue();
                                responseIDTags[0].ItemName = frontRepairTesterResponseID;
                                responseIDTags[0].Value = requestIDTagsResult;
                                plc.WriteTags(responseIDTags);

                                return req;
                            }
                            else
                            {
                                throw new HttpResponseException(
                                    HttpErrorResponse.GetHttpErrorResponse(
                                    HttpStatusCode.BadRequest, "Error", string.Format("Error Has Occured")));
                            }
                        }
                        else
                        {
                            throw new HttpResponseException(
                                HttpErrorResponse.GetHttpErrorResponse(
                                HttpStatusCode.RequestTimeout, "Request Timeout", string.Format("Timeout Has Occured")));
                        }
                        #endregion
                    }
                }

                return req;
            }
            else
            {
                if (requestedTest != null)
                {
                    //if RU OR tester mode is in RT/RU InTouch Mode
                    if (((requestedTest.BuildCode & (int)Math.Pow(2, 14)) == Math.Pow(2, 14)) || testerMode == 2)
                    {
                        #region RU Tester
                        if (requestedTest.TestId == 3 || requestedTest.TestId == 4)
                        {
                            Tester inTouchTester = new InTouchTester(opcRUURL, rearRepairTesterTopic);
                            inTouchTester.ResetTester();

                            await Task.Delay(4000);

                            if (requestedTest.TestId == 3)  //2nd row recipe
                                inTouchTester.InitializeTester(requestedTest.JobId, requestedTest.PalletId, requestedTest.BuildCode, 0);
                            else if (requestedTest.TestId == 4) //3rd row recipe
                                inTouchTester.InitializeTester(requestedTest.JobId, requestedTest.PalletId, 0, requestedTest.BuildCode);

                            var result = await inTouchTester.WaitForResponse(requestedTest);
                            requestedTest = result;
                        }
                        #endregion
                    }
                    else
                    {
                        #region RT Tester Legacy Code
                        Opc.Da.ItemValue[] writeValues2 = new Opc.Da.ItemValue[1];
                        writeValues2[0] = new Opc.Da.ItemValue();
                        writeValues2[0].ItemName = rearRepairTesterBuildCode;
                        writeValues2[0].Value = requestedTest.BuildCode;
                        plc.WriteTags(writeValues2);

                        PLCFactory waitFactory = new PLCFactory(opcURL);
                        Opc.Da.Item[] tags = new Opc.Da.Item[1];
                        tags[0] = new Opc.Da.Item();
                        tags[0].ItemName = rearRepairTesterDataReady;

                        var task = waitFactory.WaitReadTags(tags, cts.Token);

                        if (await Task.WhenAny(task, Task.Delay(timeout, cts.Token)) == task)
                        {
                            var result = await task;

                            if (result.Status == 1)
                            {
                                //Read Result and Status Tags
                                Opc.Da.Item[] readResultTags = new Opc.Da.Item[2];
                                readResultTags[0] = new Opc.Da.Item();
                                readResultTags[0].ItemName = rearRepairTesterResult;
                                readResultTags[1] = new Opc.Da.Item();
                                readResultTags[1].ItemName = rearRepairTesterStatus;

                                var results = plc.ReadTags(readResultTags);

                                int testResult = Convert.ToInt32(results[0].Value.ToString());
                                int testStatus = Convert.ToInt32(results[1].Value.ToString());

                                //passed
                                if (testResult == testStatus)
                                    requestedTest.Repaired = true;
                                else
                                    requestedTest.Repaired = false;

                                requestedTest.TestResult = new TestRepairResult
                                {
                                    TestId = requestedTest.TestId,
                                    TestResult = testResult,
                                    TestStatus = testStatus,
                                    TestResultDetails = GetTestRepairResult(requestedTest, testResult, testStatus),
                                };

                                await Task.Delay(2000);

                                //Ack PLC
                                Opc.Da.Item[] requestIDTags = new Opc.Da.Item[1];
                                requestIDTags[0] = new Opc.Da.Item();
                                requestIDTags[0].ItemName = rearRepairTesterRequestID;

                                var requestIDTagsResults = plc.ReadTags(requestIDTags);
                                var requestIDTagsResult = Convert.ToInt32(requestIDTagsResults[0].Value.ToString());

                                Opc.Da.ItemValue[] responseIDTags = new Opc.Da.ItemValue[1];
                                responseIDTags[0] = new Opc.Da.ItemValue();
                                responseIDTags[0].ItemName = rearRepairTesterRespondID;
                                responseIDTags[0].Value = requestIDTagsResult;
                                plc.WriteTags(responseIDTags);

                                return req;
                            }
                            else
                            {
                                throw new HttpResponseException(
                                    HttpErrorResponse.GetHttpErrorResponse(
                                    HttpStatusCode.BadRequest, "Error", string.Format("Error Has Occured")));
                            }
                        }
                        else
                        {
                            throw new HttpResponseException(
                                HttpErrorResponse.GetHttpErrorResponse(
                                HttpStatusCode.RequestTimeout, "Request Timeout", string.Format("Timeout Has Occured")));
                        }
                        #endregion
                    }
                }

                return req;

            }

        }