public static extern short CSECreateCardToDo(ref Csemks32.card card, ref Csemks32.card cardOp, ref Csemks32.card cardToRecode);
// 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); }
// Write To Card public static CISAResult CISACheck(KafkaMessage kmessage, NFC NFCDevice) { /* CISA DLL Testing */ CISAResult result = new CISAResult(); short rc = 0; byte[] bufCard = new byte[400]; // 221 byte[] bufCardWavemode = new byte[400]; // 228 Csemks32.csdate csdateNow; Csemks32.csdate csdateEnd; Csemks32.cstime cstimeNow; Csemks32.cstime cstimeEnd; int secNow; csdateNow.day_Renamed = 0; csdateNow.month_Renamed = 0; csdateNow.year_Renamed = 0; cstimeNow.hours = 0; cstimeNow.minutes = 0; string serialnumberC2B = string.Format("{0,7}", ""); // 8 Chars fixed length string serialnumberC2B = vbHelper.Hex2Bin(CardUID + "C15A13FF"); /* Calling CSEReadDateTime */ rc = CSEReadDateTime(ref csdateNow, ref cstimeNow, out secNow); if (rc == Csemks32.CSE_SUCCESS) { Console.WriteLine("CSEReadDateTime OK"); Console.WriteLine("Now is {0}/{1}/{2} {3}:{4}:{5}", csdateNow.day_Renamed.ToString("D2"), csdateNow.month_Renamed.ToString("D2"), csdateNow.year_Renamed.YearCisa(), cstimeNow.hours.ToString("D2"), cstimeNow.minutes.ToString("D2"), secNow.ToString("D2")); } else { result.rc = CSELoadErrNo(); result.errordesc = "\"CSEReadDateTime - ErrNo " + result.rc + "\""; Console.WriteLine("CSEReadDateTime Failed"); Console.WriteLine("ErrNo: " + result.rc.ToString()); return(result); } /* Calling CSECard2Buffer */ // 6 Chars fixed length strings string accesstname1 = string.Format("{0,6}", (kmessage.payload.room != null) ? kmessage.payload.room : kmessage.payload.zone); // room/zone - first access target name string accesstname2 = string.Format("{0,6}", (kmessage.payload.spaces != null && kmessage.payload.spaces.Count > 0) ? kmessage.payload.spaces[0] : ""); // spaces - second access target name string accesstname3 = string.Format("{0,6}", (kmessage.payload.spaces != null && kmessage.payload.spaces.Count > 1) ? kmessage.payload.spaces[1] : ""); // spaces - third access target name string accesstname4 = string.Format("{0,6}", (kmessage.payload.spaces != null && kmessage.payload.spaces.Count > 2) ? kmessage.payload.spaces[2] : ""); // spaces - fourth access target name string accesstname5 = string.Format("{0,6}", (kmessage.payload.groups != null && kmessage.payload.groups.Count > 0) ? kmessage.payload.groups[0] : ""); // groups - category name // string accesstname5 = string.Format("{0,6}", (kmessage.payload.groups != null && kmessage.payload.groups.Count > 0) ? "" : ""); // groups - category name // Pass "group" field value empty for testing purposes Csemks32.card guestcard = new Csemks32.card(); if (kmessage.payload.room != null) { guestcard.cardtype = 0; // 0 - Guest Card } else { guestcard.cardtype = 4; // 4 - Staff Card } // Provisional data for testing /* * csdateEnd.year_Renamed = csdateNow.year_Renamed; * csdateEnd.month_Renamed = csdateNow.month_Renamed; * csdateEnd.day_Renamed = 30; */ DateTime endDate = Helpers.epoch2date(double.Parse(kmessage.payload.checkoutHours)); int endDateYear = Helpers.YearPC2Cisa(endDate.Year); csdateEnd.year_Renamed = Convert.ToByte(sbyte.Parse(endDateYear.ToString().Substring(endDateYear.ToString().Length - 2))); csdateEnd.month_Renamed = Convert.ToByte(sbyte.Parse(endDate.Month.ToString())); csdateEnd.day_Renamed = Convert.ToByte(sbyte.Parse(endDate.Day.ToString())); guestcard.accessid = kmessage.payload.accessId; // Guest/Employee name guestcard.accesstime_Renamed.dateStart = csdateNow; // Checkin date guestcard.accesstime_Renamed.dateEnd = csdateEnd; // Checkout date guestcard.accesstime_Renamed.timeStart = cstimeNow; // checkin time guestcard.accesstime_Renamed.timeEnd.hours = Convert.ToByte(sbyte.Parse(endDate.Hour.ToString())); // checkout hour guestcard.accesstime_Renamed.timeEnd.minutes = Convert.ToByte(sbyte.Parse(endDate.Minute.ToString()));; // checkout minutes guestcard.credits = 0; // credits // Force null group guestcard.accesstarget5.bed = 0; guestcard.accesstarget5.id = 0; guestcard.cardinfo_Renamed.icopy = 1; guestcard.cardinfo_Renamed.ncopy = 1; if (guestcard.cardtype == 4) // Staff { guestcard.fOvrPrivacy = 0; } else // Guest { guestcard.fOvrPrivacy = 1; } guestcard.fOffice = 0; guestcard.fCardHistory = 0; guestcard.nhoursvalid = 0; if (guestcard.cardtype == 4) { // Staff's Card /* * guestcard.accesstime_Renamed.Initialize(); * * guestcard.accesstime_Renamed.mtimeshift_Renamed[0] = new Csemks32.mtimeshift(); * guestcard.accesstime_Renamed.mtimeshift_Renamed[1] = new Csemks32.mtimeshift(); * guestcard.accesstime_Renamed.mtimeshift_Renamed[2] = new Csemks32.mtimeshift(); * guestcard.accesstime_Renamed.mtimeshift_Renamed[3] = new Csemks32.mtimeshift(); * * * guestcard.accesstime_Renamed.mtimeshift_Renamed[0].start1 = 0; * guestcard.accesstime_Renamed.mtimeshift_Renamed[0].start2 = 0; * guestcard.accesstime_Renamed.mtimeshift_Renamed[0].end1 = 95; * guestcard.accesstime_Renamed.mtimeshift_Renamed[0].end2 = 0; * guestcard.accesstime_Renamed.mtimeshift_Renamed[0].days = 255; */ } rc = CSECard2Buffer(ref guestcard, String.Format(accesstname1, "!@@@@@@"), String.Format(accesstname2, "!@@@@@@"), String.Format(accesstname3, "!@@@@@@"), String.Format(accesstname4, "!@@@@@@"), String.Format(accesstname5, "!@@@@@@"), bufCard); if (rc == Csemks32.CSE_SUCCESS) { Console.WriteLine("CSECard2Buffer OK"); Console.WriteLine(vbHelper.Ascii2Hex(bufCard)); } else { result.rc = CSELoadErrNo(); result.errordesc = "\"CSECard2Buffer - ErrNo " + result.rc + "\""; Console.WriteLine("CSECard2Buffer Failed"); Console.WriteLine("ErrNo: " + result.rc.ToString()); return(result); } /* Calling CSEWaveModeEncode */ const byte IRversion = 1; rc = CSEWaveModeEncode(bufCard, serialnumberC2B, IRversion, bufCardWavemode); if (rc == Csemks32.CSE_SUCCESS) { Console.WriteLine("CSEWaveModeEncode OK"); Console.WriteLine("* bufCardWavemode Content: " + bufCardWavemode); Console.WriteLine("* bufCardWavemode Lenght: " + bufCardWavemode.Length); Console.WriteLine("* HOTEL File Lenght: " + vbHelper.MidVB(vbHelper.Ascii2Hex(bufCardWavemode), 1, 32 * 2).Length); Console.WriteLine("* HOTEL FILE: " + vbHelper.MidVB(vbHelper.Ascii2Hex(bufCardWavemode), 1, 32 * 2)); Console.WriteLine("* HOTEL FILE: " + Helpers.Mid(bufCardWavemode.Ascii2Hex(), 1, 32 * 2)); Console.WriteLine("* KEYPLAN File Lenght: " + vbHelper.MidVB(vbHelper.Ascii2Hex(bufCardWavemode), 32 * 2 + 1, 188 * 2).Length); Console.WriteLine("* KEYPLAN FILE: " + vbHelper.MidVB(vbHelper.Ascii2Hex(bufCardWavemode), 32 * 2 + 1, 188 * 2)); Console.WriteLine("* KEYPLAN FILE: " + Helpers.Mid(bufCardWavemode.Ascii2Hex(), 32 * 2 + 1, 188 * 2)); if (NFCDevice.connectCard())// establish connection to the card: you've declared this from previous post { Console.WriteLine("Writing to Card ..."); NFCDevice.writeHotelFile(vbHelper.MidVB(vbHelper.Ascii2Hex(bufCardWavemode), 1, 36 * 2)); // Write Hotel File - 36 bytes NFCDevice.writeKeyplanFile(vbHelper.MidVB(vbHelper.Ascii2Hex(bufCardWavemode), 36 * 2 + 1, 192 * 2)); // Write Keyplan File - 192 bytes NFCDevice.Close(); } else { Console.WriteLine("Card not availale."); result.rc = -1; result.errordesc = "\"Writing card failed - Card not availale.\""; return(result); } } else { result.rc = CSELoadErrNo(); result.errordesc = "\"CSEWaveModeEncode Failed - ErrNo " + result.rc + "\""; Console.WriteLine("CSEWaveModeEncode Failed"); Console.WriteLine("ErrNo: " + result.rc.ToString()); return(result); } return(result); }
public static extern short CSECheckOutCard(ref Csemks32.card card);
public static extern short CSECard2Buffer(ref Csemks32.card card, string accesstname1, string accesstname2, string accesstname3, string accesstname4, string accesstname5, [In, Out] byte[] bufCard);
public static extern short CSEBuffer2Card([In, Out] byte[] bufCard, string accesstname1, string accesstname2, string accesstname3, string accesstname4, string accesstname5, ref Csemks32.card card, string warning);
public static extern short CSESearchCard(ref Csemks32.card cardOp, ref Csemks32.card card, ref Csemks32.cardsearch cardsearch);