Example #1
0
        public void addWiegandDevice(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Enter the ID of the wiegand device which you want to add: [ID_1,ID_2 ...]");
            Console.Write(">>>> ");
            char[]        delimiterChars      = { ' ', ',', '.', ':', '\t' };
            string[]      wiegandDeviceIDs    = Console.ReadLine().Split(delimiterChars);
            List <UInt32> wiegandDeviceIDList = new List <UInt32>();

            foreach (string holidayGroupID in wiegandDeviceIDs)
            {
                if (holidayGroupID.Length > 0)
                {
                    UInt32 item;
                    if (UInt32.TryParse(holidayGroupID, out item))
                    {
                        wiegandDeviceIDList.Add(item);
                    }
                }
            }

            if (wiegandDeviceIDList.Count > 0)
            {
                IntPtr wiegandDeviceIDObj = Marshal.AllocHGlobal(sizeof(UInt32) * wiegandDeviceIDList.Count);
                for (int idx = 0; idx < wiegandDeviceIDList.Count; ++idx)
                {
                    Marshal.WriteInt32(wiegandDeviceIDObj, idx * sizeof(UInt32), (int)wiegandDeviceIDList[idx]);
                }

                Console.WriteLine("Trying to add the wiegand devices.");
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_AddWiegandDevices(sdkContext, deviceID, wiegandDeviceIDObj, (UInt32)wiegandDeviceIDList.Count);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                }

                Marshal.FreeHGlobal(wiegandDeviceIDObj);
            }
        }