Skip to content

Commit

Permalink
files to make python wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jblb committed Oct 24, 2014
1 parent f71903d commit f6b5216
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 0 deletions.
27 changes: 27 additions & 0 deletions artnet/HOWTO_PYTHON_WRAPPER
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from http://www.swig.org/tutorial.html

SWIG for the truly lazy
As it turns out, it is not always necessary to write a special interface file. If you have a header file, you can often just include it directly in the SWIG interface. For example:

%module example
%{
/* Includes the header in the wrapper code */
#include "header.h"
%}

/* Parse the header file to generate wrappers */
%include "header.h"



% swig -python artnet.i
% gcc -c artnet.c private.h misc.c network.c receive.c transmit.c tod.c artnet_wrap.c -I /usr/include/python2.7
% ld -shared artnet.o misc.o network.o receive.o transmit.o tod.o artnet_wrap.o -o _artnet.so


python usage

>>> import artnet
>>> verbose = 1
>>> node= artnet.artnet_new("192.168.5.181", verbose)

8 changes: 8 additions & 0 deletions artnet/artnet.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%module artnet
%{
/* Includes the header in the wrapper code */
#include "artnet.h"
%}

/* Parse the header file to generate wrappers */
%include "artnet.h"
115 changes: 115 additions & 0 deletions artnet/connectionArtnet.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"metadata": {
"name": "connectionArtnet"
},
"nbformat": 2,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": true,
"input": [
"import artnet"
],
"language": "python",
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def reply_handler(node_handler,i,j):",
" print (\"reply_handler \\n\")",
" "
],
"language": "python",
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"verbose = 1"
],
"language": "python",
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"node= artnet.artnet_new(\"192.168.5.181\", 1)"
],
"language": "python",
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print node"
],
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"_0031200a_p_void"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"artnet.artnet_set_short_name(node, \"jb node\")",
"artnet.artnet_set_long_name (node, \"le node de jb en python\")",
"artnet.artnet_set_node_type(node, artnet.ARTNET_SRV)",
"artnet.artnet_set_handler(node, artnet.ARTNET_REPLY_HANDLER, reply_handler, 0);",
"",
"artnet.artnet_start(node)"
],
"language": "python",
"outputs": [
{
"ename": "TypeError",
"evalue": "in method 'artnet_set_handler', argument 3 of type 'int (*)(artnet_node,void *,void *)'",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/home/jerome/Documents/Ola/libartnet-1.1.2/artnet/<ipython-input-12-ceb586fc01f1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0martnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0martnet_set_long_name\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"le node de jb en python\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0martnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0martnet_set_node_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0martnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mARTNET_SRV\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0martnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0martnet_set_handler\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0martnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mARTNET_REPLY_HANDLER\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreply_handler\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0martnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0martnet_start\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: in method 'artnet_set_handler', argument 3 of type 'int (*)(artnet_node,void *,void *)'"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"artnet.artnet_destroy(node)"
],
"language": "python",
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": true,
"input": [],
"language": "python",
"outputs": []
}
]
}
]
}
29 changes: 29 additions & 0 deletions artnet/connectionArtnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# <nbformat>2</nbformat>

# <codecell>

import artnet

# <codecell>

node= artnet.artnet_new("192.168.5.181", 1)

# <codecell>

print node

# <codecell>

artnet.artnet_set_short_name(node, "jb node")
artnet.artnet_set_long_name (node, "le node de jb en python")
artnet.artnet_set_node_type(node, artnet.ARTNET_SRV)
artnet.artnet_start(node)

# <codecell>

artnet.artnet_destroy(node)

# <codecell>


0 comments on commit f6b5216

Please sign in to comment.