# SDK API Reference 中文说明见 [SDK_API_Reference.zh-CN.md](SDK_API_Reference.zh-CN.md). This document lists the public business-level API exposed by `xin.aisu.si-m1.face`. The package is DLL-only; source files are not included in the public release. ## Namespaces | Namespace | Description | |---|---| | `Aisu.SIM1.Face.Core` | Manager, settings, callback adapter, logging, main-thread dispatch | | `Aisu.SIM1.Face.Commands` | Business services, command service, encryption adapter | | `Aisu.SIM1.Face.Protocol` | Protocol enums, packet build/parse helpers, encoding helpers | | `Aisu.SIM1.Face.Transport` | Transport interface, serial transport, mock transport | | `Aisu.SIM1.Face.Models` | Reply, note, user, verification, enrollment, image, and UVC models | ## FaceModuleManager Use `FaceModuleManager` as the recommended single entry point: ```csharp using Aisu.SIM1.Face.Core; ``` ### Properties | Property | Type | Description | |---|---|---| | `Basic` | `FaceBasicService` | Basic module commands | | `Verify` | `FaceVerifyService` | Face verification service | | `Enrollment` | `FaceEnrollmentService` | Face enrollment service | | `Users` | `FaceUserService` | User management service | | `QrCode` | `FaceQrCodeService` | QR code service | | `Images` | `FaceImageService` | Image capture and photo enrollment service | | `Features` | `FaceFeatureService` | Feature read/write service | | `Uvc` | `FaceUvcService` | UVC and advanced parameter service | | `Encryption` | `FaceEncryptionService` | Encryption service | | `Callback` | `FaceModuleCallbackAdapter` | Callback-style API adapter | | `IsOpen` | `bool` | Whether the transport is open | | `IsReady` | `bool` | Whether READY has been received | | `CurrentStatus` | `FaceModuleStatus` | Current module status | | `LastError` | `string` | Latest error message | | `CurrentCommand` | `string` | Current command name | | `Config` | `FaceModuleConfig` | Current runtime config | | `Settings` | `FaceSdkSettings` | Bound settings asset | ### Methods | Method | Description | |---|---| | `ConfigureTransport(IFaceModuleTransport transport)` | Inject a custom transport | | `Configure(bool useMockInEditor, string portName, int baudRate)` | Quick configuration for legacy code | | `ApplySettings(FaceSdkSettings sdkSettings)` | Apply ScriptableObject settings and rebuild transport | | `Open()` | Open transport | | `Close()` | Close transport | | `WaitReadyAsync(int timeoutMs = 5000)` | Wait for READY note | | `ProbeReadyByStatusAsync()` | Query status and mark manager ready | | `SendRawBytes(byte[] bytes)` | Send raw protocol bytes | | `RefreshStatus()` | Asynchronously refresh `CurrentStatus` | ### Events | Event | Description | |---|---| | `OnReady` | First READY event | | `OnStatusChanged(FaceModuleStatus)` | Module status changed | | `OnReplyReceived(FaceReply)` | REPLY packet received | | `OnNoteReceived(FaceNote)` | NOTE packet received | | `OnFaceStateUpdated(FaceFaceStateNote)` | Face state NOTE received | | `OnQrCodeReceived(string)` | QR code NOTE received | | `OnFeatureReceived(byte[])` | Feature data packet received | | `OnDataPacketReceived(FacePacket)` | Image/template data packet received | | `OnError(FaceResultCode, string)` | Error reported | | `OnRawLog(string)` | Raw TX/RX log | ## Async Services ### FaceBasicService Access path: `manager.Basic` | Method | Return | Description | |---|---|---| | `ResetAsync()` | `Task` | Reset module | | `FaceResetAsync()` | `Task` | Cancel current face flow | | `GetStatusAsync()` | `Task` | Get module status | | `GetVersionAsync()` | `Task` | Get firmware version | | `GetSnAsync()` | `Task` | Get device serial number | | `SetDemoModeAsync(bool enable)` | `Task` | Set Demo Mode | | `UpgradeFirmwareAsync()` | `Task` | Start firmware upgrade command | ### FaceVerifyService Access path: `manager.Verify` | Method | Return | Description | |---|---|---| | `VerifyAsync(byte timeout, byte maxRecognitionTimes = 30)` | `Task` | Run one face verification | | `AutoVerifyAsync(bool enable, byte timeout)` | `Task` | Enable or disable automatic verification | ### FaceEnrollmentService Access path: `manager.Enrollment` | Method | Return | Description | |---|---|---| | `EnrollAsync(bool admin, string userName, FaceDirection direction, byte timeout)` | `Task` | Interactive multi-direction enrollment | | `EnrollSingleAsync(bool admin, string userName, byte timeout)` | `Task` | Single-frame enrollment | | `EnrollIntegratedAsync(bool admin, string userName, FaceDirection direction, byte timeout, bool singleFrame = false, bool duplicateCheck = true)` | `Task` | Integrated enrollment | | `EnrollSnapFaceImageAsync(bool admin, string userName)` | `Task` | Capture face image and enroll | ### FaceUserService Access path: `manager.Users` | Method | Return | Description | |---|---|---| | `DeleteUserAsync(int userId)` | `Task` | Delete a user | | `DeleteAllAsync()` | `Task` | Delete all users | | `GetUserInfoAsync(int userId)` | `Task` | Query one user | | `GetAllUserIdsAsync()` | `Task>` | Query all user IDs | | `GetAllUserIds2Async()` | `Task>` | Query all user IDs with extended command | | `GetAllUserInfosAsync()` | `Task>` | Query all user details | | `GetAllUserInfos2Async()` | `Task>` | Query all user details with extended command | ### FaceQrCodeService Access path: `manager.QrCode` | Method | Return | Description | |---|---|---| | `ScanQrCodeAsync(byte timeout)` | `Task` | Scan QR code and return content | ### FaceImageService Access path: `manager.Images` | Method | Return | Description | |---|---|---| | `SnapUploadImageAsync()` | `Task` | Capture normal image | | `SnapUploadFaceImageAsync()` | `Task` | Capture face image | | `SnapUploadLargeImageAsync(ImageDpi dpi)` | `Task` | Capture large image | | `EnrollWithPhotoAsync(byte[] photoBytes, BioType type, string userName = null, bool duplicateCheck = true, Action onProgress = null)` | `Task` | Enroll with photo | | `EnrollWithPhotoAndIdAsync(int userId, byte[] photoBytes, BioType type, string userName = null, bool duplicateCheck = true, Action onProgress = null)` | `Task` | Enroll photo with specified user ID | ### FaceFeatureService Access path: `manager.Features` | Method | Return | Description | |---|---|---| | `ReadFeatureAsync(int userId, FeatureType type)` | `Task` | Read user feature | | `WriteFeatureAsync(byte[] featureBytes, FeatureType type, string userName = null, Action onProgress = null)` | `Task` | Write feature and enroll | ### FaceUvcService Access path: `manager.Uvc` | Method | Return | Description | |---|---|---| | `ReadUsbUvcParametersAsync()` | `Task` | Read USB/UVC parameters | | `SetUsbUvcParametersAsync(UsbUvcParameters parameters)` | `Task` | Set USB/UVC parameters | | `SetFaceLocationDisplayAsync(bool visible)` | `Task` | Set face rectangle display | | `SetRgbLevelAsync(byte level)` | `Task` | Set RGB level | | `SetDuplicateCheckAsync(bool enableCheck)` | `Task` | Set duplicate check | | `ReadDuplicateCheckAsync()` | `Task` | Read duplicate check state | ### FaceEncryptionService Access path: `manager.Encryption` | Method | Return | Description | |---|---|---| | `SetReleaseEncryptionKeyAsync(byte[] key16)` | `Task` | Set release encryption key | | `SetDebugEncryptionKeyAsync(byte[] key16)` | `Task` | Set debug encryption key | | `InitEncryptionAsync(byte[] seed4, byte mode)` | `Task` | Initialize encryption | | `EnableEncryption(IFaceModuleCrypto crypto)` | `void` | Enable local crypto adapter | | `DisableEncryption()` | `void` | Disable local crypto adapter | ```csharp public interface IFaceModuleCrypto { byte[] Encrypt(byte[] plainBytes); byte[] Decrypt(byte[] encryptedBytes); byte[] GenerateSessionKey(byte[] seed4, byte[] encKey16); } ``` ## Callback API `FaceModuleManager.Callback` is useful for Unity UI, button events, legacy callback-style code, or workflows where `await` is inconvenient. Callbacks use a consistent pattern: - `success` is invoked on success. - `error` receives an error message on failure. - Photo enrollment and feature writing support `progress(current, total)`. - Callbacks are dispatched back to the Unity main thread through `FaceModuleMainThreadDispatcher`. ### Lifecycle and Transport | Method | Success Callback | Description | |---|---|---| | `ConfigureTransport(IFaceModuleTransport transport, Action success, Action error)` | `Action` | Inject custom transport | | `Configure(bool useMockInEditor, string portName, int baudRate, Action success, Action error)` | `Action` | Configure default transport parameters | | `Open(Action success, Action error)` | `Action` | Open transport | | `Close(Action success, Action error)` | `Action` | Close transport | | `SendRawBytes(byte[] bytes, Action success, Action error)` | `Action` | Send raw bytes | | `WaitReady(int timeoutMs, Action success, Action error)` | `Action` | Wait for READY | | `ProbeReadyByStatus(Action success, Action error)` | `Action` | Probe status and mark ready | ### Basic Commands | Method | Success Callback | Description | |---|---|---| | `Reset(Action success, Action error)` | `Action` | Reset module | | `FaceReset(Action success, Action error)` | `Action` | Cancel current face flow | | `GetStatus(Action success, Action error)` | `Action` | Get module status | | `GetVersion(Action success, Action error)` | `Action` | Get firmware version | | `GetSn(Action success, Action error)` | `Action` | Get device serial number | | `SetDemoMode(bool enable, Action success, Action error)` | `Action` | Set Demo Mode | | `UpgradeFirmware(Action success, Action error)` | `Action` | Start firmware upgrade | ### Verification and Enrollment | Method | Success Callback | Description | |---|---|---| | `Verify(byte timeout, Action success, Action error, byte maxRecognitionTimes = 30)` | `Action` | Run face verification | | `AutoVerify(bool enable, byte timeout, Action success, Action error)` | `Action` | Enable or disable auto verification | | `Enroll(bool admin, string userName, FaceDirection direction, byte timeout, Action success, Action error)` | `Action` | Interactive enrollment | | `EnrollSingle(bool admin, string userName, byte timeout, Action success, Action error)` | `Action` | Single-frame enrollment | | `EnrollIntegrated(bool admin, string userName, FaceDirection direction, byte timeout, bool singleFrame, bool duplicateCheck, Action success, Action error)` | `Action` | Integrated enrollment | | `EnrollSnapFaceImage(bool admin, string userName, Action success, Action error)` | `Action` | Capture face image and enroll | ### Users | Method | Success Callback | Description | |---|---|---| | `DeleteUser(int userId, Action success, Action error)` | `Action` | Delete user | | `DeleteAll(Action success, Action error)` | `Action` | Delete all users | | `GetUserInfo(int userId, Action success, Action error)` | `Action` | Query one user | | `GetAllUserIds(Action> success, Action error)` | `Action>` | Query all user IDs | | `GetAllUserIds2(Action> success, Action error)` | `Action>` | Query all user IDs with extended command | | `GetAllUserInfos(Action> success, Action error)` | `Action>` | Query all user details | | `GetAllUserInfos2(Action> success, Action error)` | `Action>` | Query all user details with extended command | ### QR Code, Images, and Features | Method | Success Callback | Description | |---|---|---| | `ScanQrCode(byte timeout, Action success, Action error)` | `Action` | Scan QR code | | `SnapUploadImage(Action success, Action error)` | `Action` | Capture normal image | | `SnapUploadFaceImage(Action success, Action error)` | `Action` | Capture face image | | `SnapUploadLargeImage(ImageDpi dpi, Action success, Action error)` | `Action` | Capture large image | | `EnrollWithPhoto(byte[] photoBytes, BioType type, string userName, bool duplicateCheck, Action success, Action error, Action progress = null)` | `Action` | Enroll with photo | | `EnrollWithPhotoAndId(int userId, byte[] photoBytes, BioType type, string userName, bool duplicateCheck, Action success, Action error, Action progress = null)` | `Action` | Enroll photo with specified user ID | | `ReadFeature(int userId, FeatureType type, Action success, Action error)` | `Action` | Read user feature | | `WriteFeature(byte[] featureBytes, FeatureType type, string userName, Action success, Action error, Action progress = null)` | `Action` | Write feature and enroll | ### UVC and Encryption | Method | Success Callback | Description | |---|---|---| | `ReadUsbUvcParameters(Action success, Action error)` | `Action` | Read USB/UVC parameters | | `SetUsbUvcParameters(UsbUvcParameters parameters, Action success, Action error)` | `Action` | Set USB/UVC parameters | | `SetFaceLocationDisplay(bool visible, Action success, Action error)` | `Action` | Set face rectangle display | | `SetRgbLevel(byte level, Action success, Action error)` | `Action` | Set RGB level | | `SetDuplicateCheck(bool enableCheck, Action success, Action error)` | `Action` | Set duplicate check | | `ReadDuplicateCheck(Action success, Action error)` | `Action` | Read duplicate check state | | `SetReleaseEncryptionKey(byte[] key16, Action success, Action error)` | `Action` | Set release encryption key | | `SetDebugEncryptionKey(byte[] key16, Action success, Action error)` | `Action` | Set debug encryption key | | `InitEncryption(byte[] seed4, byte mode, Action success, Action error)` | `Action` | Initialize encryption | | `EnableEncryption(IFaceModuleCrypto crypto, Action success, Action error)` | `Action` | Enable local crypto adapter | | `DisableEncryption(Action success, Action error)` | `Action` | Disable local crypto adapter | ## Main Models | Type | Description | |---|---| | `FaceReply` | REPLY packet parse result | | `FaceNote` | NOTE packet parse result | | `FaceFaceStateNote` | Face state NOTE | | `FaceUserInfo` | User ID, name, and admin flag | | `FaceVerifyResult` | Verification result, user info, unlock status | | `FaceEnrollResult` | Enrollment result, user ID, direction | | `FaceImageResult` | Image bytes, `Texture2D`, user ID | | `UsbUvcParameters` | USB/UVC parameters | | `FaceCommandException` | Exception thrown for unsuccessful command replies |