示例#1
0
        /// <summary>
        ///     Retrieves information about a session established between a particular server and workstation. Descriptions taken
        ///     from https://msdn.microsoft.com/en-us/library/windows/desktop/bb525383(v=vs.85).aspx (NetSessionGetInfo function).
        /// </summary>
        /// <param name="servername">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the
        ///     function is to execute. If this parameter is NULL, the local computer is used.
        /// </param>
        /// <param name="clientame">
        ///     Pointer to a string that specifies the name of the computer session for which information is to
        ///     be returned. This parameter is required and cannot be NULL. For more information, see NetSessionEnum.
        /// </param>
        /// <param name="username">
        ///     Pointer to a string that specifies the name of the user whose session information is to be
        ///     returned. This parameter is required and cannot be NULL.
        /// </param>
        /// <returns></returns>
        public static SessionInfo2 GetSession(string servername, string clientame, string username)
        {
            var    returnValue = new SessionInfo2();
            IntPtr pBuffer;
            var    status = DllImports.NetSessionGetInfo(servername, clientame, username, 3, out pBuffer);

            if (status == 0)
            {
                var shareinfoType = typeof(Structs.SessionInfo2);
                var pItem         = new IntPtr(pBuffer.ToInt32());
                var sessionInfo2  = (Structs.SessionInfo2)Marshal.PtrToStructure(pItem, shareinfoType);
                returnValue = SessionInfo2.MapToSessionInfo2(sessionInfo2);
                ApiBuffer.FreeBuffer(pBuffer);
            }
            return(returnValue);
        }
        /// <summary>
        ///     Retrieves operating statistics for a service. Currently, only the workstation and server services are supported.
        /// </summary>
        /// <param name="serverName">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the server on which the function
        ///     is to execute. If this parameter is NULL, the local computer is used.
        /// </param>
        /// <param name="netName">
        ///     Pointer to a string that specifies the name of the service about which to get the statistics.
        ///     Only the values SERVICE_SERVER and SERVICE_WORKSTATION are currently allowed.
        /// </param>
        /// <returns>
        ///     If the function succeeds, the return value is NERR_Success. If the function fails, the return value is a
        ///     system error code. For a list of error codes, see System Error Codes.
        /// </returns>
        public static Statworkstation0 GetStatistics(string serverName, string netName)
        {
            var    returnValue = new Statworkstation0();
            IntPtr pBuffer;
            var    status = DllImports.NetShareGetInfo(serverName, netName, 503, out pBuffer);

            if (status == 0)
            {
                var shareinfoType    = typeof(Structs.StatWorkstation0);
                var pItem            = new IntPtr(pBuffer.ToInt32());
                var statworkstation0 = (Structs.StatWorkstation0)Marshal.PtrToStructure(pItem, shareinfoType);
                returnValue = Statworkstation0.MapToStatworkstation0(statworkstation0);
                ApiBuffer.FreeBuffer(pBuffer);
            }
            return(returnValue);
        }
示例#3
0
        /// <summary>
        ///     Retrieves information about a particular shared resource on a server.
        /// </summary>
        /// <param name="serverName">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the
        ///     function is to execute. If this parameter is NULL, the local computer is used.
        /// </param>
        /// <param name="netName">Pointer to a string that specifies the name of the share for which to return information.</param>
        /// <returns>A managed ShareInfo503 Object.</returns>
        public static ShareInfo503 GetInfo(string serverName, string netName)
        {
            var    returnValue = new ShareInfo503();
            IntPtr pBuffer;
            var    status = NetworkShareManagementFunctions.NetShareGetInfo.DllImports.NetShareGetInfo(serverName, netName, 503, out pBuffer);

            if (status == 0)
            {
                var shareinfoType = typeof(Structs.FileInfo3);
                var pItem         = new IntPtr(pBuffer.ToInt32());
                var shareInfo503  = (Structs.ShareInfo503)Marshal.PtrToStructure(pItem, shareinfoType);
                returnValue = ShareInfo503.MapToShareInfo503(shareInfo503);
                ApiBuffer.FreeBuffer(pBuffer);
            }
            return(returnValue);
        }
