A .NET client library for interacting with Hikvision devices using the ISAPI protocol, with integrated Serilog logging via Zyga.SeriRestClient.
- π Session Management - Automatic login/logout handling with session keep-alive
- πͺ Door Control - Remote door control operations
- π Logging - Request/response logging via Zyga.SeriRestClient's Serilog integration
- π State Management - Smart session state handling with
EnsureLoggedIn() - π Dependency Injection - First-class support for Microsoft.Extensions.DependencyInjection
- π― Keyed Services - Support for multiple Hikvision device instances
- βοΈ Configuration - Easy configuration through IConfiguration
dotnet add package Zyga.HikIsapiClientTargets .NET 8, .NET 9 and .NET 10.
Configure your Hikvision device in appsettings.json:
{
"HikDevice": {
"Name": "Main Entrance",
"Address": "http://192.168.1.100",
"User": "admin",
"Password": "your-password",
"MaxTimeout": 5000
}
}Register in your Program.cs or Startup.cs:
using Zyga.HikIsapiClient.ExtensionMethods;
Host.CreateDefaultBuilder(args)
.AddHikIsapi("HikDevice")
.Build()
.Run();public class MyService
{
private readonly IIsapi _isapi;
public MyService(IIsapi isapi)
{
_isapi = isapi;
}
public void OpenDoor()
{
// Check if device is available
if (!_isapi.IsAvailable())
{
throw new Exception("Device is not available");
}
// Login and open door #1
_isapi.Login()
.DoorOpen(1)
.LogOut();
}
public void MaintainSession()
{
// Ensure logged in (will login only if needed)
var authenticated = _isapi.EnsureLoggedIn();
// Send heartbeat to keep session alive
authenticated.SessionHeartBeat();
// Check heartbeat count
Console.WriteLine($"Heartbeats sent: {authenticated.HeartBeatCount}");
}
}Register multiple Hikvision devices:
services
.AddKeyedHikIsapi("entrance", (sp, key) =>
sp.GetRequiredService<IConfiguration>()
.GetSection("Devices:Entrance")
.Get<IsapiConfig>())
.AddKeyedHikIsapi("parking", (sp, key) =>
sp.GetRequiredService<IConfiguration>()
.GetSection("Devices:Parking")
.Get<IsapiConfig>());Use keyed services:
public class SecurityService
{
private readonly IIsapi _entranceDevice;
private readonly IIsapi _parkingDevice;
public SecurityService(
[FromKeyedServices("entrance")] IIsapi entranceDevice,
[FromKeyedServices("parking")] IIsapi parkingDevice)
{
_entranceDevice = entranceDevice;
_parkingDevice = parkingDevice;
}
}| Method | Description |
|---|---|
Login() |
Authenticate and establish a session with the device |
EnsureLoggedIn() |
Login only if not already authenticated |
IsAvailable() |
Check if the device is reachable |
| Method | Description |
|---|---|
DoorOpen(int doorNo) |
Trigger door opening for specified door number |
SessionHeartBeat() |
Send keep-alive signal to maintain session |
LogOut() |
End the current session |
HeartBeatCount |
Get the number of heartbeats sent in current session |
| Property | Description |
|---|---|
Name |
Friendly name for the device |
Address |
Base URL of the Hikvision device (e.g., http://192.168.1.100) |
User |
Username for authentication |
Password |
Password for authentication |
MaxTimeout |
Maximum request timeout in milliseconds (default: 5000) |
A runnable console sample lives in samples/HikIsapiClient.Sample β
point its appsettings.json at your own device before running it.
- .NET 8, .NET 9, or .NET 10
- RestSharp 114.0.0+
- Serilog 4.4.0+
- Zyga.SeriRestClient 0.1.1+
Issues and pull requests are welcome. See CONTRIBUTING.md.
This package uses MinVer for semantic versioning,
derived from v-prefixed git tags (e.g. v1.2.3). There is no <Version> element
anywhere in the source β maintainers cut a release by pushing a tag.