Help: SWIG & Ruby

  • Thread starter Sebastian yepes Sebastian [esn]
  • Start date
S

Sebastian yepes Sebastian [esn]

Hi All,

I need some help with SWIG and Ruby, I am trying to use some C functions
in ruby.
I have just started with SWIG and have been reading the manual en posts
around the net, but I have not been able to get this to work properly,
here are some if the questions I have:


- When I run opc_connect why isn’t “conn_id†assigned any reference?

- What’s wrong with the “%apply int *INOUT…â€, when I run opcif_open,
“if_id†does not get any reference?

- How do I work with the typedefs “typedef void * XX†in ruby?, when I
run opcdata_create, the variable data should get some data or
referenced?

- Is it necessary to create some custom typemaps to make this work?

Any help or example would be appreciated, thanks in advanced for the
help.





ruby Test.rb (OUTPUT)
-----------
TEST: opc_connect
RC: -20 / ID: <<<-- ???
TEST: opcif_open
TYPE: 4 / MODE: 24 / ID: <<<-- ???
RC: -21 / TYPE: 4 / MODE: 24 / ID: <<<-- ???
TEST: opcdata_create
RC: -21 / DATA: <<<-- ???

Test.rb
--------------------------------------
require 'api'
include Api

puts "TEST: opc_connect\n"
conn_id = nil
rc_conn = opc_connect("opc_adm", "OpC_adm", conn_id)
puts "\tRC: #{rc_conn} / ID: #{conn_id}\n"

puts "TEST: opcif_open\n"
if_type = 4
if_name = "SEBASTST"
if_mode = 24
if_id = nil

print "\tTYPE: #{if_type} / MODE: #{if_mode} / ID: #{if_id}\n"
rc_open = opcif_open(if_type, if_name, if_mode, 0, if_id)
print "\tRC: #{rc_open} / TYPE: #{if_type} / MODE: #{if_mode} / ID:
#{if_id}\n"

puts "TEST: opcdata_create\n"
data = nil
rc_data = opcdata_create(0 , data)
puts "\tRC: #{rc_data} / DATA: #{data}\n"
------------------------------



Interface file:
-------------------
%module api

%inline %{
#include "api.h"
%}

%include typemaps.i
%apply int *INOUT { int *interface_id };
--------------------


api.h
--------------------
#define OPCAPI
#define OPCLIBAPI extern

typedef void * opcdata;
typedef void * opcregcond;
typedef void * opc_connection;
typedef void * opc_iterator;
typedef int pipe_handle;
typedef pipe_handle *p_pipe_handle;

OPCLIBAPI int OPCAPI opc_connect (
const char *operator_name,
const char *operator_pwd,
opc_connection *opc_conn );

OPCLIBAPI int OPCAPI opcif_open (
int interface_type,
const char *instance,
int mode,
int max_entries,
int *interface_id );

OPCLIBAPI int OPCAPI opcdata_create (
int data_type,
opcdata *data );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top