private string conectOPC(string id_opcClient)
        {
            var opcClient = repo._context.sys_opc_clients.Where(t => t.id == id_opcClient).Select(t => t.opc_client).SingleOrDefault();
            var client    = new OpcClient(opcClient);

            try
            {
                client.Connect();
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            client.Dispose();
            return("Kết nối thành công");
        }
Exemplo n.º 2
0
        private string conectOPC(string id_opcClient, string opcnode)
        {
            var opcClient = repo._context.sys_opc_clients.Where(t => t.id == id_opcClient).Select(t => t.opc_client).SingleOrDefault();
            var client    = new OpcClient(opcClient);

            try
            {
                client.Connect();
            }
            catch (Exception e)
            {
                writelogcmd("Cannot connection: " + e.Message);
                return(null);
            }
            var Value = client.ReadNode(new OpcReadNode(opcnode, OpcAttribute.Value));

            client.Dispose();
            return(Value.ToString() ?? "");
        }
        public IActionResult getopcvalue([FromBody] JObject json)
        {
            var model = JsonConvert.DeserializeObject <sys_opc_view_model>(json.GetValue("data").ToString());

            try
            {
                var client = new OpcClient(model.opc_client);
                client.Connect();

                model.value_input  = client.ReadNode(new OpcReadNode(model.opc_node_input, OpcAttribute.Value)).ToString();
                model.value_output = client.ReadNode(new OpcReadNode(model.opc_node_output, OpcAttribute.Value)).ToString();
                model.value_error  = client.ReadNode(new OpcReadNode(model.opc_node_output, OpcAttribute.Value)).ToString();
                for (int i = 0; i < model.list_param.Count; i++)
                {
                    model.list_param[i].value = client.ReadNode(new OpcReadNode(model.list_param[i].opc_node, OpcAttribute.Value)).ToString();
                }
                client.Dispose();
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
            return(Json(model));
        }
Exemplo n.º 4
0
 public virtual void Dispose()
 {
     _OpcClient.Close();
     _OpcClient.Dispose();
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     _client.Dispose();
 }