示例#4
0
        /// <summary>
        ///     Retrieves information about a particular opening of a server resource. Descriptions taken from
        ///     https://msdn.microsoft.com/en-us/library/windows/desktop/bb525379(v=vs.85).aspx (NetFileGetInfo function).
        /// </summary>
        /// <param name="servername">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the
        ///     function is to execute. If this parameter is NULL, the local computer is used. This string is Unicode if
        ///     _WIN32_WINNT or FORCE_UNICODE is defined.
        /// </param>
        /// <param name="fileid">
        ///     Specifies the file identifier of the open resource for which to return information. The value of
        ///     this parameter must have been returned in a previous enumeration call. For more information, see the following
        ///     Remarks section.
        /// </param>
        /// <returns></returns>
        public static FileInfo3 GetFileInfo(string servername, int fileid)
        {
            var    returnValue = new FileInfo3();
            IntPtr pBuffer;
            var    status = Internal.Native.NetworkShareManagementFunctions.NetFileGetInfo.DllImports.NetFileGetInfo(servername, fileid, 3, out pBuffer);

            if (status == 0)
            {
                var shareinfoType = typeof(Structs.FileInfo3);
                var pItem         = new IntPtr(pBuffer.ToInt32());
                var fileInfo3     = (Structs.FileInfo3)Marshal.PtrToStructure(pItem, shareinfoType);
                returnValue = FileInfo3.MapToFileInfo3(fileInfo3);
                ApiBuffer.FreeBuffer(pBuffer);
            }
            return(returnValue);
        }
示例#5
0
        /// <summary>
        ///     Provides information about sessions established on a server.
        /// </summary>
        /// <param name="server">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the
        ///     function is to execute. If this parameter is NULL, the local computer is used.
        /// </param>
        /// <param name="clientName">
        ///     Pointer to a string that specifies the name of the computer session for which information is
        ///     to be returned. If this parameter is NULL, NetSessionEnum returns information for all computer sessions on the
        ///     server.
        /// </param>
        /// <param name="userName">
        ///     Pointer to a string that specifies the name of the user for which information is to be returned.
        ///     If this parameter is NULL, NetSessionEnum returns information for all users.
        /// </param>
        /// <returns>A Ienumerable of managed SessionInfo502 Objects.</returns>
        public static IEnumerable <SessionInfo502> GetSessions(string server, string clientName, string userName)
        {
            var    list = new List <SessionInfo502>();
            int    entriesRead;
            int    totalEntries;
            var    resumeHandle = 0;
            IntPtr pBuffer;
            var    status = Internal.Native.NetworkShareManagementFunctions.NetSessionEnum.DllImports.NetSessionEnum(server, null, null, 502, out pBuffer, -1, out entriesRead, out totalEntries, ref resumeHandle);

            if (status == 0 & entriesRead > 0)
            {
                var shareinfoType = typeof(Structs.SessionInfo502);
                var offset        = Marshal.SizeOf(shareinfoType);
                for (int i = 0, item = pBuffer.ToInt32(); i < entriesRead; i++, item += offset)
                {
                    var pItem                = new IntPtr(item);
                    var sessionInfo502       = (Structs.SessionInfo502)Marshal.PtrToStructure(pItem, shareinfoType);
                    var netSessionEnumResult = SessionInfo502.MapToSessionInfo502(sessionInfo502);
                    list.Add(netSessionEnumResult);
                }
            }
            ApiBuffer.FreeBuffer(pBuffer);
            return(list);
        }
