darra-ethercat-master 2.0.5

商业 EtherCAT 主站协议栈 · 实时内核驱动 · 抖动 1µs · Windows + Linux · 多编程语言 · 全协议 · 支持复杂拓扑 + 热插拔 · ethercat.darra.xyz · Commercial EtherCAT Master protocol stack · Real-time kernel driver · 1µs jitter · Multi-platform · Multi-language · Complex topology + hot-plug.
//! 设备信息 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(),
        }
    }
}