public void print(UInt32 deviceID, BS2Door door) { Console.WriteLine(">>>> Device[{0}] DoorID[{1}] name:[{2}]", deviceID, door.doorID, Encoding.UTF8.GetString(door.name).TrimEnd('\0')); Console.WriteLine(" +--sensor"); Console.WriteLine(" |--ioDeviceID[{0}]", door.sensor.deviceID); Console.WriteLine(" |--port[{0}]]", door.sensor.port); Console.WriteLine(" |--switchType[{0}]]", (BS2SwitchTypeEnum)door.sensor.switchType); Console.WriteLine(" +--apbUseDoorSensor[{0}]", door.sensor.apbUseDoorSensor); }
void print(IntPtr sdkContext, BS2Door door) { Console.WriteLine(">>>> Door ID[{0, 10}] name[{1}]", door.doorID, Encoding.UTF8.GetString(door.name).TrimEnd('\0')); Console.WriteLine(" |--entryDeviceID[{0}]", door.entryDeviceID); Console.WriteLine(" |--exitDeviceID[{0}]", door.exitDeviceID); Console.WriteLine(" |--relay[ioDeviceID[{0}] port[{1}]]", door.relay.deviceID, door.relay.port); Console.WriteLine(" |--sensor[ioDeviceID[{0}] port[{1}] switchType[{2}]]", door.sensor.deviceID, door.sensor.port, (BS2SwitchTypeEnum)door.sensor.switchType); Console.WriteLine(" |--exitButton[ioDeviceID[{0}] port[{1}] switchType[{2}]]", door.button.deviceID, door.button.port, (BS2SwitchTypeEnum)door.button.switchType); Console.WriteLine(" |--autoLockTimeout[{0}ms]", door.autoLockTimeout); Console.WriteLine(" |--heldOpenTimeout[{0}ms]", door.heldOpenTimeout); Console.WriteLine(" |--unlockFlags[{0}]", (BS2DoorFlagEnum)door.unlockFlags); Console.WriteLine(" |--lockFlags[{0}]", (BS2DoorFlagEnum)door.lockFlags); Console.WriteLine(" |--alarmFlags[{0}]", (BS2DoorAlarmFlagEnum)door.unconditionalLock); Console.WriteLine(" |--forcedOpenAlarm"); for (int idx = 0; idx < BS2Envirionment.BS2_MAX_FORCED_OPEN_ALARM_ACTION; ++idx) { BS2ActionTypeEnum actionType = (BS2ActionTypeEnum)door.heldOpenAlarm[idx].type; Console.WriteLine(" | |--ID[{0}] Type[{1}] {2}", door.heldOpenAlarm[idx].deviceID, (BS2ActionTypeEnum)door.heldOpenAlarm[idx].type, Util.getActionMsg(door.forcedOpenAlarm[idx])); } Console.WriteLine(" |--heldOpenAlarm"); for (int idx = 0; idx < BS2Envirionment.BS2_MAX_HELD_OPEN_ALARM_ACTION; ++idx) { BS2ActionTypeEnum actionType = (BS2ActionTypeEnum)door.heldOpenAlarm[idx].type; Console.WriteLine(" | |--ID[{0}] Type[{1}] {2}", door.heldOpenAlarm[idx].deviceID, (BS2ActionTypeEnum)door.heldOpenAlarm[idx].type, Util.getActionMsg(door.heldOpenAlarm[idx])); } Console.WriteLine(" |--dualAuthScheduleID[{0}]", door.dualAuthScheduleID); Console.WriteLine(" |--dualAuthDevice[{0}]", door.dualAuthDevice); Console.WriteLine(" |--dualAuthApprovalType[{0}]", (BS2DualAuthApprovalEnum)door.dualAuthApprovalType); Console.WriteLine(" |--dualAuthTimeout[{0}ms]", door.dualAuthTimeout); if (door.numDualAuthApprovalGroups > 0) { Console.WriteLine(" |--dualAuthApprovalGroupID"); for (int idx = 0; idx < door.numDualAuthApprovalGroups; ++idx) { Console.WriteLine(" | |--dual auth approval group id[{0}]", door.dualAuthApprovalGroupID[idx]); } } }
public bool checkAPBOptionInDoor(IntPtr sdkContext, UInt32 deviceID) { IntPtr doorObj = IntPtr.Zero; UInt32 numDoor = 0; BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS; Console.WriteLine("Device:{0}, Enter the ID of the door which you want to get: [ID_1,ID_2 ...]", deviceID); Console.Write(">>>> "); char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; string[] doorIDs = Console.ReadLine().Split(delimiterChars); List <UInt32> doorIDList = new List <UInt32>(); foreach (string doorID in doorIDs) { if (doorID.Length > 0) { UInt32 item; if (UInt32.TryParse(doorID, out item)) { doorIDList.Add(item); } } } if (doorIDList.Count > 0) { IntPtr doorIDObj = Marshal.AllocHGlobal(4 * doorIDList.Count); IntPtr curDoorIDObj = doorIDObj; foreach (UInt32 item in doorIDList) { Marshal.WriteInt32(curDoorIDObj, (Int32)item); curDoorIDObj = (IntPtr)((long)curDoorIDObj + 4); } Console.WriteLine("Trying to get doors from device."); result = (BS2ErrorCode)API.BS2_GetDoor(sdkContext, deviceID, doorIDObj, (UInt32)doorIDList.Count, out doorObj, out numDoor); Marshal.FreeHGlobal(doorIDObj); } else { Console.WriteLine("Invalid parameter"); } if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); } else if (numDoor > 0) { IntPtr curDoorObj = doorObj; int structSize = Marshal.SizeOf(typeof(BS2Door)); for (int idx = 0; idx < numDoor; ++idx) { BS2Door item = (BS2Door)Marshal.PtrToStructure(curDoorObj, typeof(BS2Door)); print(deviceID, item); const byte On = 1; if (item.sensor.apbUseDoorSensor != On) { item.sensor.apbUseDoorSensor = On; result = (BS2ErrorCode)API.BS2_SetDoor(sdkContext, deviceID, curDoorObj, 1); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); } } curDoorObj = (IntPtr)((long)curDoorObj + structSize); } API.BS2_ReleaseObject(doorObj); return(true); } else { Console.WriteLine(">>> There is no door in the device."); Console.WriteLine(" Set the door 1st in the DoorControl."); Console.WriteLine(" Set the access group and access level 2nd in the AccessControl."); Console.WriteLine(" Set a user 3rd in the UserControl."); } return(false); }
public void getDoor(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice) { IntPtr doorObj = IntPtr.Zero; UInt32 numDoor = 0; BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS; Console.WriteLine("Do you want to get all doors? [Y/n]"); Console.Write(">>>> "); if (Util.IsYes()) { Console.WriteLine("Trying to get all doors from device."); result = (BS2ErrorCode)API.BS2_GetAllDoor(sdkContext, deviceID, out doorObj, out numDoor); } else { Console.WriteLine("Enter the ID of the door which you want to get: [ID_1,ID_2 ...]"); Console.Write(">>>> "); char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; string[] doorIDs = Console.ReadLine().Split(delimiterChars); List <UInt32> doorIDList = new List <UInt32>(); foreach (string doorID in doorIDs) { if (doorID.Length > 0) { UInt32 item; if (UInt32.TryParse(doorID, out item)) { doorIDList.Add(item); } } } if (doorIDList.Count > 0) { IntPtr doorIDObj = Marshal.AllocHGlobal(4 * doorIDList.Count); IntPtr curDoorIDObj = doorIDObj; foreach (UInt32 item in doorIDList) { Marshal.WriteInt32(curDoorIDObj, (Int32)item); curDoorIDObj = (IntPtr)((long)curDoorIDObj + 4); } Console.WriteLine("Trying to get doors from device."); result = (BS2ErrorCode)API.BS2_GetDoor(sdkContext, deviceID, doorIDObj, (UInt32)doorIDList.Count, out doorObj, out numDoor); Marshal.FreeHGlobal(doorIDObj); } else { Console.WriteLine("Invalid parameter"); } } if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); } else if (numDoor > 0) { IntPtr curDoorObj = doorObj; int structSize = Marshal.SizeOf(typeof(BS2Door)); for (int idx = 0; idx < numDoor; ++idx) { BS2Door item = (BS2Door)Marshal.PtrToStructure(curDoorObj, typeof(BS2Door)); print(sdkContext, item); curDoorObj = (IntPtr)((long)curDoorObj + structSize); } API.BS2_ReleaseObject(doorObj); } else { Console.WriteLine(">>> There is no door in the device."); } }
public void setDoor(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice) { Console.WriteLine("How many doors do you want to set? [1(default)-128]"); Console.Write(">>>> "); char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; int amount = Util.GetInput(1); List <BS2Door> doorList = new List <BS2Door>(); for (int idx = 0; idx < amount; ++idx) { BS2Door door = Util.AllocateStructure <BS2Door>(); Console.WriteLine("Enter a value for door[{0}]", idx); Console.WriteLine(" Enter the ID for the door which you want to set"); Console.Write(" >>>> "); door.doorID = (UInt32)Util.GetInput(); Console.WriteLine(" Enter the name for the door which you want to set"); Console.Write(" >>>> "); string doorName = Console.ReadLine(); if (doorName.Length == 0) { Console.WriteLine(" [Warning] door name will be displayed as empty."); } else if (doorName.Length > BS2Envirionment.BS2_MAX_DOOR_NAME_LEN) { Console.WriteLine(" Name of door should less than {0} words.", BS2Envirionment.BS2_MAX_DOOR_NAME_LEN); return; } else { byte[] doorArray = Encoding.UTF8.GetBytes(doorName); Array.Clear(door.name, 0, BS2Envirionment.BS2_MAX_DOOR_NAME_LEN); Array.Copy(doorArray, door.name, doorArray.Length); } Console.WriteLine(" Enter the ID of the Reader for entrance"); Console.Write(" >>>> "); door.entryDeviceID = Util.GetInput((UInt32)0); Console.WriteLine(" Enter the ID of the Reader for exit"); Console.Write(" >>>> "); door.exitDeviceID = Util.GetInput((UInt32)0); Console.WriteLine(" Enter the AutoLock timeout in seconds: [3(default)]"); Console.Write(" >>>> "); door.autoLockTimeout = Util.GetInput((UInt32)3); Console.WriteLine(" Enter the HeldOpen timeout in seconds: [3(default)]"); Console.Write(" >>>> "); door.heldOpenTimeout = Util.GetInput((UInt32)3); Console.WriteLine(" Should this Door be locked instantly when it is closed? [Y/n]"); Console.Write(" >>>> "); if (Util.IsYes()) { door.instantLock = 1; } else { door.instantLock = 0; } Console.WriteLine(" Does this door has a relay? [Y/n]"); Console.Write(" >>>> "); if (Util.IsYes()) { Console.WriteLine(" Enter the device id for the relay on this door."); Console.Write(" >>>> "); door.relay.deviceID = (UInt32)Util.GetInput(); Console.WriteLine(" Enter the the port of the relay on this door.[0(default)]"); Console.Write(" >>>> "); door.relay.port = Util.GetInput(0); } Console.WriteLine(" Does this door has a door sensor? [Y/n]"); Console.Write(" >>>> "); if (Util.IsYes()) { Console.WriteLine(" Enter the device id of the door sensor on this door."); Console.Write(" >>>> "); door.sensor.deviceID = (UInt32)Util.GetInput(); Console.WriteLine(" Enter the the port of the door sensor on this door.[0(default)]"); Console.Write(" >>>> "); door.sensor.port = Util.GetInput(0); Console.WriteLine(" Enter the switch type of the door sensor on this door: [0: normally open, 1: normally closed]."); Console.Write(" >>>> "); door.sensor.switchType = Util.GetInput(0); } Console.WriteLine(" Does this door has a exit button? [Y/n]"); Console.Write(" >>>> "); if (Util.IsYes()) { Console.WriteLine(" Enter the device id of the exit button on this door."); Console.Write(" >>>> "); door.button.deviceID = (UInt32)Util.GetInput(); Console.WriteLine(" Enter the the port of the exit button on this door.[0(default)]"); Console.Write(" >>>> "); door.button.port = Util.GetInput(0); Console.WriteLine(" Enter the switch type of the exit button on this door: [0: normally open, 1: normally closed]."); Console.Write(" >>>> "); door.button.switchType = Util.GetInput(0); } Console.WriteLine(" How to act at lock door? [0: None(default), 1: Schedule, 2: Emergency, 4: Operator]"); Console.Write(" >>>> "); door.lockFlags = Util.GetInput((byte)BS2DoorFlagEnum.NONE); Console.WriteLine(" How to act at unlock door? [0: None(default), 1: Schedule, 2: Emergency, 4: Operator]"); Console.Write(" >>>> "); door.unlockFlags = Util.GetInput((byte)BS2DoorFlagEnum.NONE); BS2DoorAlarmFlagEnum doorAlarmFlag = BS2DoorAlarmFlagEnum.NONE; for (int loop = 0; loop < BS2Envirionment.BS2_MAX_FORCED_OPEN_ALARM_ACTION; ++loop) { door.forcedOpenAlarm[loop].type = (byte)BS2ActionTypeEnum.NONE; } for (int loop = 0; loop < BS2Envirionment.BS2_MAX_HELD_OPEN_ALARM_ACTION; ++loop) { door.heldOpenAlarm[loop].type = (byte)BS2ActionTypeEnum.NONE; } #if false //please refer to ZoneControl Console.WriteLine(" Does this door need to forced open door alarm? [y/N]"); if (!Util.IsNo()) { Console.WriteLine(" How many forced open door alarm do you want to set? [1(default)-{0}]", BS2Envirionment.BS2_MAX_FORCED_OPEN_ALARM_ACTION); Console.Write(" >>>> "); int alarmCount = Util.GetInput(1); if (alarmCount > 0) { doorAlarmFlag |= BS2DoorAlarmFlagEnum.FORCED_OPEN; for (int loop = 0; loop < alarmCount; ++loop) { Console.WriteLine(" Enter the action type which you want to set [6(default) : relay, 7 : ttl, 8 : sound, 9: display, 10 : buzzer, 11: led]"); Console.Write(" >>>> "); door.forcedOpenAlarm[loop].type = Util.GetInput((byte)BS2ActionTypeEnum.RELAY); switch ((BS2ActionTypeEnum)door.forcedOpenAlarm[loop].type) { case BS2ActionTypeEnum.RELAY: { BS2RelayAction relay = Util.AllocateStructure <BS2RelayAction>(); Console.WriteLine(" Enter the the port of the relay on this door.[0(default)]"); Console.Write(" >>>> "); relay.relayIndex = Util.GetInput(0); } break; } } } } #endif door.unconditionalLock = (byte)doorAlarmFlag; Console.WriteLine(" Does this door need to dual authentication? [y/N]"); if (Util.IsNo()) { door.dualAuthDevice = (byte)BS2DualAuthDeviceEnum.NO_DEVICE; door.dualAuthScheduleID = (UInt32)BS2ScheduleIDEnum.NEVER; door.dualAuthTimeout = 0; door.dualAuthApprovalType = (byte)BS2DualAuthApprovalEnum.NONE; door.numDualAuthApprovalGroups = 0; } else { Console.WriteLine(" Which reader requires dual authentication? [1: Entrance Only(default), 2: Exit Only, 3: Both]"); Console.Write(" >>>> "); door.dualAuthDevice = Util.GetInput((byte)BS2DualAuthDeviceEnum.ENTRY_DEVICE_ONLY); Console.WriteLine(" Enter the id of access schedule for dual authentication: [0: Never, 1: Always(default), or the other schedule id]"); Console.Write(" >>>> "); door.dualAuthScheduleID = Util.GetInput((UInt32)BS2ScheduleIDEnum.ALWAYS); Console.WriteLine(" Enter the dual authentication timeout in seconds: [5(default)]"); Console.Write(" >>>> "); door.dualAuthTimeout = Util.GetInput((UInt32)5); Console.WriteLine(" Who should be the dual authentication approver for this door? [0: Not required(default), 1: Second user] "); Console.Write(" >>>> "); door.dualAuthApprovalType = Util.GetInput((byte)BS2DualAuthApprovalEnum.NONE); Console.WriteLine(" Enter the ID of access groups for dual authentication approval: [ID_1,ID_2 ...]"); Console.Write(" >>>> "); string[] accessGroupIDs = Console.ReadLine().Split(delimiterChars); List <UInt32> accessGroupIDList = new List <UInt32>(); foreach (string accessGroupID in accessGroupIDs) { if (accessGroupID.Length > 0) { UInt32 item; if (UInt32.TryParse(accessGroupID, out item)) { accessGroupIDList.Add(item); } } } door.numDualAuthApprovalGroups = (byte)accessGroupIDList.Count; for (int loop = 0; loop < accessGroupIDList.Count; ++loop) { door.dualAuthApprovalGroupID[loop] = accessGroupIDList[loop]; } //If you want to set up one door apb zone, please refer to ZoneControl section. } doorList.Add(door); } int structSize = Marshal.SizeOf(typeof(BS2Door)); IntPtr doorListObj = Marshal.AllocHGlobal(structSize * doorList.Count); IntPtr curDoorListObj = doorListObj; foreach (BS2Door item in doorList) { Marshal.StructureToPtr(item, curDoorListObj, false); curDoorListObj = (IntPtr)((long)curDoorListObj + structSize); } Console.WriteLine("Trying to set doors to device."); BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetDoor(sdkContext, deviceID, doorListObj, (UInt32)doorList.Count); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); } Marshal.FreeHGlobal(doorListObj); }