private void SetMaskClick(object sender, EventArgs e) { if ((_currentConnectoinContext != null)) { byte mask = 0; foreach (object checkedItem in checkedListBox1.CheckedItems) { if (checkedItem is CardFamilyBindingWrapper) { mask |= (checkedItem as CardFamilyBindingWrapper).Value; } } try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_SetCardsMask(ref portEndpoin, address, mask); if (errorCode != 0) { throw new ApiCallException("Ошибка при установке маски карт", errorCode); } MessageBox.Show(this, "Команда выполнена успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void controlOutSet_Click(object sender, EventArgs e) { try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_SetControlOutputState( ref portEndpoin, address, 1, (byte)(toGround.Checked ? 1 : 0), Convert.ToByte(controlOutTime.Value)); if (errorCode != 0) { throw new ApiCallException("Ошибка при задании состояния контрольного выхода", errorCode); } MessageBox.Show(this, "Команда выполнена успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void SetMaskResetClick(object sender, EventArgs e) { if (_currentConnectoinContext != null) { byte mask = 0; for (int index = 0; index < checkedListBox1.Items.Count; index++) { checkedListBox1.SetItemCheckState(index, CheckState.Unchecked); } try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_SetCardsMask(ref portEndpoin, address, mask); if (errorCode != 0) { throw new ApiCallException("Ошибка при установке маски карт", errorCode); } MessageBox.Show(this, "Команда выполнена успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); DoConnectDisconnect(); } } }
private void ResetProfilesClick(object sender, EventArgs e) { if ((_currentConnectoinContext != null)) { _authorizeCheckBehavior = true; for (int index = 0; index < profilesListBox.Items.Count; index++) { profilesListBox.SetItemCheckState(index, CheckState.Unchecked); } _authorizeCheckBehavior = false; try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_ClearProfiles(ref portEndpoin, address); if (errorCode != 0) { throw new ApiCallException("Ошибка при очистке профилей", errorCode); } MessageBox.Show(this, "Команда выполнена успешно.", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
void AutoPollTimer_Elapsed(object sender, ElapsedEventArgs e) { RG_ENDPOINT portEndpoin = AutoPullDevice.Endpoint; byte address = AutoPullDevice.DeviceInfoShort.DeviceAddress; RG_PIN_SATETS_16 pinStates = new RG_PIN_SATETS_16(); RG_DEVICE_STATUS_TYPE statusType = RG_DEVICE_STATUS_TYPE.DS_UNKNONWN; RG_CARD_INFO cardInfo = new RG_CARD_INFO() { CardType = RG_CARD_TYPE_CODE.CT_UNKNOWN }; RG_CARD_MEMORY cardMemory = new RG_CARD_MEMORY() { ProfileBlock = 0, MemBlock = new byte[16] }; uint errorCode = RG_GetStatus(ref portEndpoin, address, ref statusType, ref pinStates, ref cardInfo, ref cardMemory); if (errorCode != 0 && statusType == RG_DEVICE_STATUS_TYPE.DS_UNKNONWN) { throw new ApplicationException($"Ошибка {errorCode} при запросе статуса устройства"); } var result = new CardStateEventArgs(pinStates, statusType, cardInfo, cardMemory); if (statusType != RG_DEVICE_STATUS_TYPE.DS_NOCARD) { logger.Debug($"Прочитана карта: {result.CardUid}"); } СardStatusRead?.Invoke(this, result); }
private void StartIndicationClick(object sender, EventArgs e) { try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_StartCodogramm( ref portEndpoin, address, Convert.ToByte(priotiryBox.SelectedIndex), enableSound.Checked ? _defaultCodogramms[soundBox.SelectedIndex].Number : (byte)0, enableRed.Checked ? _defaultCodogramms[redBox.SelectedIndex].Number : (byte)0, enableGreen.Checked ? _defaultCodogramms[greenBox.SelectedIndex].Number : (byte)0, enableBlue.Checked ? _defaultCodogramms[blueBox.SelectedIndex].Number : (byte)0); if (errorCode != 0) { throw new ApiCallException("Ошибка при запске схемы индикации", errorCode); } } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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++; } } } }
private void WriteAllPRofiles(object sender, EventArgs e) { if ((_currentConnectoinContext != null)) { _authorizeCheckBehavior = true; for (int index = 0; index < profilesListBox.Items.Count; index++) { profilesListBox.SetItemCheckState(index, CheckState.Checked); } _authorizeCheckBehavior = false; try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_ClearProfiles(ref portEndpoin, address); if (errorCode != 0) { throw new ApiCallException("Ошибка при очистке профилей", errorCode); } RG_PROFILE_DATA apiProfileData = new RG_PROFILE_DATA(); apiProfileData.AccessFlags = 0; apiProfileData.MfKey = new byte[6]; apiProfileData.MfAesKey = new byte[16]; for (int index = 0; index < profilesListBox.Items.Count; index++) { ProfileData localData = _defaultProfiles[index]; var accessFlag = (localData.CryptoOneKeyB ? 1 : 0) | ((localData.AesKeyB ? 1 : 0) << 1); apiProfileData.AccessFlags = Convert.ToByte(accessFlag); Buffer.BlockCopy(localData.CryptoOneKey, 0, apiProfileData.MfKey, 0, apiProfileData.MfKey.Length); Buffer.BlockCopy(localData.AesKey, 0, apiProfileData.MfAesKey, 0, apiProfileData.MfAesKey.Length); errorCode = UnmanagedContext.Instance.RG_WriteProfile(ref portEndpoin, address, Convert.ToByte(index), localData.BlockNumber, ref apiProfileData); if (errorCode != 0) { throw new ApiCallException("Ошибка при записи профиля.", errorCode); } } MessageBox.Show(this, "Команда выполнена успешно.", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
void AutoPollTimer_Elapsed(object sender, ElapsedEventArgs e) { RG_ENDPOINT portEndpoin = AutoPullDevice.Endpoint; byte address = AutoPullDevice.DeviceInfoShort.DeviceAddress; RG_PIN_SATETS_16 pinStates = new RG_PIN_SATETS_16(); RG_DEVICE_STATUS_TYPE statusType = RG_DEVICE_STATUS_TYPE.DS_UNKNONWN; RG_CARD_INFO cardInfo = new RG_CARD_INFO() { CardType = RG_CARD_TYPE_CODE.CT_UNKNOWN }; RG_CARD_MEMORY cardMemory = new RG_CARD_MEMORY() { ProfileBlock = 0, MemBlock = new byte[16] }; if (ticksLeft <= 0) { if (stateNoCard) { stateNoCard = false; if (AutoPullDevice.DeviceInfoShort.DeviceAddress == 0) { random.NextBytes(lastUid); } else if (AutoPullDevice.DeviceInfoShort.DeviceAddress == 1) { NextStepReader1(); } ticksLeft = 10; } else { stateNoCard = true; ticksLeft = 25; } } else { ticksLeft--; } if (stateNoCard) { statusType = RG_DEVICE_STATUS_TYPE.DS_NOCARD; } else { statusType = RG_DEVICE_STATUS_TYPE.DS_CARD; cardInfo.CardUid = lastUid; } var result = new CardStateEventArgs(pinStates, statusType, cardInfo, cardMemory); СardStatusRead?.Invoke(this, result); }
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); } } }
public void StartDevice(DeviceInfo device) { //Записываю Кодограмму RG_ENDPOINT portEndpoin = device.Endpoint; RG_CODOGRAMM codogram = new RG_CODOGRAMM { Length = 32, Body = 0x00000000 }; byte codogramNumber = 1; uint errorCode = RG_WriteCodogramm(ref portEndpoin, device.DeviceInfoShort.DeviceAddress, codogramNumber, ref codogram); if (errorCode != 0) { throw new ApplicationException($"Ошибка при записи кодограммы = {errorCode}"); } }
private void SetCardMask(DeviceInfo device, IList <CardType> cardTypes) { logger.Debug("Устанавливаем маску используемых карт."); byte mask = 0; foreach (var type in cardTypes.Where(x => x.Active)) { mask |= (byte)type.CardTypeFamily; } RG_ENDPOINT portEndpoin = device.Endpoint; byte address = device.DeviceInfoShort.DeviceAddress; uint errorCode = RG_SetCardsMask(ref portEndpoin, address, mask); if (errorCode != 0) { throw new ApplicationException($"Ошибка {errorCode} при установке маски карт"); } }
private void WriteCodogramm(CodogrammData data) { try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; RG_CODOGRAMM codogram = new RG_CODOGRAMM { Length = data.LengthBits, Body = data.CodogrammBody }; uint errorCode = UnmanagedContext.Instance.RG_WriteCodogramm(ref portEndpoin, address, data.Number, ref codogram); if (errorCode != 0) { throw new ApiCallException("Ошибка при записи кодограммы", errorCode); } } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RequestStatusClick(object sender, EventArgs e) { if (_currentConnectoinContext != null) { try { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; RG_PIN_SATETS_16 pinStates = new RG_PIN_SATETS_16(); RG_DEVICE_STATUS_TYPE statusType = RG_DEVICE_STATUS_TYPE.DS_UNKNONWN; RG_CARD_INFO cardInfo = new RG_CARD_INFO() { CardType = RG_CARD_TYPE_CODE.CT_UNKNOWN }; RG_CARD_MEMORY cardMemory = new RG_CARD_MEMORY { ProfileBlock = 0, MemBlock = new byte[16] }; uint errorCode = UnmanagedContext.Instance.RG_GetStatus(ref portEndpoin, address, ref statusType, ref pinStates, ref cardInfo, ref cardMemory); if (errorCode != 0 && statusType == RG_DEVICE_STATUS_TYPE.DS_UNKNONWN) { throw new ApiCallException("Ошибка при запросе статуса устройства", errorCode); } Debug.WriteLine("Тампер: {0} Контрольный выход: {1}", pinStates.Pin00, pinStates.Pin01); cardCodeTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : SystemColors.Control; cardTypeTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : SystemColors.Control; cardUidTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : SystemColors.Control; cardMemoryTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : SystemColors.Control; profileNumBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : SystemColors.Control; switch (statusType) { case RG_DEVICE_STATUS_TYPE.DS_NOCARD: { cardCodeTextBox.Text = ""; cardTypeTextBox.Text = ""; cardUidTextBox.Text = ""; profileNumBox.Text = ""; cardMemoryTextBox.Text = ""; break; } case RG_DEVICE_STATUS_TYPE.DS_CARD: { string enumFieldName = Enum.GetName(typeof(RG_CARD_TYPE_CODE), cardInfo.CardType); string uidField = BitConverter.ToString(cardInfo.CardUid); cardCodeTextBox.Text = ((byte)cardInfo.CardType).ToString("X2"); cardTypeTextBox.Text = enumFieldName; cardUidTextBox.Text = uidField; profileNumBox.Text = ""; cardMemoryTextBox.Text = ""; break; } case RG_DEVICE_STATUS_TYPE.DS_CARDAUTH: { string enumFieldName = Enum.GetName(typeof(RG_CARD_TYPE_CODE), cardInfo.CardType); string uidField = BitConverter.ToString(cardInfo.CardUid); string memoryData = BitConverter.ToString(cardMemory.MemBlock); cardCodeTextBox.Text = ((byte)cardInfo.CardType).ToString("X2"); cardTypeTextBox.Text = enumFieldName; cardUidTextBox.Text = uidField; profileNumBox.Text = cardMemory.ProfileBlock.ToString(); cardMemoryTextBox.Text = memoryData; break; } case RG_DEVICE_STATUS_TYPE.DS_CARDNOAUTH: { string enumFieldName = Enum.GetName(typeof(RG_CARD_TYPE_CODE), cardInfo.CardType); string uidField = BitConverter.ToString(cardInfo.CardUid); cardCodeTextBox.Text = ((byte)cardInfo.CardType).ToString("X2"); cardTypeTextBox.Text = enumFieldName; cardUidTextBox.Text = uidField; profileNumBox.Text = ""; cardMemoryTextBox.Text = string.Format("Ошибка доступа 0x{0:X2}", errorCode - 2000); break; } } } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ReaderConnectionContext(RG_ENDPOINT readerPort, byte readerAddress, RG_DEVICE_INFO_SHORT deviceInfo) { _readerPort = readerPort; _readerAddress = readerAddress; _deviceInfo = deviceInfo; }
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(); }
private void WriteSelectedProfiles(object sender, EventArgs e) { if ((_currentConnectoinContext != null)) { try { if (profilesListBox.CheckedItems.Count > 0) { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; uint errorCode = UnmanagedContext.Instance.RG_ClearProfiles(ref portEndpoin, address); if (errorCode != 0) { throw new ApiCallException("Ошибка при очистке профилей", errorCode); } RG_PROFILE_DATA apiProfileData = new RG_PROFILE_DATA(); apiProfileData.AccessFlags = 0; apiProfileData.MfKey = new byte[6]; apiProfileData.MfAesKey = new byte[16]; byte profileIndex = 0; byte[] accesFlagsStorage = new byte[1]; foreach (var checkedProfile in profilesListBox.CheckedItems) { ProfileData localData = checkedProfile as ProfileData; BitArray accessFlagsArray = new BitArray(8); switch (localData.ProfileType) { case ProfileType.Mifare: accessFlagsArray.Set(0, localData.CryptoOneKeyB); accessFlagsArray.Set(1, localData.AesKeyB); accessFlagsArray.Set(5, false); accessFlagsArray.Set(6, false); break; case ProfileType.AppleGooglePay: case ProfileType.MobileAccess: accessFlagsArray.Set(0, localData.KeyBitGenerated); accessFlagsArray.Set(1, localData.KeyBitDirect); accessFlagsArray.Set(2, localData.KeyBitEmited); accessFlagsArray.Set(5, localData.ProfileType == ProfileType.AppleGooglePay); accessFlagsArray.Set(6, localData.ProfileType != ProfileType.AppleGooglePay); break; } accessFlagsArray.CopyTo(accesFlagsStorage, 0); apiProfileData.AccessFlags = accesFlagsStorage[0]; Buffer.BlockCopy(localData.CryptoOneKey, 0, apiProfileData.MfKey, 0, apiProfileData.MfKey.Length); Buffer.BlockCopy(localData.AesKey, 0, apiProfileData.MfAesKey, 0, apiProfileData.MfAesKey.Length); errorCode = UnmanagedContext.Instance.RG_WriteProfile(ref portEndpoin, address, profileIndex++, localData.BlockNumber, ref apiProfileData); if (errorCode != 0) { throw new ApiCallException("Ошибка при записи профиля.", errorCode); } } MessageBox.Show(this, "Команда выполнена успешно.", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(this, string.Format("({1}) {0}", ex.Message, (ex is ApiCallException) ? (ex as ApiCallException).ApiCallErrorCode.ToString() : "..."), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void poll(Action completeCallback) { try { while (!_pollStopEvent.WaitOne(200)) { if (_currentConnectoinContext != null) { RG_ENDPOINT portEndpoin = _currentConnectoinContext.ReaderPort; byte address = _currentConnectoinContext.ReaderAddress; RG_PIN_SATETS_16 pinStates = new RG_PIN_SATETS_16(); RG_DEVICE_STATUS_TYPE statusType = RG_DEVICE_STATUS_TYPE.DS_UNKNONWN; RG_CARD_INFO cardInfo = new RG_CARD_INFO() { CardType = RG_CARD_TYPE_CODE.CT_UNKNOWN }; RG_CARD_MEMORY cardMemory = new RG_CARD_MEMORY() { ProfileBlock = 0, MemBlock = new byte[16] }; uint errorCode = UnmanagedContext.Instance.RG_GetStatus(ref portEndpoin, address, ref statusType, ref pinStates, ref cardInfo, ref cardMemory); if (errorCode != 0 && statusType == RG_DEVICE_STATUS_TYPE.DS_UNKNONWN) { throw new ApiCallException("Ошибка при запросе статуса устройства", errorCode); } Debug.WriteLine("Тампер: {0} Контрольный выход: {1}", pinStates.Pin00, pinStates.Pin01); readerDataGroup.InvokeIfRequired(() => { cardCodeTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : Color.LightGreen; cardTypeTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : Color.LightGreen; cardUidTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : Color.LightGreen; cardMemoryTextBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : Color.LightGreen; profileNumBox.BackColor = pinStates.Pin00 ? Color.DarkSalmon : Color.LightGreen; }); switch (statusType) { case RG_DEVICE_STATUS_TYPE.DS_NOCARD: { readerDataGroup.InvokeIfRequired(() => { cardCodeTextBox.Text = ""; cardTypeTextBox.Text = ""; cardUidTextBox.Text = ""; profileNumBox.Text = ""; cardMemoryTextBox.Text = ""; }); break; } case RG_DEVICE_STATUS_TYPE.DS_CARD: { string enumFieldName = Enum.GetName(typeof(RG_CARD_TYPE_CODE), cardInfo.CardType); string uidField = BitConverter.ToString(cardInfo.CardUid); readerDataGroup.InvokeIfRequired(() => { cardCodeTextBox.Text = ((byte)cardInfo.CardType).ToString("X2"); cardTypeTextBox.Text = enumFieldName; cardUidTextBox.Text = uidField; profileNumBox.Text = ""; cardMemoryTextBox.Text = ""; }); break; } case RG_DEVICE_STATUS_TYPE.DS_CARDAUTH: { string enumFieldName = Enum.GetName(typeof(RG_CARD_TYPE_CODE), cardInfo.CardType); string uidField = BitConverter.ToString(cardInfo.CardUid); string memoryData = BitConverter.ToString(cardMemory.MemBlock); readerDataGroup.InvokeIfRequired(() => { cardCodeTextBox.Text = ((byte)cardInfo.CardType).ToString("X2"); cardTypeTextBox.Text = enumFieldName; cardUidTextBox.Text = uidField; profileNumBox.Text = cardMemory.ProfileBlock.ToString(); cardMemoryTextBox.Text = memoryData; }); break; } case RG_DEVICE_STATUS_TYPE.DS_CARDNOAUTH: { string enumFieldName = Enum.GetName(typeof(RG_CARD_TYPE_CODE), cardInfo.CardType); string uidField = BitConverter.ToString(cardInfo.CardUid); readerDataGroup.InvokeIfRequired(() => { cardCodeTextBox.Text = ((byte)cardInfo.CardType).ToString("X2"); cardTypeTextBox.Text = enumFieldName; cardUidTextBox.Text = uidField; profileNumBox.Text = ""; cardMemoryTextBox.Text = string.Format("Ошибка доступа 0x{0:X2}", errorCode - 2000); }); break; } default: break; } } else { break; } } } finally { if (completeCallback != null) { try { completeCallback(); } catch { } } } }