Пример #1
0
        public void RefreshDevices()
        {
            Devices.Clear();
            IntPtr endPointsListHandle = IntPtr.Zero;
            uint   endpointsCount      = 0;
            bool   findUsbFlag         = true;
            bool   findHidFlag         = true;
            byte   endPointsMask       = (byte)(0 | (findUsbFlag ? 1 : 0) | (findHidFlag ? 2 : 0));

            if (endPointsMask > 0)
            {
                uint errorCode =
                    RG_FindEndPoints(ref endPointsListHandle, endPointsMask, ref endpointsCount);
                if (errorCode != 0)
                {
                    throw new ApplicationException($"Ошибка {errorCode} при вызове RG_FindEndPoints");
                }

                if (endPointsListHandle != IntPtr.Zero)
                {
                    RG_ENDPOINT_INFO portInfo  = new RG_ENDPOINT_INFO();
                    uint             portIndex = 0;
                    while (RG_GetFoundEndPointInfo(endPointsListHandle, portIndex, ref portInfo) == 0)
                    {
                        //Считываем все устройство на точке подключения
                        RG_ENDPOINT endpoint = new RG_ENDPOINT();
                        endpoint.Type    = portInfo.PortType;
                        endpoint.Address = portInfo.Address;
                        byte currentDeviceAddress = 0;
                        while (currentDeviceAddress < 4)
                        {
                            errorCode = RG_InitDevice(ref endpoint, currentDeviceAddress);
                            if (errorCode == 0)
                            {
                                RG_DEVICE_INFO_SHORT deviceInfo = new RG_DEVICE_INFO_SHORT();
                                if (RG_GetInfo(ref endpoint, currentDeviceAddress, ref deviceInfo) == 0)
                                {
                                    Devices.Add(new DeviceInfo(portInfo, deviceInfo));
                                }
                            }
                            currentDeviceAddress++;
                        }
                        portIndex++;
                    }
                    RG_CloseResource(endPointsListHandle);
                }
            }
        }
Пример #2
0
        private void UpdatePortList(bool findUsbFlag, bool findHidFlag)
        {
            groupBox1.Enabled = false;

            _availablePorts.Clear();
            try {
                IntPtr endPointsListHandle = IntPtr.Zero;
                uint   endpointsCount      = 0;
                byte   endPointsMask       = (byte)(0 | (findUsbFlag ? 1 : 0) | (findHidFlag ? 2 : 0));
                if (endPointsMask > 0)
                {
                    uint errorCode =
                        UnmanagedContext.Instance.RG_FindEndPoints(ref endPointsListHandle, endPointsMask, ref endpointsCount);
                    if (errorCode != 0)
                    {
                        throw new ApiCallException("Ошибка при вызове RG_FindEndPoints", errorCode);
                    }

                    if (endPointsListHandle != IntPtr.Zero)
                    {
                        RG_ENDPOINT_INFO portInfo  = new RG_ENDPOINT_INFO();
                        uint             portIndex = 0;
                        while (UnmanagedContext.Instance.RG_GetFoundEndPointInfo(endPointsListHandle, portIndex, ref portInfo) == 0)
                        {
                            _availablePorts.Add(new PortInfoBindingWrapper(portInfo));
                            portIndex++;
                        }

                        UnmanagedContext.Instance.RG_CloseResource(endPointsListHandle);
                    }
                }
            }
            catch (ApiCallException ex) {
                MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, ex.ApiCallErrorCode), "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            connectionsBox.SelectedIndex = -1;

            groupBox1.Enabled = true;
        }
Пример #3
0
 public DeviceInfo(RG_ENDPOINT_INFO endpointInfo, RG_DEVICE_INFO_SHORT deviceInfoShort)
 {
     this.EndpointInfo    = endpointInfo;
     this.DeviceInfoShort = deviceInfoShort;
 }