471,354 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

interactive mode in python with ctypes???

Dear all:

I am coming with problem, to apply ctypes under interactive mode
in python.

libdll.dll is a third-party library. The below code segment will
run well under the batch mode(ie. python test.py 11060)
but when I type sequencially it doesn't work as usual. Can any
give me a hand??

# file test.py begin
from ctypes import *
lib = CDLL("libdll.dll")
def evCb(ev, clData, caData):
print "event: ", ev,"=>" , string_at(caData)

def run(port):
libinf = lib.libCreate(0)
lib.libConnect(libinf,port,0,0)
evfptr = CFUNCTYPE(None,c_char_p, c_void_p,c_void_p)
lib.libCltAddEventCallback(libinf,"AllEvents",evfp tr(evCb),0)
result = c_char_p()
libbuf = raw_input("lib>")
while libbuf != "quit":
lib.libCallCommand(libinf,libbuf,0,pointer(result) )
print "result: ",result.value
if libbuf == "Exit":
break
libbuf = raw_input("lib>")
lib.libDestroy(libinf)
if __name__ == "__main__":
import sys,string
run(string.atoi(sys.argv[1]))
# file test.py end

I type in interactive mode of python as below:

from ctypes import *
lib = CDLL("libdll.dll")
def evCb(ev,clData,caData):
print "event: ", ev,"=>" , string_at(caData)
libinf = lib.libCreate(0)
lib.libConnect(libinf, 11060, 0,0)
evfptr = CFUNCTYPE(None,c_char_p, c_void_p,c_void_p)
lib.libCltAddEventCallback(libinf,"AllEvents",evfp tr(evCb),0)
result = c_char_p()
lib.libCallCommand(libinf,"somecmd",0,pointer(resu lt))
lib.libDestroy(libinf)
Dec 26 '07 #1
4 1650
En Wed, 26 Dec 2007 12:57:44 -0300, <di*******@gmail.comescribi:
libdll.dll is a third-party library. The below code segment will
run well under the batch mode(ie. python test.py 11060)
but when I type sequencially it doesn't work as usual. Can any
give me a hand??
Define "doesn't work as usual"; at least describe what actually happens
and what you expected to happen instead. If you get an exception, post the
full traceback.
run(string.atoi(sys.argv[1]))
string.atoi is deprecated eons ago; use int() instead

--
Gabriel Genellina

Dec 27 '07 #2
On 1227, 4r40, "Gabriel Genellina" <gagsl-....@yahoo.com.ar>
wrote:
En Wed, 26 Dec 2007 12:57:44 -0300, <digitn...@gmail.comescribi:
libdll.dll is a third-party library. The below code segment will
run well under the batch mode(ie. python test.py 11060)
but when I type sequencially it doesn't work as usual. Can any
give me a hand??

Define "doesn't work as usual"; at least describe what actually happens
and what you expected to happen instead. If you get an exception, post the
full traceback.
run(string.atoi(sys.argv[1]))

string.atoi is deprecated eons ago; use int() instead

--
Gabriel Genellina
"doesn't work" means there is no result without exception. The python
interpretter still run without complains; but when running under batch
mode it run as the expectation. Are there difference for python
interpretter between batch mode and interactive mode ?

Thanks for Gabriel.
Dec 27 '07 #3
You should get it to work with this loop (from run()):
while libbuf != "quit":
lib.libCallCommand(libinf,libbuf,0,pointer(result) )
print "result: ",result.value
if libbuf == "Exit":
break
libbuf = raw_input("lib>")
Dec 27 '07 #4
On 1227, 10r05, digitn...@gmail.com wrote:
On 1227, 4r40, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Wed, 26 Dec 2007 12:57:44 -0300, <digitn...@gmail.comescribi:
libdll.dll is a third-party library. The below code segment will
run well under the batch mode(ie. python test.py 11060)
but when I type sequencially it doesn't work as usual. Can any
give me a hand??
Define "doesn't work as usual"; at least describe what actually happens
and what you expected to happen instead. If you get an exception, post the
full traceback.
run(string.atoi(sys.argv[1]))
string.atoi is deprecated eons ago; use int() instead
--
Gabriel Genellina

"doesn't work" means there is no result without exception. The python
interpretter still run without complains; but when running under batch
mode it run as the expectation. Are there difference for python
interpretter between batch mode andinteractivemode ?

Thanks for Gabriel.
sorry, I explain more precisely.
"No result" means the callback function evCB will not be called as
it in batch mode.
For callback function, are there difference for python interpretter
between batch and interactive mode ?

Dec 28 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Darren Dale | last post: by
24 posts views Thread by Jean-Baptiste PERIN | last post: by
reply views Thread by David S. | last post: by
20 posts views Thread by Joe | last post: by
2 posts views Thread by Charles Krug | last post: by
1 post views Thread by Alex | last post: by
11 posts views Thread by diffuser78 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.