-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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