Crates.io | opc_da_bindings |
lib.rs | opc_da_bindings |
version | 0.1.2 |
source | src |
created_at | 2024-11-26 07:13:40.327005 |
updated_at | 2024-11-28 02:42:16.370326 |
description | OPC Data Access bindings |
homepage | |
repository | https://github.com/Ronbb/rust_opc |
max_upload_size | |
id | 1461288 |
size | 193,303 |
Please see docs on docs.rs.
use opc_da_bindings::{
CATID_OPCDAServer10, CATID_OPCDAServer20, CATID_OPCDAServer30, IOPCServerList,
};
use windows::Win32::System::Com::{
CLSIDFromProgID, CoCreateInstance, CoInitializeEx, ProgIDFromCLSID, CLSCTX_ALL,
COINIT_MULTITHREADED,
};
use windows_core::{w, Interface, GUID};
pub fn get_servers() -> Vec<String> {
unsafe { CoInitializeEx(None, COINIT_MULTITHREADED).unwrap() };
let id = unsafe { CLSIDFromProgID(w!("OPC.ServerList.1")).unwrap() };
let servers: IOPCServerList = unsafe { CoCreateInstance(&id, None, CLSCTX_ALL).unwrap() };
let enumer = unsafe {
servers
.EnumClassesOfCategories(
&[
CATID_OPCDAServer10::IID,
CATID_OPCDAServer20::IID,
CATID_OPCDAServer30::IID,
],
&[],
)
.unwrap()
};
let mut results = vec![];
loop {
let mut server_id = vec![GUID::zeroed(); 8];
let mut count = 0;
unsafe { enumer.Next(&mut server_id, Some(&mut count)).unwrap() };
if count == 0 {
break;
}
for i in 0..count {
let id = server_id[i as usize];
unsafe {
let id = ProgIDFromCLSID(&id).unwrap();
println!("ProgID: {}", id.to_string().unwrap());
results.push(id.to_string().unwrap());
}
}
}
results
}