Пример #1
0
        public static SafeFileHandle GetComPortHandle(string name, FileAccess access, ShareMode shareMode, uint readTimeout, uint writeTimeout)
        {
            string         fileName = String.Format(@"\\.\{0}", name);
            SafeFileHandle handle   = HandleUtils.GetFileHandle(fileName, access, shareMode);

            if (!handle.IsInvalid)
            {
                SetCommTimeouts(handle, readTimeout, writeTimeout);
            }
            return(handle);
        }
Пример #2
0
        public static List <int> GetPhysicalDiskIndexList()
        {
            List <string> devicePathList = DeviceInterfaceUtils.GetDevicePathList(DeviceInterfaceUtils.DiskClassGuid);
            List <int>    result         = new List <int>();

            foreach (string devicePath in devicePathList)
            {
                SafeFileHandle        hDevice = HandleUtils.GetFileHandle(devicePath, FileAccess.Read, ShareMode.ReadWrite);
                STORAGE_DEVICE_NUMBER number  = GetDeviceNumber(hDevice);
                hDevice.Close();
                result.Add((int)number.DeviceNumber);
            }
            // We'll now sort the list based on disk number
            result.Sort();
            return(result);
        }
Пример #3
0
        public static SafeFileHandle GetComPortHandle(int portIndex, FileAccess access, ShareMode shareMode)
        {
            string fileName = String.Format(@"\\.\COM{0}", portIndex);

            return(HandleUtils.GetFileHandle(fileName, access, shareMode));
        }
Пример #4
0
 public SPTITarget(string path, bool emulateReportLUNs)
 {
     m_path              = path;
     m_handle            = HandleUtils.GetFileHandle(m_path, FileAccess.ReadWrite, ShareMode.None);
     m_emulateReportLUNs = emulateReportLUNs;
 }