Skip to content

Instantly share code, notes, and snippets.

@kirillrybin
Last active September 2, 2015 08:55
Show Gist options
  • Save kirillrybin/c429d5c37fa2756e4ca6 to your computer and use it in GitHub Desktop.
Save kirillrybin/c429d5c37fa2756e4ca6 to your computer and use it in GitHub Desktop.
Unity3D class for work with Smartec ST-CE010EM (Em Marine) http://www.smartec-security.ru/news/usb-card-reader.htm
using UnityEngine;
public class RFIDController : MonoBehaviour
{
public delegate void RFIDEvent(string code);
public delegate void RFIDErrorEvent(string message);
public event RFIDEvent OnRFID;
public event RFIDErrorEvent OnRFIDError;
private string _tempRfidCode = "";
private string _rfidCode = "";
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha0)) _tempRfidCode += "0";
if (Input.GetKeyDown(KeyCode.Alpha1)) _tempRfidCode += "1";
if (Input.GetKeyDown(KeyCode.Alpha2)) _tempRfidCode += "2";
if (Input.GetKeyDown(KeyCode.Alpha3)) _tempRfidCode += "3";
if (Input.GetKeyDown(KeyCode.Alpha4)) _tempRfidCode += "4";
if (Input.GetKeyDown(KeyCode.Alpha5)) _tempRfidCode += "5";
if (Input.GetKeyDown(KeyCode.Alpha6)) _tempRfidCode += "6";
if (Input.GetKeyDown(KeyCode.Alpha7)) _tempRfidCode += "7";
if (Input.GetKeyDown(KeyCode.Alpha8)) _tempRfidCode += "8";
if (Input.GetKeyDown(KeyCode.Alpha9)) _tempRfidCode += "9";
if (Input.GetKeyDown(KeyCode.Return))
{
if (_tempRfidCode.Length == 10)
{
_rfidCode = _tempRfidCode;
Debug.Log("RFID: " + _rfidCode);
if (OnRFID != null) OnRFID(_rfidCode);
}
else
{
Debug.LogError("Wrong RFID: " + _tempRfidCode);
if (OnRFIDError != null) OnRFIDError("Wrong RFID: " + _tempRfidCode);
}
_tempRfidCode = "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment