예제 #1
0
        public void updatePLCOutput(PLCOutput plcOutput)
        {
            var collection = _database.GetCollection <BsonDocument>("PLC_outputs");
            var filter     = Builders <BsonDocument> .Filter.Eq("id", plcOutput.id);

            var update = Builders <BsonDocument> .Update.Set("iPLC_STATUS", plcOutput.iPlc_Status);

            //  .Set("output_int", testOutput.output_int)
            //  .Set("output_random", testOutput.output_random);
            //var update = Builders<BsonDocument>.Update.Set("order_status", order.order_status);
            var result = collection.UpdateMany(filter, update);
        }
예제 #2
0
 // POST: api/PLCOutput
 public void Post(string json_plcOutput)
 {
     try
     {
         PLCOutput plcOutput = (PLCOutput)JsonConvert.DeserializeObject(json_plcOutput);
         dbClient.InsertPLCOutput(plcOutput);
     }
     catch (Exception ex)
     {
         //cannot parse object (invalid input string)
     }
 }
예제 #3
0
        public List <PLCOutput> GetPLCOutputs()
        {
            List <PLCOutput> _plcOutputs = new List <PLCOutput>();
            var collection = _database.GetCollection <BsonDocument>("PLC_outputs");
            var filter     = new BsonDocument();
            var results    = collection.Find(filter).Limit(100).ToList();

            if (results.Count > 0)
            {
                foreach (var result in results)
                {
                    PLCOutput plcOutput = new PLCOutput(result);
                    _plcOutputs.Add(plcOutput);
                }
            }
            return(_plcOutputs);
        }
예제 #4
0
 internal void InsertPLCOutput(PLCOutput pLCOutput)
 {
     throw new NotImplementedException();
 }
예제 #5
0
        void ReadItems(OPCGroup ObjOPCGroup)
        {
            //READ ITEMS
            object qualities;
            object timestamp;

            try
            {
                if (CurrentPLCOutput == null)
                {
                    CurrentPLCOutput = new PLCOutput();
                }

                while (!stopThreads)
                {
                    //DA SE NAJDE DOBAR NACIN ZA CITANJE NA TAGOVITE SO SERVER HANDLES
                    ObjOPCGroup.SyncRead((short)OPCAutomation.OPCDataSource.OPCDevice,
                                         tagIndexReader - 1,
                                         ref readerItemServerHandles,
                                         out ItemServerReadValues,
                                         out readerItemServerErrors,
                                         out qualities,
                                         out timestamp);
                    string message = "";
                    for (int i = 1; i <= Globals.GetTotalNumberOfOutputTags(); i++)
                    {
                        int index = Globals.OUTPUT_TAGS.FirstOrDefault(x => x.Name == "iPLC_STATUS").Index;
                        if (index == i)
                        {
                            CurrentPLCOutput.iPlc_Status = (int)ItemServerReadValues.GetValue(i);
                        }

                        //vaka i za drugite nadolu, nemoj so switch

                        //switch (i)
                        //{
                        //    case CurrentPLCOutput.indexes.IndexOf("iPLC_STATUS"):
                        //        CurrentPLCOutput.iPlc_Status = (int)ItemServerReadValues.GetValue(i);
                        //        break;
                        //    //case 2:
                        //    //    CurrentTestOutput.output_bool = (bool)ItemServerReadValues.GetValue(i);
                        //    //    break;
                        //    //case 4:
                        //    //    CurrentTestOutput.output_int = (int)ItemServerReadValues.GetValue(i);
                        //    //    break;
                        //    //case 5:
                        //    //    CurrentTestOutput.output_random = (int)ItemServerReadValues.GetValue(i);
                        //    //    break;
                        //    default:
                        //        break;
                        //}
                        Workflow.plcOutputs.Add(CurrentPLCOutput);
                        message = message + i.ToString() + ": " + ItemServerReadValues.GetValue(i).ToString() + "\t";
                    }

                    //message = message + " " + ((Array)timestamp).GetValue(1).ToString() + " " + ((Array)timestamp).GetValue(2).ToString() + " " + ((Array)timestamp).GetValue(3).ToString();
                    Console.WriteLine(message);
                    //Workflow.LogMessage(message);
                    //UPDATE WORKFLOW.VENDORS.ROBOT.ORDER.STATUS with OPC STATUSES!!! np tests
                    //}

                    /*
                     * foreach (Vendor vendor in Workflow.vendors)
                     * {
                     *  vendor.robot.test1 = ItemServerReadValues.GetValue(1).ToString();
                     *  vendor.robot.test2 = ItemServerReadValues.GetValue(2).ToString();
                     *  vendor.robot.test3 = ItemServerReadValues.GetValue(3).ToString();
                     * }
                     */


                    System.Threading.Thread.Sleep(500);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                throw;
            }
        }