Using Visual Studio 2015, we will create a C# sample project that will interface with the SmartPin L100 and will perform the following activities:
Create a new Windows Form Application in Visual Studio. In our example, we use project name L100_Simple_Demo
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();
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;
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);
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);
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);
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;
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;
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);
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";
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;
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";
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);
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;
}
}
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;
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)
{
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)
{
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);
}
}
}