public static string action2str(CARD_ACTION action)
        {
            IntPtr str_ret = dbg_action2str(action);

            return(Marshal.PtrToStringAnsi(str_ret));
        }
Exemplo n.º 2
0
        private void MessageCallBack(IDTechSDK.IDT_DEVICE_Types type, DeviceState state, byte[] data, IDTTransactionData cardData, EMV_Callback emvCallback, RETURN_CODE transactionResultCode)
        {
            // Setup Connection
            IDTechComm comm = Profile.getComm(type, DEVICE_INTERFACE_Types.DEVICE_INTERFACE_USB);

            if (comm == null)
            {
                comm = Profile.getComm(type, DEVICE_INTERFACE_Types.DEVICE_INTERFACE_SERIAL);
            }

            if (comm == null)
            {
                comm = Profile.getComm(type, DEVICE_INTERFACE_Types.DEVICE_INTERFACE_BT);
            }

            if (comm == null)
            {
                comm = Profile.getComm(type, DEVICE_INTERFACE_Types.DEVICE_INTERFACE_AUDIO_JACK);
            }

            deviceConnect  = DEVICE_INTERFACE_Types.DEVICE_INTERFACE_UNKNOWN;
            deviceProtocol = DEVICE_PROTOCOL_Types.DEVICE_PROTOCOL_UNKNOWN;

            if (comm != null)
            {
                deviceConnect  = comm.getDeviceConnection();
                deviceProtocol = comm.getDeviceProtocol();
            }

            //Debug.WriteLine("DeviceCfg::MessageCallBack: device discovery: state={0}", state);

            switch (state)
            {
            case DeviceState.ToConnect:
            {
                deviceType = type;
                Debug.WriteLine("device connecting: {0}", (object)deviceType.ToString());
                break;
            }

            case DeviceState.Connected:
            {
                deviceType = type;
                Debug.WriteLine("device connected: {0}", (object)IDTechSDK.Profile.IDT_DEVICE_String(type, deviceConnect));

                // Populate Device Configuration
                if (!connected && !firmwareUpdate)
                {
                    new Thread(() =>
                        {
                            Thread.CurrentThread.IsBackground = false;
                            connected = true;

                            // Get Device Configuration
                            SetDeviceConfig();

                            Thread.Sleep(100);

                            // Get Device Information
                            GetDeviceInformation();
                        }).Start();
                }

                break;
            }

            case DeviceState.Disconnected:
            {
                if (!firmwareUpdate)
                {
                    connected = false;
                    DeviceRemovedHandler();
                }
                break;
            }

            case DeviceState.DefaultDeviceTypeChange:
            {
                break;
            }

            case DeviceState.Notification:
            {
                if (cardData.Notification == EVENT_NOTIFICATION_Types.EVENT_NOTIFICATION_Card_Not_Seated)
                {
                    Debug.WriteLine("Notification: ICC Card not Seated\n");
                }
                if (cardData.Notification == EVENT_NOTIFICATION_Types.EVENT_NOTIFICATION_Card_Seated)
                {
                    Debug.WriteLine("Notification: ICC Card Seated\n");
                }
                if (cardData.Notification == EVENT_NOTIFICATION_Types.EVENT_NOTIFICATION_Swipe_Card)
                {
                    Debug.WriteLine("Notification: MSR Swipe Card\n");
                }

                break;
            }

            case DeviceState.TransactionData:
            {
                if (cardData == null)
                {
                    break;
                }

                //lastCardData = cardData;

                if (type == IDT_DEVICE_Types.IDT_DEVICE_AUGUSTA && deviceProtocol == DEVICE_PROTOCOL_Types.DEVICE_PROTOCOL_KB)
                {
                    if (cardData.msr_rawData != null)
                    {
                        if (cardData.msr_rawData.Length == 1 && cardData.msr_rawData[0] == 0x18)
                        {
                            Debug.WriteLine("Get MSR Complete! \n");
                            Debug.WriteLine("Get MSR Complete! \n");
                        }
                    }

                    //clearCallbackData(ref data, ref cardData);

                    return;
                }

                if (cardData.Event != EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_PIN_DATA &&
                    cardData.Event != EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_DATA_CARD_DATA &&
                    cardData.Event != EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_DATA_EMV_DATA)
                {
                    //SoftwareController.MSR_LED_RED_SOLID();
                    Debug.WriteLine("MSR Error " + cardData.msr_errorCode.ToString() + "\n");
                    Debug.WriteLine("MSR Error " + cardData.msr_errorCode.ToString());
                }
                else
                {
                    if (cardData.Event != EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_DATA_EMV_DATA)
                    {
                        //SoftwareController.MSR_LED_GREEN_SOLID();
                    }

                    //output parsed card data
                    Debug.WriteLine("Return Code: " + transactionResultCode.ToString() + "\r\n");

                    // Data Received Processing
                    ///ProcessCardData(cardData);
                }

                break;
            }

            case DeviceState.DataReceived:
            {
                //SetOutputTextLog(GetTimestamp() +  " IN: " + Common.getHexStringFromBytes(data));
                break;
            }

            case DeviceState.DataSent:
            {
                //SetOutputTextLog(GetTimestamp() + " OUT: " + Common.getHexStringFromBytes(data));
                break;
            }

            case DeviceState.CommandTimeout:
            {
                Debug.WriteLine("Command Timeout\n");
                break;
            }

            case DeviceState.CardAction:
            {
                if (data != null & data.Length > 0)
                {
                    CARD_ACTION   action = (CARD_ACTION)data[0];
                    StringBuilder sb     = new StringBuilder("Card Action Request: ");

                    if ((action & CARD_ACTION.CARD_ACTION_INSERT) == CARD_ACTION.CARD_ACTION_INSERT)
                    {
                        sb.Append("INSERT ");
                    }

                    if ((action & CARD_ACTION.CARD_ACTION_REINSERT) == CARD_ACTION.CARD_ACTION_REINSERT)
                    {
                        sb.Append("REINSERT ");
                    }

                    if ((action & CARD_ACTION.CARD_ACTION_REMOVE) == CARD_ACTION.CARD_ACTION_REMOVE)
                    {
                        sb.Append("REMOVE ");
                    }

                    if ((action & CARD_ACTION.CARD_ACTION_SWIPE) == CARD_ACTION.CARD_ACTION_SWIPE)
                    {
                        sb.Append("SWIPE ");
                    }

                    if ((action & CARD_ACTION.CARD_ACTION_SWIPE_AGAIN) == CARD_ACTION.CARD_ACTION_SWIPE_AGAIN)
                    {
                        sb.Append("SWIPE_AGAIN ");
                    }

                    if ((action & CARD_ACTION.CARD_ACTION_TAP) == CARD_ACTION.CARD_ACTION_TAP)
                    {
                        sb.Append("TAP ");
                    }

                    if ((action & CARD_ACTION.CARD_ACTION_TAP_AGAIN) == CARD_ACTION.CARD_ACTION_TAP_AGAIN)
                    {
                        sb.Append("TAP_AGAIN ");
                    }

                    Debug.WriteLine(sb.ToString() + "\n");
                }

                break;
            }

            case DeviceState.MSRDecodeError:
            {
                //SoftwareController.MSR_LED_RED_SOLID();
                Debug.WriteLine("MSR Decode Error\n");
                break;
            }

            case DeviceState.SwipeTimeout:
            {
                Debug.WriteLine("Swipe Timeout\n");
                break;
            }

            case DeviceState.TransactionCancelled:
            {
                Debug.WriteLine("TransactionCancelled.");
                //Debug.WriteLine("");
                //Debug.WriteLine(DeviceTerminalInfo.getDisplayMessage(DeviceTerminalInfo.MSC_ID_WELCOME));
                break;
            }

            case DeviceState.DeviceTimeout:
            {
                Debug.WriteLine("Device Timeout\n");
                break;
            }

            case DeviceState.TransactionFailed:
            {
                if ((int)transactionResultCode == 0x8300)
                {
                    //SoftwareController.MSR_LED_RED_SOLID();
                }

                string text = IDTechSDK.errorCode.getErrorString(transactionResultCode);
                Debug.WriteLine("Transaction Failed: {0}\r\n", (object)text);

                // Allow for GUI Recovery
                string [] message = { "" };
                message[0] = "***** TRANSACTION FAILED: " + text + " *****";
                NotificationRaise(new DeviceNotificationEventArgs {
                        NotificationType = NOTIFICATION_TYPE.NT_PROCESS_CARDDATA_ERROR, Message = message
                    });
                break;
            }

            case DeviceState.FirmwareUpdate:
            {
                switch (transactionResultCode)
                {
                case RETURN_CODE.RETURN_CODE_FW_STARTING_UPDATE:
                {
                    string [] message = { "STARTING FIRMWARE UPDATE...." };
                    Logger.debug("device: {0}", (object)message[0]);
                    NotificationRaise(new DeviceNotificationEventArgs {
                                NotificationType = NOTIFICATION_TYPE.NT_FIRMWARE_UPDATE_STATUS, Message = message
                            });
                    break;
                }

                case RETURN_CODE.RETURN_CODE_DO_SUCCESS:
                {
                    string [] message = { "FIRMWARE UPDATE SUCCESSFUL" };
                    Logger.debug("device: {0}", (object)message[0]);
                    NotificationRaise(new DeviceNotificationEventArgs {
                                NotificationType = NOTIFICATION_TYPE.NT_FIRMWARE_UPDATE_STATUS, Message = message
                            });

                    new Thread(() =>
                            {
                                Thread.CurrentThread.IsBackground = false;
                                firmwareUpdate = false;

                                // Get Device Configuration
                                SetDeviceFirmwareVersion();
                            }).Start();

                    break;
                }

                case RETURN_CODE.RETURN_CODE_APPLYING_FIRMWARE_UPDATE:
                {
                    string [] message = { "APPLYING FIRMWARE UPDATE...." };
                    Logger.debug("device: {0}", (object)message[0]);
                    NotificationRaise(new DeviceNotificationEventArgs {
                                NotificationType = NOTIFICATION_TYPE.NT_FIRMWARE_UPDATE_STATUS, Message = message
                            });
                    break;
                }

                case RETURN_CODE.RETURN_CODE_ENTERING_BOOTLOADER_MODE:
                {
                    Logger.debug("device: entering Bootloader Mode....");
                    break;
                }

                case RETURN_CODE.RETURN_CODE_BLOCK_TRANSFER_SUCCESS:
                {
                    int start = data[0];
                    int end   = data[1];
                    if (data.Length == 4)
                    {
                        start = data[0] * 0x100 + data[1];
                        end   = data[2] * 0x100 + data[3];
                    }
                    Logger.debug("device: sent block {0} of {1}", start.ToString(), end.ToString());
                    string [] message = { start.ToString() };
                    NotificationRaise(new DeviceNotificationEventArgs {
                                NotificationType = NOTIFICATION_TYPE.NT_FIRMWARE_UPDATE_STEP, Message = message
                            });
                    break;
                }

                default:
                {
                    Logger.debug("device: firmware Update Error Code: 0x{0:X} : {1}", (ushort)transactionResultCode, IDTechSDK.errorCode.getErrorString(transactionResultCode));
                    break;
                }
                }
                break;
            }
            }
        }
 private static extern IntPtr dbg_action2str(CARD_ACTION action);