darra-ethercat-master 0.5.0

Darra EtherCAT Master SDK - Rust 绑定 (封装 Darra.Core.dll/libDarraCore.so)
Documentation
//! 设备信息 API
//!
//! 对应 C# Static/DeviceInfo.cs
//! 提供设备序列号获取等功能。

use crate::utils::ffi;
use std::ffi::CStr;

/// 获取当前设备的序列号(用于授权验证)
///
/// 对应 C# DarraEtherCAT.GetSerialNumber()
pub fn get_serial_number() -> String {
    unsafe {
        let ptr = ffi::GetSerialNumber();
        if ptr.is_null() {
            return String::new();
        }
        match CStr::from_ptr(ptr).to_str() {
            Ok(s) => s.to_string(),
            Err(_) => String::new(),
        }
    }
}

/// 获取设备名称
///
/// 对应 C# DeviceNameHelper.GetDeviceName()
pub fn get_device_name() -> String {
    unsafe {
        let ptr = ffi::GetDeviceName();
        if ptr.is_null() {
            return String::new();
        }
        match CStr::from_ptr(ptr).to_str() {
            Ok(s) => s.to_string(),
            Err(_) => String::new(),
        }
    }
}

/// 获取用户邮箱
///
/// 对应 C# DeviceNameHelper.GetUserEmail()
pub fn get_user_email() -> String {
    unsafe {
        let ptr = ffi::GetUserEmail();
        if ptr.is_null() {
            return String::new();
        }
        match CStr::from_ptr(ptr).to_str() {
            Ok(s) => s.to_string(),
            Err(_) => String::new(),
        }
    }
}

/// 获取 Windows 产品密钥
///
/// 对应 C# DeviceNameHelper.GetWindowsProductKey()
pub fn get_windows_product_key() -> String {
    unsafe {
        let ptr = ffi::GetWindowsProductKey();
        if ptr.is_null() {
            return String::new();
        }
        match CStr::from_ptr(ptr).to_str() {
            Ok(s) => s.to_string(),
            Err(_) => String::new(),
        }
    }
}

/// 获取系统驱动列表
///
/// 对应 C# DeviceNameHelper.GetDriverList()
pub fn get_driver_list() -> String {
    unsafe {
        let ptr = ffi::GetDriverList();
        if ptr.is_null() {
            return String::new();
        }
        match CStr::from_ptr(ptr).to_str() {
            Ok(s) => s.to_string(),
            Err(_) => String::new(),
        }
    }
}