コード例 #1
0
        //Initialize OPC Server and obtain the IOPCSyncIO interface
        private bool InitializeServer()
        {
            OPCServerLib.Server server = new OPCServerLib.Server();
            int    TimeBias            = 0;
            float  DeadBand            = 0.0f;
            uint   phServerGroup;
            uint   UpdateRate;
            var    id = typeof(OPC.IOPCItemMgt).GUID;
            object p;

            server.AddGroup("Group1", 1, 10, 1, ref TimeBias, ref DeadBand, 0, out phServerGroup, out UpdateRate, ref id, out p);

            //Obtain IOPCItemMgt interface
            OPC.IOPCItemMgt pOPCItemMgt = (OPC.IOPCItemMgt)p;
            Item[]          items       = { new Item("ItemY1", 1, VarEnum.VT_R8, VarEnum.VT_EMPTY, false, null),
                                            new Item("ItemY2",                2, VarEnum.VT_R8, VarEnum.VT_EMPTY, false, null),
                                            new Item("ItemY3",                3, VarEnum.VT_R8, VarEnum.VT_EMPTY, false, null) };

            IntPtr itemPtr = OPCHelper.GetIntPtrfromItemArray(items);
            IntPtr dataPtr;
            IntPtr errorsPtr;

            pOPCItemMgt.AddItems(3, itemPtr, out dataPtr, out errorsPtr);

            //Obtain IOPCSyncIO interface
            syncIO = (OPC.IOPCSyncIO)p;

            return(true);
        }
コード例 #2
0
        //Obtain signals from IOPCSyncIO
        private ItemValue[] ReadSignals()
        {
            int[]  serverIds = { 0, 1, 2 };
            IntPtr dataPtr1;
            IntPtr errorsPtr1;

            syncIO.Read(DataSource.Cache, 3, serverIds, out dataPtr1, out errorsPtr1);

            ItemValue[] temItem = OPCHelper.GetSignalsState(3, dataPtr1, errorsPtr1);
            for (int k = 0; k < 3; ++k)
            {
                if (temItem[k].Error < 0)
                {
                    Console.WriteLine("Error!");
                    return(null);
                }
            }
            return(temItem);
        }
コード例 #3
0
        private void 获取opc配置_Click(object sender, RoutedEventArgs e)
        {
            Tuple <string, Guid> server = cmb_OpcSerList.SelectedItem as Tuple <string, Guid>;

            if (null == server)
            {
                MessageBox.Show("请选择服务点");
                return;
            }
            List <DriveNodeEntity> listDriveNodes;

            OPCHelper.GetOpcServerAllItem(txtOpcIp.Text.Trim(), server.Item2, out listDriveNodes);

            driveNodeRoot.nodeStrGuid = server.Item2.ToString();
            driveNodeRoot.nodeName    = server.Item1;
            driveNodeRoot.serviceIp   = txtOpcIp.Text.Trim();
            driveNodeRoot.childNode   = listDriveNodes;

            string strDriveNodeRoot;

            JsonHelper.ObjectToStrJson(driveNodeRoot, out strDriveNodeRoot);
            Console.WriteLine(strDriveNodeRoot);
        }
コード例 #4
0
        private void 获取opc服务列表_Click(object sender, RoutedEventArgs e)
        {
            List <Tuple <string, Guid> > opcSerList = OPCHelper.GetOPCServiceList(txtOpcIp.Text.Trim());

            cmb_OpcSerList.ItemsSource = opcSerList;
        }