Exemplo n.º 1
0
 private void UpdateDevicesOnPort()
 {
     _availableDevices.Clear();
     if (connectionsBox.SelectedIndex >= 0)
     {
         PortInfoBindingWrapper wrapper = connectionsBox.SelectedItem as PortInfoBindingWrapper;
         if (wrapper != null)
         {
             RG_ENDPOINT endpoint = new RG_ENDPOINT();
             endpoint.Type    = wrapper.PortType;
             endpoint.Address = wrapper.ConnectionString;
             byte currentDeviceAddress = 0;
             while (currentDeviceAddress < 4)
             {
                 uint errorCode = UnmanagedContext.Instance.RG_InitDevice(ref endpoint, currentDeviceAddress);
                 if (errorCode == 0)
                 {
                     RG_DEVICE_INFO_SHORT deviceInfo = new RG_DEVICE_INFO_SHORT();
                     if (UnmanagedContext.Instance.RG_GetInfo(ref endpoint, currentDeviceAddress,
                                                              ref deviceInfo) == 0)
                     {
                         _availableDevices.Add(new DeviceInfoBindingWrapper(deviceInfo));
                     }
                 }
                 currentDeviceAddress++;
             }
         }
     }
 }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        private void DoConnectDisconnect()
        {
            // если не подключены
            if (_currentConnectoinContext == null)
            {
                UpdateConnectBlock(false);
                try {
                    RG_ENDPOINT portEndpoint = new RG_ENDPOINT();
                    portEndpoint.Type    = _currentEndpointType;
                    portEndpoint.Address = _currentConenctionString;

                    uint errorCcode = UnmanagedContext.Instance.RG_InitDevice(ref portEndpoint, _currentReaderAddress);
                    if (errorCcode != 0)
                    {
                        logger.Error($"Error in RG_InitDevice = {errorCcode}");
                        throw new ApiCallException("Ошибка при подключении к устройству", errorCcode);
                    }
                    logger.Debug("Устройство проинициализировано");

                    RG_DEVICE_INFO_SHORT deviceInfo = new RG_DEVICE_INFO_SHORT();
                    errorCcode =
                        UnmanagedContext.Instance.RG_GetInfo(ref portEndpoint, _currentReaderAddress,
                                                             ref deviceInfo);
                    if (errorCcode != 0)
                    {
                        logger.Error($"Error in RG_GetInfo = {errorCcode}");
                        throw new ApiCallException("Ошибка при запросе данных устройства", errorCcode);
                    }

                    logger.Debug("Устройство опрошено");

                    _currentConnectoinContext =
                        new ReaderConnectionContext(portEndpoint, _currentReaderAddress, deviceInfo);

                    foreach (CodogrammData defaultCodogramm in _defaultCodogramms)
                    {
                        logger.Debug($"Пишем кодограмму {defaultCodogramm.Name}");
                        try {
                            WriteCodogramm(defaultCodogramm);
                        }
                        catch (Exception ex) {
                            MessageBox.Show(this,
                                            string.Format("({1}) {0}", ex.Message,
                                                          (ex is ApiCallException)
                                        ? (ex as ApiCallException).ApiCallErrorCode.ToString()
                                        : "..."),
                                            "Ошибка",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                catch (Exception ex) {
                    MessageBox.Show(this,
                                    string.Format("({1}) {0}", ex.Message,
                                                  (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."),
                                    "Ошибка",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                _pollStopEvent.Set();
                _currentConnectoinContext = null;
            }

            UpdateConnectBlock(true);
            EnableDisableReaderDataGroup();
        }
Exemplo n.º 4
0
 public ReaderConnectionContext(RG_ENDPOINT readerPort, byte readerAddress, RG_DEVICE_INFO_SHORT deviceInfo)
 {
     _readerPort    = readerPort;
     _readerAddress = readerAddress;
     _deviceInfo    = deviceInfo;
 }
Exemplo n.º 5
0
 public DeviceInfo(RG_ENDPOINT_INFO endpointInfo, RG_DEVICE_INFO_SHORT deviceInfoShort)
 {
     this.EndpointInfo    = endpointInfo;
     this.DeviceInfoShort = deviceInfoShort;
 }