IDTech Windows SDK Guide  1.2.35.0
API reference for SpectrumPro
Sample Project Tutorial

Using Visual Studio 2015, we will create a C# sample project that will interface with the SpectrumPro and will perform the following activities:

  • Select USB or COM interface
  • Set UID and report device info
  • Display ICC Status (card inserted/removed, ICC power on/off)
  • Turn on/off ICC reader
  • Get/Set terminal data file
  • Get/Set AID for Visa
  • Get/Set CAPKs for Visa
  • Perform EMV Transaction
  • Start/Stop a Swipe Request
  • Show log of all data going to/from SpectrumPro

Step 1: Create New Project

Create a new Windows Form Application in Visual Studio. In our example, we use project name SpectrumPro_Simple_Demo

newProject.png

Step 2: Import Libraries

Import the necessary libraries

Step 3: Design Interface

Use the Form Designer to layout buttons/fields
Open your form designer and add items so it contains the following buttons/fields:

  • Radio buttons for USB and COM selection. For COM selection, add a text box to specify COM port
  • Add buttons to execute the following functions:
    • Set UID
    • Show ICC Status
    • Turn ON ICC Reader
    • Turn OFF ICC Reader
    • Set Terminal Data
    • Get Terminal Data
    • Set Visa AID
    • Get Visa AID
    • Set Visa CAPKs
    • List All CAPKs
    • Start EMV Transaction
    • Cancel EMV Transaction
    • Start Swipe
    • Cancel Swipe
  • Add a text box to communicate data from the SpectrumPro.
  • Add a text box for the log of SpectrumPro.
form.png

Step 4: Configure the project file

