darra-ethercat-master 2.7.0

Commercial EtherCAT master protocol stack, real-time kernel driver integration, Windows and Linux support, multi-language SDKs, complex topology and hot-plug support.
Documentation

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

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(),
        }
    }
}

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(),
        }
    }
}

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(),
        }
    }
}

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(),
        }
    }
}

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(),
        }
    }
}