示例#1
0
        //public override void UpdateDevice(string deviceId, object obj)
        //{
        //    return;
        //}

        //public override void RemoveDevice(string deviceId)
        //{
        //    return;
        //}

        public override void StartService()
        {
            try
            {
                if (_config == null)
                {
                    return;
                }

                if (_config.StartOpcClientService)
                {
                    if (_client == null)
                    {
                        _client = new OPCClient(_config);
                        _client.OPCClientDataChangeEvent += Client_OPCClientDataChangeEvent;
                    }

                    //ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncInitialize));

                    _client.Initialize();
                }
            }
            catch (Exception ex)
            {
                OnServiceLog(ex.Message);
            }
        }
示例#2
0
        public void init()
        {
            try
            {
                DevExpress.Persistent.Base.PasswordCryptographer.EnableRfc2898       = true;
                DevExpress.Persistent.Base.PasswordCryptographer.SupportLegacySha512 = false;

                //INIT XAF AND DEFAULT DB SERVER
                initXAFServer();

                //INIT WS PRIVATE INTERFACES HTTP SELFHOSTING
                initWSHostPrivateInterfaces();

                //INIT WS PUBLIC INTERFACES HTTP SELFHOSTING
                initWSHostPublicInterfaces();


                SetAisleList();
                SetAbcTypeList();
                SetStorageHeightList();


                //INIT OPC
                opcClient = new OPCClient();
                opcClient.init();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurs: " + e.Message);
                Console.WriteLine("Press Enter to close.");
                Console.ReadLine();
            }
        }
示例#3
0
 public BrainHeart()
 {
     lastSignal = currentSignal = false;
     config     = ConfigString.GetInstance();
     config.GetALLNeedDataFromIni();
     opcClient = new OPCClient(config.OPC_Read_Address);
     tcpClient = new TCPCommunication(config.IP);
     ScanTask  = new Task(ScanReadImageSignal);
 }
示例#4
0
        void Init()
        {
            dbClient  = new DBClient();
            opcClient = new OPCClient();

            opcClient.AddWriteGroupTags();
            opcClient.AddReadGroupTags();

            opcClient.writeGroup = opcClient.SetupOPCWriteGroup("WriteGroup");
            opcClient.readGroup  = opcClient.SetupOPCReadGroup("ReadGroup");
        }
        /*---- End Code Migration ----*/

        public MonitoringForm()
        {
            InitializeComponent();
            this._presenter = new MainPresenter(this);

            /*---- Start Code Migration ----*/
            OPC = new OPCClient();
            // Subscribe to the notification handler:
            OPC.NotificationHandler += new Action(CheckNotifications);

            // Subscribe to error message handler:
            OPC.ComErrorHandler += new Action <string>(ComErrorMessage);
            /*---- End Code Migration ----*/
        }
        private static void notifyOpc(string lcode)
        {
            var        param = new OPCParam();
            IOpcClient client;

#if DEBUG
            client = new FakeOpcClient(param);
#else
            client = new OPCClient();
#endif
            client.Open(clsSetting.OPCServerIP);
            param.DeleteLCode = new LCodeSignal(client, "DeleteLCode");

            PlcHelper.NotifyLabelCodeDeleted(client, param, lcode);
        }
示例#7
0
        public MonitoringService()
        {
            InitializeComponent();

            application = new ApplicationInstance();
            application.ApplicationType   = ApplicationType.Client;
            application.ConfigSectionName = "Quickstarts.ReferenceClient";

            //// load the application configuration.
            string configPath = AppDomain.CurrentDomain.BaseDirectory + @"\Quickstarts.ReferenceClient.Config.xml";

            application.LoadApplicationConfiguration(configPath, true);

            //// check the application certificate.
            application.CheckApplicationInstanceCertificate(false, 0);

            // set OPC server endpoint
            serverUrl = TankDataTypes.serverUrl;

            opcClient = new OPCClient(application.ApplicationConfiguration, serverUrl);
        }
示例#8
0
        /// <summary>
        /// 初始化参数
        /// </summary>
        private void Initialize()
        {
            sConFilePath    = ConfigurationSettings.AppSettings["Config.FilePath"];
            sLogFilePath    = ConfigurationSettings.AppSettings["Log.FilePath"];
            sServerName     = ConfigurationSettings.AppSettings["ServerName"];
            sSqlStr         = ConfigurationSettings.AppSettings["SqlStr"];
            iDataRefrTimes  = int.Parse(ConfigurationSettings.AppSettings["DataRefrTimes"]);
            iSqlRefrTimes   = int.Parse(ConfigurationSettings.AppSettings["SqlRefrTimes"]);
            bReConnect      = bool.Parse(ConfigurationSettings.AppSettings["bReConnect"]);
            iReConnectTimes = int.Parse(ConfigurationSettings.AppSettings["ReConnectTimes"]);

            opcKepClient = new OPCClient(sLogFilePath);

            string[] sConFilePaths = sConFilePath.Split(new char[] { ';' });
            foreach (string sConFilePath in sConFilePaths)
            {
                string[] sFlieNames = sConFilePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string   sFlieName  = sFlieNames[sFlieNames.Length - 1];
                sFlieName = sFlieName.Replace(".xlsx", "");

                OPCItemsStruct OPCItemsStrt = new OPCItemsStruct();
                OPCItemsStrt.sGroupName = sFlieName;

                DataSet   dsOPCGroup = ExcelFunction.ExcelRead(sConFilePath);
                DataTable dtOPCGroup = dsOPCGroup.Tables[0];
                int       iRowCounts = dtOPCGroup.Rows.Count;

                OPCItemsStrt.sItems = new string[iRowCounts];
                for (int i = 0; i < iRowCounts; i++)
                {
                    if (dtOPCGroup.Rows[i][0] is System.DBNull == false)
                    {
                        OPCItemsStrt.sItems[i] = sFlieName + "." + dtOPCGroup.Rows[i][0].ToString();
                    }
                }
                lOPCItemsStrt.Add(OPCItemsStrt);
            }
        }
        public void init()
        {
            try
            {
                log.Info("LogXServer init() begins..!");
                DevExpress.Persistent.Base.PasswordCryptographer.EnableRfc2898       = true;
                DevExpress.Persistent.Base.PasswordCryptographer.SupportLegacySha512 = false;

                //INIT XAF AND DEFAULT DB SERVER
                initXAFServer();
                log.Info("LogXServer.xafServer inited.");

                //INIT WS PRIVATE INTERFACES HTTP SELFHOSTING
                initWSHostPrivateInterfaces();

                //INIT WS PUBLIC INTERFACES HTTP SELFHOSTING
                initWSHostPublicInterfaces();
                log.Info("LogXServer.ws interfaces are inited.");

                //INIT OPC
                opcClient = new OPCClient();
                opcClient.init();
                log.Info("LogXServer opcClient inited");

                SetAisleList();
                SetAbcTypeList();
                SetStorageHeightList();
                log.Info("LogXServer default lists loaded");


                log.Info("LogXServer init() end!");
            }
            catch (Exception e)
            {
                log.Fatal("Error in LogXServer.init(): ", e);
            }
        }
示例#10
0
文件: Input.cs 项目: goneyears/lambda
 public Input(string name, OPCClient oc) : base(name, oc)
 {
 }
示例#11
0
        static async Task Execute()
        {
            try
            {
                GetClient(new HandlerConfig().WithElement("SetVariableAsync", SetVariableAsync).Elements);

                CustomLogger logger = new CustomLogger();

                var opcConnectionString = @"opc.tcp://127.0.0.1:49320";
                MyClient = new OPCClient(opcConnectionString, "", "", logger, "Mytest2", SecurityPolicy.Basic128, MessageSecurity.Sign);

                R1 = (OPCTag)MyClient.AddTag("RAMP1", "ns=2;s=TEST_OPC.RAMP.RAMP1", typeof(float));
                T0 = (OPCTag)MyClient.AddTag("WRITE1", "ns=2;s=TEST_OPC.WRITE.WRITE1", typeof(float));
                T1 = (OPCTag)MyClient.AddTag("WRITE2", "ns=2;s=TEST_OPC.WRITE.WRITE2", typeof(float));
                T2 = (OPCTag)MyClient.AddTag("WRITE3", "ns=2;s=TEST_OPC.WRITE.WRITE3", typeof(float));

                var T3 = (OPCTag)MyClient.AddTag("Cast", "ns=2;s=TEST_OPC.WRITE.WRITESLOW1", typeof(double));
                T3.ReadItem();

                List <string> TagNameList = new List <string>();
                TagNameList.Add(T0.Name);
                TagNameList.Add(T1.Name);
                TagNameList.Add(T2.Name);
                TagNameList.Add(R1.Name);

                var baseName1 = "ns=2;s=TEST_OPC.RAMP.RAMP";
                var baseName2 = "ns=2;s=TEST_OPC.RAND.RAND";

                for (int i = 1; i <= 150; i++)
                {
                    var tagName1 = $"{baseName1}{i}";
                    MyClient.AddTag(tagName1, tagName1, typeof(float));
                    TagNameList.Add(tagName1);

                    var tagName2 = $"{baseName2}{i}";
                    MyClient.AddTag(tagName2, tagName2, typeof(int));
                    TagNameList.Add(tagName2);
                }

                while (true)
                {
                    MyClient.ReadTags(TagNameList);
                    IotMessage message = new IotMessage();
                    message.Datetime = DateTime.Now;
                    message.DeviceId = "PLC0001";
                    message.Data     = new List <Payload>();
                    foreach (var x in TagNameList)
                    {
                        double y = 0;
                        if (MyClient.GetTag(x)?.Value != null)
                        {
                            y = Double.Parse(MyClient.GetTag(x).Value.ToString());
                        }

                        message.Data.Add(new Payload()
                        {
                            datetime = DateTime.Now, name = MyClient.GetTag(x).Name, value = y
                        });
                        Console.WriteLine(MyClient.GetTag(x).Name + " | " + MyClient.GetTag(x).Value);
                    }

                    SendEvent(_deviceClient, message).GetAwaiter().GetResult();

                    Thread.Sleep(100);
                    Console.WriteLine("----");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            try
            {
                Tag_List = new ObservableCollection <OPCTag>();

                CustomLogger logger = new CustomLogger();

                var opcConnectionString = @"opc.tcp://127.0.0.1:49320";
                //var opcConnectionString = @"opc.tcp://10.0.2.170:49320";

                //var endpoint1 = OPCCoreUtils.SelectEndpointBySecurity(opcConnectionString, SecurityPolicy.Basic128, MessageSecurityMode.Sign, 10000);


                MyClient = new OPCClient(opcConnectionString, "", "", logger, "Mytest2", SecurityPolicy.Basic128, MessageSecurity.Sign);

                T  = (OPCTag)MyClient.AddTag("RAMP1", "ns=2;s=TEST_OPC.RAMP.RAMP1", typeof(float));
                T0 = (OPCTag)MyClient.AddTag("WRITE1", "ns=2;s=TEST_OPC.WRITE.WRITE1", typeof(float));
                T1 = (OPCTag)MyClient.AddTag("WRITE2", "ns=2;s=TEST_OPC.WRITE.WRITE2", typeof(float));
                T2 = (OPCTag)MyClient.AddTag("WRITE3", "ns=2;s=TEST_OPC.WRITE.WRITE3", typeof(float));
                float val         = 5;
                var   writeResult = T0.WriteItem(val);
                T0.ReadItem();

                var T3 = (OPCTag)MyClient.AddTag("CAst", "ns=2;s=TEST_OPC.WRITE.WRITESLOW1", typeof(double));
                T3.ReadItem();
                Console.WriteLine(T3.Value);

                //T0 = (OPCTag)MyClient.AddTag("Write01", "ns=4;s=MAIN.iMS0", typeof(short));
                //T0.WriteItem((short)5);

                //T0.ReadItem();

                //val = 100f;
                //T0.WriteItem(val);
                //T0.ReadItem();

                //T0.SubscribeItem(null,null, Newvalue);
                List <string> TagNameList   = new List <string>();
                List <object> TagObjectList = new List <object>();
                TagNameList.Add(T0.Name);
                TagNameList.Add(T1.Name);
                TagNameList.Add(T2.Name);
                TagObjectList.Add(101f);
                TagObjectList.Add(102f);
                TagObjectList.Add(103f);
                bool Readok = MyClient.ReadTags(TagNameList);

                bool Writeok = MyClient.WriteTags(TagNameList, TagObjectList);

                //Tag_List.Add(T);
                //Tag_List.Add(T);

                //this.DataContext = Tag_List;

                ////T.WriteItem(10);

                // Read multiple variables at once
                var baseName1 = "ns=2;s=TEST_OPC.RAMP.RAMP";
                var baseName2 = "ns=2;s=TEST_OPC.RAND.RAND";

                tagsToRead = new List <string>();
                for (int i = 1; i <= 150; i++)
                {
                    var tagName1 = $"{baseName1}{i}";
                    MyClient.AddTag(tagName1, tagName1, typeof(float));
                    tagsToRead.Add(tagName1);

                    var tagName2 = $"{baseName2}{i}";
                    MyClient.AddTag(tagName2, tagName2, typeof(int));
                    tagsToRead.Add(tagName2);
                }

                concurrentQueue = new ConcurrentQueue <Tuple <bool, long> >();

                Timer _timer = new Timer(50);
                _timer.Elapsed += _timer_Elapsed;
                _timer.Start();

                Timer _health = new Timer(1000);
                _health.Elapsed += _health_Elapsed;
                _health.Start();

                //MyClient.SubScribeTag(T, 0, 0, null);
                MyClient.SubscribeTag(T0, 0, 0, Newvalue);
                //var name = Console.ReadLine();

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#13
0
 public Variable(string name, OPCClient oc)
 {
     _OPCClient = oc;
     Name       = name;
 }
示例#14
0
 public connectManager()
 {
     OPC = new OPCClient();
 }
示例#15
0
 public static void setup(OPCClient c, OPCParam p, Action <string, string, LogViewType> logfunc)
 {
     client = c;
     param  = p;
     _log   = logfunc;
 }