IDTech Windows SDK Guide  1.1.81.0
API reference for SmartPIN L100
Sample Project Tutorial

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

  • Get firmware version
  • Prompt for PIN Entry and return data
  • Display a secure message and prompt for entry
  • Display a non-secure message
  • Connect to either USB or Serial Versions of L100.
  • Show log of all data going to/from L100

Step 1: Create New Project

Create a new Windows Form Application in Visual Studio. In our example, we use project name L100_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 a drop-down for baud rate
  • Add buttons to execute the following functions:
    • Get Firmware
    • Get PIN Entry
    • Secure Message Prompt
    • Unsecure Message Prompt
  • Add a text box to communicate data from the L100.
  • Add a text box for the log of L100.
form.png
namespace L100_Simple_Demo
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.logOutput = new System.Windows.Forms.TextBox();
this.btnSecureMessage = new System.Windows.Forms.Button();
this.btnGetPIN = new System.Windows.Forms.Button();
this.btnFirmwareVersion = new System.Windows.Forms.Button();
this.tbOutput = new System.Windows.Forms.TextBox();
this.rbCOMM = new System.Windows.Forms.RadioButton();
this.rbUSB = new System.Windows.Forms.RadioButton();
this.tbCOMPort = new System.Windows.Forms.TextBox();
this.cbBaud = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.btnUnsecureMessage = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// logOutput
//
this.logOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.logOutput.BackColor = System.Drawing.SystemColors.HighlightText;
this.logOutput.Location = new System.Drawing.Point(9, 330);
this.logOutput.Multiline = true;
this.logOutput.Name = "logOutput";
this.logOutput.ReadOnly = true;
this.logOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.logOutput.Size = new System.Drawing.Size(343, 171);
this.logOutput.TabIndex = 124;
//
// btnSecureMessage
//
this.btnSecureMessage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnSecureMessage.Location = new System.Drawing.Point(9, 104);
this.btnSecureMessage.Name = "btnSecureMessage";
this.btnSecureMessage.Size = new System.Drawing.Size(348, 23);
this.btnSecureMessage.TabIndex = 123;
this.btnSecureMessage.Text = "Secure Message Prompt";
this.btnSecureMessage.UseVisualStyleBackColor = true;
this.btnSecureMessage.Click += new System.EventHandler(this.btnSecureMessage_Click);
//
// btnGetPIN
//
this.btnGetPIN.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnGetPIN.Location = new System.Drawing.Point(9, 75);
this.btnGetPIN.Name = "btnGetPIN";
this.btnGetPIN.Size = new System.Drawing.Size(348, 23);
this.btnGetPIN.TabIndex = 122;
this.btnGetPIN.Text = "Get PIN Entry";
this.btnGetPIN.UseVisualStyleBackColor = true;
this.btnGetPIN.Click += new System.EventHandler(this.btnGetPIN_Click);
//
// btnFirmwareVersion
//
this.btnFirmwareVersion.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnFirmwareVersion.Location = new System.Drawing.Point(9, 46);
this.btnFirmwareVersion.Name = "btnFirmwareVersion";
this.btnFirmwareVersion.Size = new System.Drawing.Size(348, 23);
this.btnFirmwareVersion.TabIndex = 121;
this.btnFirmwareVersion.Text = "Firmware Version";
this.btnFirmwareVersion.UseVisualStyleBackColor = true;
this.btnFirmwareVersion.Click += new System.EventHandler(this.btnFirmwareVersion_Click);
//
// tbOutput
//
this.tbOutput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbOutput.BackColor = System.Drawing.SystemColors.HighlightText;
this.tbOutput.Location = new System.Drawing.Point(9, 162);
this.tbOutput.Multiline = true;
this.tbOutput.Name = "tbOutput";
this.tbOutput.ReadOnly = true;
this.tbOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.tbOutput.Size = new System.Drawing.Size(343, 162);
this.tbOutput.TabIndex = 120;
//
// rbCOMM
//
this.rbCOMM.AutoSize = true;
this.rbCOMM.Location = new System.Drawing.Point(74, 11);
this.rbCOMM.Name = "rbCOMM";
this.rbCOMM.Size = new System.Drawing.Size(52, 17);
this.rbCOMM.TabIndex = 119;
this.rbCOMM.Text = "COM:";
this.rbCOMM.UseVisualStyleBackColor = true;
//
// rbUSB
//
this.rbUSB.AutoSize = true;
this.rbUSB.Location = new System.Drawing.Point(9, 11);
this.rbUSB.Name = "rbUSB";
this.rbUSB.Size = new System.Drawing.Size(47, 17);
this.rbUSB.TabIndex = 117;
this.rbUSB.Text = "USB";
this.rbUSB.UseVisualStyleBackColor = true;
this.rbUSB.CheckedChanged += new System.EventHandler(this.rbUSB_CheckedChanged);
//
// tbCOMPort
//
this.tbCOMPort.Location = new System.Drawing.Point(127, 10);
this.tbCOMPort.Name = "tbCOMPort";
this.tbCOMPort.Size = new System.Drawing.Size(45, 20);
this.tbCOMPort.TabIndex = 118;
this.tbCOMPort.Text = "1";
//
// cbBaud
//
this.cbBaud.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbBaud.FormattingEnabled = true;
this.cbBaud.Items.AddRange(new object[] {
"Default",
"2400",
"4800",
"9600",
"19200",
"38400",
"115000"});
this.cbBaud.Location = new System.Drawing.Point(263, 12);
this.cbBaud.Name = "cbBaud";
this.cbBaud.Size = new System.Drawing.Size(60, 21);
this.cbBaud.TabIndex = 82;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(225, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(32, 13);
this.label1.TabIndex = 83;
this.label1.Text = "Baud";
//
// btnUnsecureMessage
//
this.btnUnsecureMessage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnUnsecureMessage.Location = new System.Drawing.Point(9, 133);
this.btnUnsecureMessage.Name = "btnUnsecureMessage";
this.btnUnsecureMessage.Size = new System.Drawing.Size(348, 23);
this.btnUnsecureMessage.TabIndex = 125;
this.btnUnsecureMessage.Text = "Display Unsecure Message";
this.btnUnsecureMessage.UseVisualStyleBackColor = true;
this.btnUnsecureMessage.Click += new System.EventHandler(this.btnUnsecureMessage_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(367, 511);
this.Controls.Add(this.btnUnsecureMessage);
this.Controls.Add(this.label1);
this.Controls.Add(this.logOutput);
this.Controls.Add(this.cbBaud);
this.Controls.Add(this.btnSecureMessage);
this.Controls.Add(this.btnGetPIN);
this.Controls.Add(this.btnFirmwareVersion);
this.Controls.Add(this.tbOutput);
this.Controls.Add(this.rbCOMM);
this.Controls.Add(this.rbUSB);
this.Controls.Add(this.tbCOMPort);
this.Name = "Form1";
this.Text = "L100";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox tbCOMPort;
private System.Windows.Forms.RadioButton rbUSB;
private System.Windows.Forms.RadioButton rbCOMM;
private System.Windows.Forms.TextBox tbOutput;
private System.Windows.Forms.Button btnFirmwareVersion;
private System.Windows.Forms.Button btnStartEMVTransaction;
private System.Windows.Forms.Button btnCancelEMVTransaction;
private System.Windows.Forms.TextBox logOutput;
private System.Windows.Forms.Button btnSecureMessage;
private System.Windows.Forms.Button btnGetPIN;
private System.Windows.Forms.ComboBox cbBaud;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnUnsecureMessage;
}
}

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 L100 singleton object in the class initializer. Reference: Initialize SmartPIN L100
  • Implement the radio button methods CheckChanged handlers to set the proper interface for SDK communications
    private void rbUSB_CheckedChanged(object sender, EventArgs e)
    {
    if (rbUSB.Checked)
    {
    IDT_L100.useUSB();
    return;
    }
    if (cbBaud.SelectedIndex == 0) {
    IDT_L100.useSerialPort(Convert.ToInt32(tbCOMPort.Text), false);
    }
    else
    {
    IDT_L100.useSerialPort(Convert.ToInt32(tbCOMPort.Text), Convert.ToInt32(cbBaud.SelectedItem), false);
    }
    }
  • Implement the button methods Click handlers for button press code execution
    private void btnFirmwareVersion_Click(object sender, EventArgs e)
    {
    string firmwareVersion = "";
    RETURN_CODE rt = IDT_L100.SharedController.device_getFirmwareVersion(ref firmwareVersion);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Firmware Ver: " + firmwareVersion + "\r\n");
    System.Diagnostics.Debug.WriteLine("Firmware Ver: " + firmwareVersion);
    }
    else
    {
    tbOutput.AppendText("Get Firmware Fail Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    System.Diagnostics.Debug.WriteLine("Get Firmware Fail Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt));
    }
    }
    private void btnGetPIN_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_L100.SharedController.pin_getEncryptedPIN(1, "4111111111111111", "ENTER PIN", 45);
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Enter Pin Executed Successful\r\n");
    System.Diagnostics.Debug.WriteLine("Enter Pin Executed Successful");
    }
    else
    {
    tbOutput.AppendText("Enter Pin Executed failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    System.Diagnostics.Debug.WriteLine("Enter Pin Executed failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt));
    }
    }
    private void btnSecureMessage_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_L100.SharedController.pin_promptForKeyInput(Convert.ToInt32(tbMessageID.Text), Convert.ToInt32(tbLanguageID.Text), cbMaskInput.Checked, Convert.ToInt32(tbMinLength.Text), Convert.ToInt32(tbMaxLength.Text), Convert.ToInt32(tbPinTimout.Text));
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Prompt for Key Entry Command Successful\r\n");
    }
    else
    {
    tbOutput.AppendText("Prompt for Key Entry Command Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    }
    }
    private void btnUnsecureMessage_Click(object sender, EventArgs e)
    {
    RETURN_CODE rt = IDT_Device.SharedController.lcd_displayMessage(1, "SmartPIN L100 Ready");
    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
    {
    tbOutput.AppendText("Display Message Successful\r\n");
    System.Diagnostics.Debug.WriteLine("Display Message Successful");
    }
    else
    {
    tbOutput.AppendText("Display Message failed Error Code: " + "0x" + String.Format("{0:X}", (ushort)rt) + ": " + IDTechSDK.errorCode.getErrorString(rt) + "\r\n");
    System.Diagnostics.Debug.WriteLine("Display Message 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:
SetOutputText("To connect\r\n");
break;
case DeviceState.DefaultDeviceTypeChange:
SetOutputText("DefaultDeviceTypeChange\r\n");
break;
case DeviceState.Connected:
SetOutputText("Connected\r\n");
break;
case DeviceState.Disconnected:
SetOutputText("Disconnected\r\n");
break;
case DeviceState.ConnectionFailed:
SetOutputText("Connection Failed\r\n");
break;
case DeviceState.Notification:
SetOutputText("Notification\r\n");
break;
case DeviceState.TransactionData:
if (cardData == null) break;
//output parsed card data
SetOutputText("Return Code: " + transactionResultCode.ToString() + "\r\n");
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\nKey Entry: " + cardData.pin_KeyEntry + "\r\n");
return;
}
break;
case DeviceState.DataReceived:
SetOutputTextLog(" IN: " + Common.getHexStringFromBytes(data)+ "\r\n");
break;
case DeviceState.DataSent:
SetOutputTextLog(" OUT: " + Common.getHexStringFromBytes(data)+ "\r\n");
break;
case DeviceState.CommandTimeout:
SetOutputText("Command Timeout\r\n");
break;
case DeviceState.ToSwipe:
SetOutputText("To Swipe\r\n");
break;
case DeviceState.MSRDecodeError:
SetOutputText("MSR Decode Error\r\n");
break;
case DeviceState.ToTap:
SetOutputText("To Tap\r\n");
break;
case DeviceState.SwipeTimeout:
SetOutputText("Swipe Timeout\r\n");
break;
case DeviceState.TransactionCancelled:
System.Diagnostics.Debug.WriteLine("TransactionCancelled\r\n");
break;
case DeviceState.DeviceTimeout:
SetOutputText("Device Timeout\r\n");
break;
case DeviceState.TransactionFailed:
SetOutputText("Transaction Failed: " + IDTechSDK.errorCode.getErrorString(transactionResultCode) + "\r\n");
break;
case DeviceState.EMVCallback:
SetOutputText("EMV Callback\r\n");
break;
case DeviceState.PINpadKeypress:
SetOutputText("PINPad Key was pressed\r\n");
break;
default:
break;
}
}
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);
}
}
}