Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create/instantiate and work with objects of compiled nodesets. #395

Open
degeable opened this issue Oct 29, 2024 · 1 comment
Open

Create/instantiate and work with objects of compiled nodesets. #395

degeable opened this issue Oct 29, 2024 · 1 comment

Comments

@degeable
Copy link

Hello,

I am trying to make use of the nodeset compiler but I got stuck at some things. This is related to #310

The first thing that seems off is the fact that I cant see the AutoId Device Types. I compiled DI and AutoID like this:

❯ node gen_nodeset.js --ns 2 --nodeset DI/Opc.Ua.Di.NodeSet2.xml --module di

❯ node gen_nodeset.js --ns 3 --nodeset Machinery/Opc.Ua.Machinery.NodeSet2.xml --module machinery

Then I added them to my server, following the approach in the README.

Now I do see the DI related nodes in the address space:
DI_softwareType_correct

But I cant see the device types from the AutoID:
AUTO_ID_missing_rfid

Here is the "correct" address space (open62541 server with the same nodesets loaded):
expectedAutoID

I could still manage to create an instance like this:

    let rifreader_type_id = NodeId::new(4, 1003);
    //...

    let instance = ObjectBuilder::new(&instance_node_id, "TestRFIDReaderDeviceType", "TestRFIDReaderDeviceType")
    .has_component(rifreader_type_id.clone())
    .event_notifier(EventNotifier::SUBSCRIBE_TO_EVENTS)
    .organized_by(NodeId::objects_folder_id())
    .insert(address_space);

But I cant write a variable or call a method. I managed to set a callback function but only if I add the method as a direct component of my RfidReader:

    let scan_method_id = NodeId::new(4, 7013);
    //...
    
    let instance = ObjectBuilder::new(&instance_node_id, "TestRFIDReaderDeviceType", "TestRFIDReaderDeviceType")
    .has_component(rifreader_type_id.clone())
    .has_component(scan_method_id.clone())
    .event_notifier(EventNotifier::SUBSCRIBE_TO_EVENTS)
    .organized_by(NodeId::objects_folder_id())
    .insert(address_space);
    
    address_space.register_method_handler(scan_method_id, Box::new(testMethod));
 
   // testMethod trait impl.
   
  struct testMethod;

impl callbacks::Method for testMethod {

    fn call(
        &mut self,
        _session_id: &NodeId,
        _session_map: Arc<RwLock<SessionManager>>,
        _request: &CallMethodRequest,
    ) -> Result<CallMethodResult, StatusCode> {
        println!("Scan method called");
        let message = format!("Hello from Scan!");
        Ok(CallMethodResult {
            status_code: StatusCode::Good,
            input_argument_results: None,
            input_argument_diagnostic_infos: None,
            output_arguments: Some(vec![Variant::from(message)]),
        })
    }
}

But this does not allow for the correct input/output arguments. I would need to use the MethodBuilder. But this doesn't work because the nodeId of this Method is already in the address space.

All this leads to the question, does this even work? Like can I load two nodesets to the server, create instances of objects and then write variables and call methods with my own callback AND the correct input and output arguments?

Any input on this is appreciated! Thank you.

@evanjs
Copy link

evanjs commented Jan 20, 2025

Yes, this is possible, and I am doing so in a project utilizing this repository at the moment

Unfortunately, it's for a closed source project, so it's a little harder to share examples right away.

That being said, I came across this comment just now, and I am wondering if/how @einarmo's fork provides easier ways to accomplish these goals

Per the README:

We have basic support for custom structures.

But I have not had time to look into it yet

If anything, perhaps we could consider copying this ticket to the fork if the basic support provided seems insufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants