Class: OPCUA::Client::cMethodNode

Inherits:
cNode
  • Object
show all
Defined in:
ext/opcua/client/client.c

Instance Method Summary collapse

Methods inherited from cNode

#id, #to_s, #unsubscribe

Instance Method Details

#call(*args) ⇒ Object

{{{



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'ext/opcua/client/client.c', line 508

static VALUE node_call(int argc, VALUE* argv, VALUE self) { //{{{
  node_struct *ns;
  UA_StatusCode retval;

  VALUE splat;
  rb_scan_args(argc, argv, "*", &splat);

  Data_Get_Struct(self, node_struct, ns);

  UA_NodeId parent;
  if (!client_node_get_reference_by_type(ns->master->master, ns->id, UA_NODEID_NUMERIC(0,UA_NS0ID_HASCOMPONENT), &parent, true)) {
    if (!client_node_get_reference_by_type(ns->master->master, ns->id, UA_NODEID_NUMERIC(0,UA_NS0ID_HASORDEREDCOMPONENT), &parent, true)) {
      rb_raise(rb_eRuntimeError, "Cant find parent node, neither hascomponent nor hasorderedcomponent is there!");
    }
  }

  UA_NodeId ia;
  client_node_get_reference_by_name(ns->master->master, ns->id, UA_QUALIFIEDNAME(0,"InputArguments"), &ia, false);
  UA_Variant iaval;
  UA_Variant_init(&iaval);
  UA_Client_readValueAttribute(ns->master->master, ia, &iaval);

  UA_UInt32 proposal[RARRAY_LEN(splat)];
  for (int i=0; i < iaval.arrayLength; i++) {
    UA_ExtensionObject* eoarg= (UA_ExtensionObject *)(iaval.data);
    UA_Argument* arg = (UA_Argument *)(eoarg[i].content.decoded.data);

    if (arg->dataType.namespaceIndex == 0) {
		  proposal[i] = arg->dataType.identifier.numeric - 1; // what a dirty hack TODO, translate node to value
    }
  }

  UA_Variant inputArguments[RARRAY_LEN(splat)];
  for (long i=0; i<RARRAY_LEN(splat); i++) {
    value_to_variant(RARRAY_AREF(splat, i),&inputArguments[i],proposal[i]);
  }

  size_t outputSize;
  UA_Variant *output;

  retval = UA_Client_call(
    ns->master->master,
    parent,
    ns->id,
    RARRAY_LEN(splat),
    (UA_Variant *)&inputArguments,
    &outputSize,
    &output
  );

  if (retval == UA_STATUSCODE_GOOD && outputSize > 0) {
    VALUE ret = rb_ary_new2(outputSize);
    for (int i=0; i<outputSize; i++) {
      rb_ary_store(ret,i,rb_ary_entry(extract_value(output[i]),0));
    }
    return rb_ary_entry(ret,0);
  } else {
    return Qnil;
  }
}