Using Visual Studio 2015, we will create a C# sample project that will interface with the UniPay and will perform the following activities:
Create a new Windows Form Application in Visual Studio. In our example, we use project name UniPay_Simple_Demo
delegate void SetTextCallback(string text);
delegate void SetTextCallbackWithTextAlign(string text, bool withAlign = false);
public static String GetTimestamp()
{
DateTime value = DateTime.Now;
return value.ToString("HH:mm:ss.fff");
}
private void MessageCallBack(
IDTechSDK.IDT_DEVICE_Types type, DeviceState state, byte[] data, IDTTransactionData cardData, EMV_Callback emvCallback, RETURN_CODE transactionResultCode)
{
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);
DEVICE_INTERFACE_Types connect = DEVICE_INTERFACE_Types.DEVICE_INTERFACE_UNKNOWN;
DEVICE_PROTOCOL_Types protocol = DEVICE_PROTOCOL_Types.DEVICE_PROTOCOL_UNKNOWN;
if (comm != null)
{
connect = comm.getDeviceConnection();
protocol = comm.getDeviceProtocol();
}
switch (state)
{
case DeviceState.ToConnect:
SetOutputText("To connect\n");
break;
case DeviceState.DefaultDeviceTypeChange:
SetOutputText(
"\nSDK Default Device = " +
IDTechSDK.Profile.IDT_DEVICE_String(type, connect));
SetTitleText(
"Universal SDK Demo: " +
IDTechSDK.Profile.IDT_DEVICE_String(type, connect));
break;
case DeviceState.Connected:
SetOutputText(
"\nConnected " +
IDTechSDK.Profile.IDT_DEVICE_String(type, connect));
break;
case DeviceState.Disconnected:
SetOutputText(
"\nDisconnected " +
IDTechSDK.Profile.IDT_DEVICE_String(type, connect));
break;
case DeviceState.ConnectionFailed:
SetOutputText("\nConnection Failed\n");
break;
case DeviceState.TransactionData:
if (cardData == null) break;
SetOutputText("Return Code MSR: " + transactionResultCode.ToString() + "\r\n");
displayCardData(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:
SetOutputText("Command Timeout\n");
break;
case DeviceState.ToSwipe:
SetOutputText("To Swipe\n");
break;
case DeviceState.MSRDecodeError:
SetOutputText("MSR Decode Error\n");
break;
case DeviceState.ToTap:
SetOutputText("To Tap\n");
break;
case DeviceState.SwipeTimeout:
SetOutputText("Swipe Timeout\n");
break;
case DeviceState.TransactionCancelled:
SetOutputText("Transaction Cancelled\n");
break;
case DeviceState.DeviceTimeout:
SetOutputText("Device Timeout\n");
break;
case DeviceState.TransactionFailed:
SetOutputText(
"Transaction Failed: " +
IDTechSDK.errorCode.getErrorString(transactionResultCode) +
"\r\n");
break;
case DeviceState.EMVCallback:
SetOutputText("EMV Callback\n");
break;
default:
break;
}
}