示例#6
0
        /// <summary>
        ///     Returns information about some or all open files on a server, depending on the parameters specified.
        /// </summary>
        /// <param name="server">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the
        ///     function is to execute. If this parameter is NULL, the local computer is used. This string is Unicode if
        ///     _WIN32_WINNT or FORCE_UNICODE is defined.
        /// </param>
        /// <returns>A IEnumerable of Managed FileInfo3 Objects.</returns>
        public static IEnumerable <FileInfo3> GetNetFileList(string server)
        {
            var list = new List <FileInfo3>();
            int entriesRead;
            int totalEntries;
            var resumeHandle = 0;
            var pBuffer      = IntPtr.Zero;
            var status       = DllImports.NetFileEnum(server, null, null, 3, ref pBuffer, -1, out entriesRead, out totalEntries, ref resumeHandle);

            if (status == 0 & entriesRead > 0)
            {
                var shareinfoType = typeof(Structs.FileInfo3);
                var offset        = Marshal.SizeOf(shareinfoType);
                for (int i = 0, item = pBuffer.ToInt32(); i < entriesRead; i++, item += offset)
                {
                    var pItem             = new IntPtr(item);
                    var fileInfo3         = (Structs.FileInfo3)Marshal.PtrToStructure(pItem, shareinfoType);
                    var nEtFileEnumResult = FileInfo3.MapToFileInfo3(fileInfo3);
                    list.Add(nEtFileEnumResult);
                }
                ApiBuffer.FreeBuffer(pBuffer);
            }
            return(list);
        }
示例#7
0
        /// <summary>
        /// 建立通讯
        /// </summary>
        /// <param name="infoHardWare"></param>
        private void EstablishCommunication(object infoHardWare)
        {
            var softservoInfo = infoHardWare as SoftservoControlerInfo;
            int ret;

            Thread.Sleep(5000);

            cmApi           = new CoreMotion(wmx);
            fx_EventControl = new EventControl(wmx);
            fx_ApiBuffer    = new ApiBuffer(wmx);
            ecapi           = new EcApiLib(wmx);

            fx_ListMotion = new ListMotion(wmx);

            wmx_IO = new Io(wmx);
            //设置系统参数
            ret = cmApi.Config.ImportAndSetAll(softservoInfo.m_strConfigPath);
            if (ret != 0)
            {
                string errorCode = "";
                errorCode = WMX3Api.ErrorToString(ret);
                //  Global.logger.ErrorFormat("WMX3参数获取失败!错误信息:{0}", errorCode);
                //return false;
            }
            //开始进行通讯
            int wd_count = 0;

            do
            {
                ret = wmx.StartCommunication();//通讯函数
                Thread.Sleep(500);
                wd_count++;
                cmApi.GetStatus(ref status);
            } while ((status.EngineState == EngineState.Communicating) && (wd_count < 10));//确认是否通讯成功

            if (status.EngineState != EngineState.Communicating)
            {
                // string ErrorCode = "";
                // wmx.ErrorToString(ret, ref ErrorCode, 128);
                string errorCode = WMX3Api.ErrorToString(ret); //获取错误代码
                // Global.logger.ErrorFormat("WMX3通讯失败,错误信息:{0}!", errorCode);
                //return false;
            }

            //清除轴警信息
            for (int i = 0; i < 8; i++)
            {
                cmApi.AxisControl.ClearAmpAlarm(i);
                cmApi.AxisControl.ClearAxisAlarm(i);
            }

            //轴上使能
            for (int i = 0; i < 8; i++)
            {
                cmApi.AxisControl.SetServoOn(i, 1);
            }

            //检查所用到的轴有没上使能
            Thread.Sleep(1000);
            cmApi.GetStatus(ref status);
            for (int i = 0; i < 8; i++)
            {
                if (status.AxesStatus[i].ServoOn == false)
                {
                    //使用失败的处理。
                    //    Global.logger.ErrorFormat("WMX3 轴{0}使能失败!", i);
                    //return false;
                }
            }
            //timer1.Interval = 50;
            //timer1.Enabled = true;
            ret = cmApi.Motion.CreateSplineBuffer(5, 1024);
            if (ret != 0)
            {
                //     Global.logger.ErrorFormat("WMX3创建缓存出现错误!错误信息:{0}", WMX3Api.ErrorToString(ret));
            }

            while (bInitOK)
            {
                Thread.Sleep(10);
                GetAllMotionStatus();
                GetAllIOStatus();
            }
        }