// Read From Card public static CardData CISAReadCard(NFC NFCDevice) { /* CISA DLL Testing */ CardData cardData = new CardData(); string hotelFile, keyplanFile; short rc = 0; string serialnumberC2B = string.Format("{0,7}", ""); // 8 Chars fixed length string serialnumberC2B = vbHelper.Hex2Bin(CardUID + "C15A13FF"); byte[] bufCard = new byte[400]; // 221 byte[] bufCardWavemode = new byte[400]; // 228 string accesstname1Read = string.Format("{0,6}", ""); // room/zone - first access target name string accesstname2Read = string.Format("{0,6}", ""); // spaces - second access target name string accesstname3Read = string.Format("{0,6}", ""); // spaces - third access target name string accesstname4Read = string.Format("{0,6}", ""); // spaces - fourth access target name string accesstname5Read = string.Format("{0,6}", ""); // groups - category name string warning = ""; Csemks32.card guestcard = new Csemks32.card(); if (NFCDevice.connectCard())// establish connection to the card { Console.WriteLine("Reading from Card ..."); hotelFile = NFCDevice.readHotelFile(); // Read Hotel File - 36 bytes keyplanFile = NFCDevice.readKeyplanFile(); // Read Keyplan File - 192 bytes NFCDevice.Close(); // Console.WriteLine("* HOTEL FILE: " + vbHelper.Ascii2Hex(Encoding.ASCII.GetBytes(hotelFile))); // Console.WriteLine("* KEYPLAN FILE: " + vbHelper.Ascii2Hex(Encoding.ASCII.GetBytes(keyplanFile))); Console.WriteLine("* HOTEL FILE: " + hotelFile); Console.WriteLine("* KEYPLAN FILE: " + keyplanFile); string bufCardWavemodeStr = hotelFile + keyplanFile; bufCardWavemode = (byte[])Helpers.Hex2Byte(bufCardWavemodeStr); rc = CSEWaveModeDecode(bufCardWavemode, serialnumberC2B, bufCard); // We are getting bufCardWavemode value reading the card via NFC if (rc == Csemks32.CSE_SUCCESS) { rc = CSEBuffer2Card(bufCard, accesstname1Read, accesstname2Read, accesstname3Read, accesstname4Read, accesstname5Read, ref guestcard, warning); if (rc == Csemks32.CSE_SUCCESS) { Console.WriteLine("Card readed correctly"); cardData.result.rc = 0; // Reading Result Successful = Csemks32.CSE_SUCCESS // checkoutHours: get param from guestcard.accesstime_Renamed variable string codateYear = DateTime.Now.Year.ToString().Substring(0, 2) + Helpers.YearCisa(guestcard.accesstime_Renamed.dateEnd.year_Renamed); // Checkout date (year) int codateMonth = (int)guestcard.accesstime_Renamed.dateEnd.month_Renamed; // Checkout date (month) int codateDay = (int)guestcard.accesstime_Renamed.dateEnd.day_Renamed; // Checkout date (day) int codateHour = (int)guestcard.accesstime_Renamed.timeEnd.hours; // Checkout date (hour) int codateMinutes = (int)guestcard.accesstime_Renamed.timeEnd.minutes; // Checkout date (minutes) DateTime checkoutDate = DateTime.ParseExact(codateYear + "-" + codateMonth.ToString("00") + "-" + codateDay.ToString("00") + " " + codateHour.ToString("00") + ":" + codateMinutes.ToString("00") + ":00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); cardData.message.payload.checkoutHours = Helpers.date2epoch(checkoutDate); // Read room/zone if (guestcard.cardtype > 0) // Staff { cardData.message.payload.zone = CISAReadAccessTargetZone(guestcard.accesstarget1); // Read zone cardData.message.payload.room = null; cardData.message.payload.accessId = "Staff name"; // The Staff name is not physically written on the card, so it cannot be returned. } else // Guest { cardData.message.payload.room = CISAReadAccessTargetLock(guestcard.accesstarget1); // Read room cardData.message.payload.zone = null; cardData.message.payload.accessId = "Guest name"; // The Guest name is not physically written on the card, so it cannot be returned. } // Try to Get "Guest/Staff member" name // nCard parameter -> guestcard.cardinfo_Renamed.ncard; // Function to call -> rc = CSESearchCard(ref guestcardOp, ref guestcardRead, ref cardSearch); Csemks32.card guestcardRead = new Csemks32.card(); Csemks32.card guestcardOp = new Csemks32.card(); Csemks32.cardsearch cardSearch = new Csemks32.cardsearch(); cardSearch.ncard = guestcard.cardinfo_Renamed.ncard; //byte[] bufCardop = new byte[600]; // 221 //byte[] bufCard = new byte[600]; // 221 rc = CSESearchCard(ref guestcardOp, ref guestcardRead, ref cardSearch); if (rc == Csemks32.CSE_SUCCESS) { string name = guestcardRead.accessid; cardData.message.payload.accessId = name; // Set "guest/staff member" name // DateTime dtStart = Helpers.csdt2Dt(guestcardRead.accesstime_Renamed.dateStart, guestcardRead.accesstime_Renamed.timeStart); // DateTime dtEnd = Helpers.csdt2Dt(guestcardRead.accesstime_Renamed.dateEnd, guestcardRead.accesstime_Renamed.timeEnd); //Console.WriteLine("Card info: " + string.Format("ncard:{0} name:{1} start:{2} End:{3}\n", guestcardRead.cardinfo_Renamed.ncard, name, dtStart, dtEnd)); } else { cardData.result.rc = CSELoadErrNo(); cardData.result.errordesc = "\"CSESearchCard - ErrNo " + cardData.result.rc + "\""; Console.WriteLine("CSESearchCard Failed"); Console.WriteLine("ErrNo: " + cardData.result.rc.ToString()); } // End Get "Guest/Staff member" name // Read extra spaces List <string> spaces = new List <string>(); if (guestcard.accesstarget2.bed != 0) // Check if extraSpace is not empty (bed = 0) { string space1 = CISAReadAccessTargetLock(guestcard.accesstarget2); spaces.Add(space1); } if (guestcard.accesstarget3.bed != 0) // Check if extraSpace is not empty (bed = 0) { string space2 = CISAReadAccessTargetLock(guestcard.accesstarget3); spaces.Add(space2); } if (guestcard.accesstarget4.bed != 0) // Check if extraSpace is not empty (bed = 0) { string space3 = CISAReadAccessTargetLock(guestcard.accesstarget4); spaces.Add(space3); } cardData.message.payload.spaces = spaces; // new List<string>(new string[] { "espace1", "espace2" }); // Read groups List <string> groups = new List <string>(); if (guestcard.accesstarget5.bed != 0) // Check if group is not empty (bed = 0) { string group1 = CISAReadAccessTargetLock(guestcard.accesstarget5); groups.Add(group1); } cardData.message.payload.groups = groups; // new List<string>(new string[] { "group1", "group2" }); } else { cardData.result.rc = CSELoadErrNo(); cardData.result.errordesc = "\"CSEBuffer2Card - ErrNo " + cardData.result.rc + "\""; Console.WriteLine("CSEBuffer2Card Failed"); Console.WriteLine("ErrNo: " + cardData.result.rc.ToString()); } } else { cardData.result.rc = CSELoadErrNo(); cardData.result.errordesc = "\"CSEWaveModeDecode Failed - ErrNo " + cardData.result.rc + "\""; Console.WriteLine("CSEWaveModeDecode Failed"); Console.WriteLine("ErrNo: " + cardData.result.rc.ToString()); } } else { Console.WriteLine("Card not availale."); cardData.result.rc = -1; cardData.result.errordesc = "\"Reading card failed - Card not availale.\""; } return(cardData); }
public static extern short CSESearchCard(ref Csemks32.card cardOp, ref Csemks32.card card, ref Csemks32.cardsearch cardsearch);