In the start of the class file, perform the following:

  • Add using statements to utilize library
  • set callback method and initialize SpectrumPro singleton object in the class initializer. Reference: Initialize SpectrumPro
  • Implement the button methods Click handlers for button press code execution
    private void btnFirmwareVersion_Click(object sender, EventArgs e)
    {
    SpectrumInfo info = new SpectrumInfo();
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.device_setUID(IDT_Device.Spectrum_UID, 2, ref info);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("UID set Successful\r\nFirmware: " + info.firmwareVersion + "\r\nApplication: " + info.applicationVersion + "\r\nMSR: " + info.msrHead + "\r\nHardware: " + info.hardwareVersion + "\r\nSerial Number: " + info.serialNumber + "\r\nKey Mode: " + info.keyType.ToString() + "\r\n");
    }
    else
    {
    tbOutput.AppendText("UID set failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnStartEMVTransaction_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_startTransaction(1.00, 0,2, 0, 30, null, false);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Start EMV Successful\r\n");
    }
    else
    {
    tbOutput.AppendText("Start EMV failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnCancelEMVTransaction_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_cancelTransaction();
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Cancel Transaction Successful\r\n");
    System.Diagnostics.Debug.WriteLine("Cancel Transaction Successful");
    }
    else
    {
    tbOutput.AppendText("Cancel Transaction failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    System.Diagnostics.Debug.WriteLine("Cancel Transaction failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt));
    }
    }
    private void btnSetTerminalData_Click(object sender, EventArgs e)
    {
    byte[] term = Common.getByteArray("5f3601029f1a0208409f3501229f330360f8c89f4005f00000a0019f1e085465726d696e616c9f150212349f160f3030303030303030303030303030309f1c0838373635343332319f4e2231303732312057616c6b65722053742e20437970726573732c204341202c5553412edf260101df1008656e667265737a68df110101df270100dfee150101dfee160100dfee170107dfee180180dfee1e08f0dc3cf0c29e9400dfee1f0180dfee1b083030303135313030dfee20013cdfee21010adfee2203323c3c");
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_setTerminalData(term);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Set Terminal Successful:" + " \r\n");
    }
    else
    {
    tbOutput.AppendText("Save Terminal failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnGetTerminalData_Click(object sender, EventArgs e)
    {
    byte[] tlv = null;
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_retrieveTerminalData(ref tlv);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Retrieve Terminal Successful- TLV: " + " \r\n" + Common.getHexStringFromBytes(tlv) + "\r\n");
    }
    else
    {
    tbOutput.AppendText("Retrieve Terminal failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnSetVisaAid_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt;
    byte[] name = Common.getByteArray("a0000000031010");
    byte[] aid = Common.getByteArray("9f01065649534130305f5701005f2a0208409f090200965f3601029f1b0400003a98df25039f3704df28039f0802dfee150101df13050000000000df14050000000000df15050000000000df180100df170400002710df190100");
    rt = IDT_SpectrumPro.SharedController.emv_setApplicationData(name, aid);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Default AID Successful\r\n");
    }
    else
    {
    tbOutput.AppendText("Default AID failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnGetVisaAid_Click(object sender, EventArgs e)
    {
    byte[] tlv = null;
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_retrieveApplicationData(Common.getByteArray("a0000000031010"), ref tlv);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Retrieve AID Successful- TLV: " + " \r\n" + Common.getHexStringFromBytes(tlv) + " \r\n");
    }
    else
    {
    tbOutput.AppendText("Retrieve AID failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    System.Diagnostics.Debug.WriteLine("Retrieve AID failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt));
    }
    }
    private void btnSetVisaCAPKs_Click(object sender, EventArgs e)
    {
    byte[] capk = Common.getByteArray("a000000003500101b769775668cacb5d22a647d1d993141edab7237b000100018000d11197590057b84196c2f4d11a8f3c05408f422a35d702f90106ea5b019bb28ae607aa9cdebcd0d81a38d48c7ebb0062d287369ec0c42124246ac30d80cd602ab7238d51084ded4698162c59d25eac1e66255b4db2352526ef0982c3b8ad3d1cce85b01db5788e75e09f44be7361366def9d1e1317b05e5d0ff5290f88a0db47");
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    capk = Common.getByteArray("a000000003510101b9d248075a3f23b522fe45573e04374dc4995d71000000039000db5fa29d1fda8c1634b04dccff148abee63c772035c79851d3512107586e02a917f7c7e885e7c4a7d529710a145334ce67dc412cb1597b77aa2543b98d19cf2cb80c522bdbea0f1b113fa2c86216c8c610a2d58f29cf3355ceb1bd3ef410d1edd1f7ae0f16897979de28c6ef293e0a19282bd1d793f1331523fc71a228800468c01a3653d14c6b4851a5c029478e757f");
    rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    capk = Common.getByteArray("a000000003530101ac213a2e0d2c0ca35ad0201323536d58097e4e5700000003f800bcd83721be52cccc4b6457321f22a7dc769f54eb8025913be804d9eabbfa19b3d7c5d3ca658d768caf57067eec83c7e6e9f81d0586703ed9dddadd20675d63424980b10eb364e81eb37db40ed100344c928886ff4ccc37203ee6106d5b59d1ac102e2cd2d7ac17f4d96c398e5fd993ecb4ffdf79b17547ff9fa2aa8eefd6cbda124cbb17a0f8528146387135e226b005a474b9062ff264d2ff8efa36814aa2950065b1b04c0a1ae9b2f69d4a4aa979d6ce95fee9485ed0a03aee9bd953e81cfd1ef6e814dfd3c2ce37aefa38c1f9877371e91d6a5eb59fdedf75d3325fa3ca66cdfba0e57146cc789818ff06be5fcc50abd362ae4b80996d");
    rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    capk = Common.getByteArray("a0000000039601017616e9ac8be014af88ca11a8fb17967b7394030e000000038000b74586d19a207be6627c5b0aafbc44a2ecf5a2942d3a26ce19c4ffaeee920521868922e893e7838225a3947a2614796fb2c0628ce8c11e3825a56d3b1bbaef783a5c6a81f36f8625395126fa983c5216d3166d48acde8a431212ff763a7f79d9edb7fed76b485de45beb829a3d4730848a366d3324c3027032ff8d16a1e44d8d");
    rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    capk = Common.getByteArray("a000000003570101251a5f5de61cf28b5c6e2b5807c0644a01d46ff5000100016000942b7f2ba5ea307312b63df77c5243618acc2002bd7ecb74d821fe7bdc78bf28f49f74190ad9b23b9713b140ffec1fb429d93f56bdc7ade4ac075d75532c1e590b21874c7952f29b8c0f0c1ce3aeedc8da25343123e71dcf86c6998e15f756e3");
    rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    capk = Common.getByteArray("a000000003580101753ed0aa23e4cd5abd69eae7904b684a34a57c2200010001c80099552c4a1ecd68a0260157fc4151b5992837445d3fc57365ca5692c87be358cdcdf2c92fb6837522842a48eb11cdffe2fd91770c7221e4af6207c2de4004c7dee1b6276dc62d52a87d2cd01fbf2dc4065db52824d2a2167a06d19e6a0f781071cdb2dd314cb94441d8dc0e936317b77bf06f5177f6c5aba3a3bc6aa30209c97260b7a1ad3a192c9b8cd1d153570afcc87c3cd681d13e997fe33b3963a0a1c79772acf991033e1b8397ad0341500e48a24770bc4cbe19d2ccf419504fdbf0389bc2f2fdcd4d44e61f");
    rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    capk = Common.getByteArray("a00000000354010106960618791a86d387301edd4a3baf2d34fef1b400010001f800c6ddc0b7645f7f16286ab7e4116655f56dd0c944766040dc68664dd973bd3bfd4c525bcbb95272b6b3ad9ba8860303ad08d9e8cc344a4070f4cfb9eeaf29c8a3460850c264cda39bbe3a7e7d08a69c31b5c8dd9f94ddbc9265758c0e7399adcf4362caee458d414c52b498274881b196dacca7273f687f2a65faeb809d4b2ac1d3d1efb4f6490322318bd296d153b307a3283ab4e5be6ebd910359a8565eb9c4360d24baaca3dbfe393f3d6c830d603c6fc1e83409dfcd80d3a33ba243813bbb4ceaf9cbab6b74b00116f72ab278a88a011d70071e06cab140646438d986d48281624b85b3b2ebb9a6ab3bf2178fcc3011e7caf24897ae7d");
    rt = IDT_SpectrumPro.SharedController.emv_setCAPK(capk);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Load Visa CAPK Successful:" + " \r\n");
    }
    else
    {
    tbOutput.AppendText("Load Visa CAPK failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnListCAPKs_Click(object sender, EventArgs e)
    {
    byte[] capk = null;
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_retrieveCAPKList(ref capk);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("List CAPK Successful \r\n");
    if (capk.Length > 0)
    {
    for (int x = 0; x < capk.Length; x = x + 6)
    {
    byte[] thecapk = new byte[] { capk[x], capk[x + 1], capk[x + 2], capk[x + 3], capk[x + 4], capk[x + 5] };
    tbOutput.AppendText(Common.getHexStringFromBytes(thecapk) + " \r\n");
    }
    }
    }
    else
    {
    tbOutput.AppendText("List CAPK failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnStartSwipe_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.msr_startMSRSwipe(60);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("MSR Turned On successfully; Ready to swipe\r\n");
    tbOutput.ReadOnly = false;
    tbOutput.Focus();
    }
    else
    {
    tbOutput.AppendText("MSR Turned On failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnCancelSwipe_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_SpectrumPro.SharedController.msr_cancelMSRSwipe();
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("MSR Turned Off successfully\r\n");
    System.Diagnostics.Debug.WriteLine("MSR Turned Off successfully");
    }
    else
    {
    tbOutput.AppendText("MSR Turned Off failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    System.Diagnostics.Debug.WriteLine("MSR Turned Off failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt));
    }
    }

Step 5: Configure callback to receive important SDK data (messages,log info and transaction results)

private void MessageCallBack(IDTechSDK.IDT_DEVICE_Types type, DeviceState state, byte[] data, IDTTransactionData cardData, EMV_Callback emvCallback, RETURN_CODE transactionResultCode)
{
switch (state)
{
case DeviceState.ToConnect:
//A connection attempt is starting for IDT_DEVICE_TYPES type
SetOutputText("Callback:ToConnect\n");
break;
case DeviceState.DefaultDeviceTypeChange:
//The SDK is changing the default device to IDT_DEVICE_TYPES type
SetOutputText("Callback:DefaultDeviceTypeChange\n");
break;
case DeviceState.Connected:
//A connection has been made to IDT_DEVICE_TYPES type
SetOutputText("Callback:Connected\n");
break;
case DeviceState.Disconnected:
//A disconnection has occured with IDT_DEVICE_TYPES type
SetOutputText("Callback:Disconnected\n");
break;
case DeviceState.ConnectionFailed:
//A connection attempt has failed for IDT_DEVICE_TYPES type
SetOutputText("Callback:ConnectionFailed\n");
break;
case DeviceState.TransactionData:
//Transaction data is beign returned in IDTTransactionData cardData
SetOutputText("Callback:TransactionData\n");
if (cardData.emv_resultCode == EMV_RESULT_CODE.EMV_RESULT_CODE_GO_ONLINE)
{
//auto complete. Normally, a host response is required here
SetOutputText("Online request. Auto Complete EMV Transaction.\n");
byte[] responseCode = new byte[] { 0x30, 0x30 };
byte[] iad = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x30, 0x30 };
RETURN_CODE rt = IDT_SpectrumPro.SharedController.emv_completeTransaction(false, responseCode, iad, null,null);
return;
}
displayCardData(cardData);
break;
case DeviceState.DataReceived:
//Low-level data received for IDT_DEVICE_TYPES type
SetOutputTextLog(GetTimestamp() + " IN: " + Common.getHexStringFromBytes(data));
break;
case DeviceState.DataSent:
//Low-level data sent for IDT_DEVICE_TYPES type
SetOutputTextLog(GetTimestamp() + " OUT: " + Common.getHexStringFromBytes(data));
break;
case DeviceState.CommandTimeout:
SetOutputText("Callback:CommandTimeout\n");
//Command timeout has occurred for IDT_DEVICE_TYPES type
break;
case DeviceState.ToSwipe:
//Awaiting a swipe for IDT_DEVICE_TYPES type
SetOutputText("Callback:ToSwipe\n");
break;
case DeviceState.MSRDecodeError:
//Awaiting a swipe for IDT_DEVICE_TYPES type
SetOutputText("Callback:MSRDecodeError\n");
break;
case DeviceState.ToTap:
//Awaiting a contactless tap for IDT_DEVICE_TYPES type
SetOutputText("Callback:ToTap\n");
break;
case DeviceState.SwipeTimeout:
//Waiting for swipe timed out
SetOutputText("Callback:SwipeTimeout\n");
break;
case DeviceState.TransactionCancelled:
//Transaction has been cancelled
SetOutputText("Callback:TransactionCancelled\n");
break;
case DeviceState.DeviceTimeout:
//Waiting for device timeout
SetOutputText("Callback:DeviceTimeout\n");
break;
case DeviceState.TransactionFailed:
//Transaction failed to complete
SetOutputText("Callback:TransactionFailed\n");
break;
case DeviceState.EMVCallback:
//Callback during EMV transaction retrieved from EMV_Callback emvCallback
SetOutputText("Callback:EMVCallback\n");
if (emvCallback.callbackType == EMV_CALLBACK_TYPE.EMV_CALLBACK_TYPE_LCD) //LCD Callback Type
{
if (emvCallback.lcd_displayMode == EMV_LCD_DISPLAY_MODE.EMV_LCD_DISPLAY_MODE_CLEAR_SCREEN)
{
SetOutputText("LCD Callback:Clear LCD Screen\n");
return;
}
else if (emvCallback.lcd_displayMode == EMV_LCD_DISPLAY_MODE.EMV_LCD_DISPLAY_MODE_MESSAGE)
{
// A message is requested to be displayed. See other test app included with SDK for a complete example.
SetOutputText("LCD Callback:Display Message\n");
}
else
{
//Display message with menu/language or prompt, and return result to emv_callbackResponseLCD
//Kernel will not proceed until this step is complete
//seeing to default value of 1. See other test app included with SDK for a complete example
SetOutputText("LCD Callback:Menu Display Request. Sending result 1\n");
IDT_SpectrumPro.SharedController.emv_callbackResponseLCD(emvCallback.lcd_displayMode, 1);
}
}
break;
default:
break;
}
}
private void displayCardData(IDTTransactionData cardData)
{
string text = "";
if (cardData.Event == EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_PIN_DATA)
{
SetOutputText("PIN Data received:\r\nKSN: " + cardData.pin_KSN + "\r\nPINBLOCK: " + cardData.pin_pinblock + "\r\n");
return;
}
if (cardData.Event == EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_DATA_CARD_DATA)
{
SetOutputText("Data received: (Length [" + cardData.msr_rawData.Length.ToString() + "])\n" + string.Concat(cardData.msr_rawData.ToArray().Select(b => b.ToString("X2")).ToArray()) + "\r\n");
System.Diagnostics.Debug.WriteLine("Data received: (Length [" + cardData.msr_rawData.Length.ToString() + "])\n" + string.Concat(cardData.msr_rawData.ToArray().Select(b => b.ToString("X2")).ToArray()));
}
if (cardData.device_RSN != null && cardData.device_RSN.Length > 0)
text += "Serial Number: " + cardData.device_RSN + "\r\n";
if (cardData.msr_track1Length > 0)
text += "Track 1: " + cardData.msr_track1 + "\r\n";
if (cardData.msr_encTrack1 != null)
text += "Track 1 Encrypted: " + Common.getHexStringFromBytes(cardData.msr_encTrack1) + "\r\n";
if (cardData.msr_hashTrack1 != null)
text += "Track 1 Hash: " + Common.getHexStringFromBytes(cardData.msr_hashTrack1) + "\r\n";
if (cardData.msr_track2Length > 0)
text += "Track 2: " + cardData.msr_track2 + "\r\n";
if (cardData.msr_encTrack2 != null)
text += "Track 2 Encrypted: " + Common.getHexStringFromBytes(cardData.msr_encTrack2) + "\r\n";
if (cardData.msr_hashTrack2 != null)
text += "Track 2 Hash: " + Common.getHexStringFromBytes(cardData.msr_hashTrack2) + "\r\n";
if (cardData.msr_track3Length > 0)
text += "Track 3: " + cardData.msr_track3 + "\r\n";
if (cardData.msr_encTrack3 != null)
text += "Track 3 Encrypted: " + Common.getHexStringFromBytes(cardData.msr_encTrack3) + "\r\n";
if (cardData.msr_hashTrack3 != null)
text += "Track 3 Hash: " + Common.getHexStringFromBytes(cardData.msr_hashTrack3) + "\r\n";
if (cardData.msr_KSN != null)
text += "KSN: " + Common.getHexStringFromBytes(cardData.msr_KSN) + "\r\n";
if (cardData.emv_clearingRecord != null)
{
if (cardData.emv_clearingRecord.Length > 0)
{
text += "\r\nCTLS Clearing Record: \r\n";
text += Common.getHexStringFromBytes(cardData.emv_clearingRecord) + "\r\n";
Dictionary<string, string> dict = Common.processTLVUnencrypted(cardData.emv_clearingRecord);
foreach (KeyValuePair<string, string> kvp in dict) text += kvp.Key + ": " + kvp.Value + "\r\n";
text += "\r\n\r\n";
}
}
if (cardData.emv_unencryptedTags != null)
{
if (cardData.emv_unencryptedTags.Length > 0)
{
text += "\r\n======================== \r\n";
text += "\r\nUnencrypted Tags: \r\n";
text += Common.getHexStringFromBytes(cardData.emv_unencryptedTags) + "\r\n\r\n";
text += tlvToValues(cardData.emv_unencryptedTags);
text += "\r\n======================== \r\n";
}
}
if (cardData.emv_encryptedTags != null)
{
if (cardData.emv_encryptedTags.Length > 0)
{
text += "\r\n======================== \r\n";
text += "\r\nEncrypted Tags: \r\n";
text += Common.getHexStringFromBytes(cardData.emv_encryptedTags) + "\r\n\r\n";
text += tlvToValues(cardData.emv_encryptedTags);
text += "\r\n======================== \r\n";
}
}
if (cardData.emv_maskedTags != null)
{
if (cardData.emv_maskedTags.Length > 0)
{
text += "\r\n======================== \r\n";
text += "\r\nMasked Tags: \r\n";
text += Common.getHexStringFromBytes(cardData.emv_maskedTags) + "\r\n\r\n";
text += tlvToValues(cardData.emv_maskedTags);
text += "\r\n======================== \r\n";
}
}
text += "ICC Present: ";
text += (cardData.iccPresent ? "TRUE" : "FALSE") + "\r\n";
text += "is CTLS: ";
text += (cardData.isCTLS ? "TRUE" : "FALSE") + "\r\n";
if (cardData.Event == EVENT_TRANSACTION_DATA_Types.EVENT_TRANSACTION_DATA_EMV_DATA)
{
if (!cardData.isCTLS) text += "Capture Encrypt Type: " + ((cardData.emv_encryptionMode == EMV_ENCRYPTION_MODE.EMV_ENCRYPTION_MODE_TDES) ? "TDES" : "AES") + "\r\n";
switch (cardData.emv_resultCode)
{
case EMV_RESULT_CODE.EMV_RESULT_CODE_APPROVED:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_APPROVED" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_APPROVED_OFFLINE:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_APPROVED_OFFLINE" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_DECLINED_OFFLINE:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_DECLINED_OFFLINE" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_DECLINED:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_DECLINED" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_GO_ONLINE:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_GO_ONLINE" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_CALL_YOUR_BANK:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_CALL_YOUR_BANK" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_NOT_ACCEPTED:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_NOT_ACCEPTED" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_FALLBACK_TO_MSR:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_FALLBACK_TO_MSR" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_TIMEOUT:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_TIMEOUT" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_AUTHENTICATE_TRANSACTION:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_AUTHENTICATE_TRANSACTION" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_SWIPE_NON_ICC:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_SWIPE_NON_ICC" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_CTLS_TWO_CARDS:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_CTLS_TWO_CARDS" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_CTLS_TERMINATE:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_CTLS_TERMINATE" + "\r\n");
break;
case EMV_RESULT_CODE.EMV_RESULT_CODE_CTLS_TERMINATE_TRY_ANOTHER:
text += ("EMV RESULT: " + "EMV_RESULT_CODE_CTLS_TERMINATE_TRY_ANOTHER" + "\r\n");
break;
}
}
SetOutputText(text);
}
private string tlvToValues(byte[] tlv)
{
string text = "";
Dictionary<string, string> dict = Common.processTLVUnencrypted(tlv);
foreach (KeyValuePair<string, string> kvp in dict) text += kvp.Key + ": " + kvp.Value + "\r\n";
return text;
}
delegate void SetTextCallback(string text);
private void SetOutputText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (tbOutput.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetOutputText);
Invoke(d, new object[] { text });
}
else
{
try { tbOutput.AppendText(text + "\r\n"); } catch (Exception ex) { }
}
}
private void SetOutputTextLog(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (logOutput.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetOutputTextLog);
Invoke(d, new object[] { text });
}
else
{
try { logOutput.AppendText(text + "\r\n"); }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception: " + ex);
}
}
}
public static String GetTimestamp()
{
DateTime value = DateTime.Now;
return value.ToString("HH:mm:ss.fff");
}