Run the example

  1. Install and run the device gateway
  2. Download the C# client library
  3. Copy the root certificate of the device gateway to your working directory. As default, the certificate(ca.crt) resides in cert of the installation directory.
  4. The example uses grpc-dotnet. You can change the example/action/test/test.csproj file as needed.
  5. Change the gateway and the device information in example/action/test/Program.cs as needed.

     // the path of the root certificate
     private const string GATEWAY_CA_FILE = "../../../../cert/gateway/ca.crt";
    
     // the address of the gateway
     private const string GATEWAY_ADDR = "192.168.0.2";
     private const int GATEWAY_PORT = 4000;
    
     // the ip address of the target device
     private const string DEVICE_ADDR = "192.168.0.110";
     private const int DEVICE_PORT = 51211;
    
  6. Build and run.

     cd example/action/test
     dotnet run
    

1. Connect to the gateway and the device

The example assumes you use the device gateway. For the master gateway or other connection options, refer to the Connect or ConnectMaster examples.

  GatewayClient gatewayClient = new GatewayClient();
  gatewayClient.Connect(GATEWAY_CA_FILE, GATEWAY_ADDR, GATEWAY_PORT);

  var connectInfo = new ConnectInfo{ IPAddr = DEVICE_ADDR, Port = DEVICE_PORT, UseSSL = USE_SSL };
  uint devID = userTest.connectSvc.Connect(connectInfo); 

2. Make triggers

You can make several types of triggers. The example shows how to make event triggers among these.

  var cardFailTrigger = new Trigger{ DeviceID = deviceID, Type = TriggerType.TriggerEvent, Event = new EventTrigger{ EventCode = BS2_EVENT_VERIFY_FAIL | BS2_SUB_EVENT_CREDENTIAL_CARD }};
  var fingerFailTrigger = new Trigger{ DeviceID = deviceID, Type = TriggerType.TriggerEvent, Event = new EventTrigger{ EventCode = BS2_EVENT_IDENTIFY_FAIL | BS2_SUB_EVENT_CREDENTIAL_FINGER }};

3. Make actions

The example shows how to make a relay action. Refer to ActionType for available types of actions.

  var failAction = new Action.Action{ DeviceID = deviceID, Type = ActionType.ActionRelay, Relay = new RelayAction{ RelayIndex = 0, Signal = new Signal{ Count = 3, OnDuration = 500, OffDuration = 500}}};

4. Make TriggerActionConfig

You can configure up to 128 pairs of trigger and action in TriggerActionConfig.

  var config = new TriggerActionConfig();
  config.TriggerActions.Add( new TriggerActionConfig.Types.TriggerAction{ Trigger = cardFailTrigger, Action = failAction });
  config.TriggerActions.Add( new TriggerActionConfig.Types.TriggerAction{ Trigger = fingerFailTrigger, Action = failAction });

  actionSvc.SetConfig(deviceID, config);

Updated: