3 releases
0.1.2 | Nov 28, 2024 |
---|---|
0.1.1 | Nov 26, 2024 |
0.1.0 | Nov 26, 2024 |
#421 in HTTP server
398 downloads per month
195KB
5.5K
SLoC
OPC DA Bindings
Please see docs on docs.rs.
Example
Enumerate server list
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
}
Dependencies
~128MB
~2M SLoC