Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > interactive mode in python with ctypes???

Reply
Thread Tools

interactive mode in python with ctypes???

 
 
digitnctu@gmail.com
Guest
Posts: n/a
 
      12-26-2007
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)
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-27-2007
En Wed, 26 Dec 2007 12:57:44 -0300, <(E-Mail Removed)> escribi:

> 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

 
Reply With Quote
 
 
 
 
digitnctu@gmail.com
Guest
Posts: n/a
 
      12-27-2007
On 1227, 4r40, "Gabriel Genellina" <(E-Mail Removed)>
wrote:
> En Wed, 26 Dec 2007 12:57:44 -0300, <(E-Mail Removed)> escribi:
>
> > 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.
 
Reply With Quote
 
ajaksu
Guest
Posts: n/a
 
      12-27-2007
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>")
 
Reply With Quote
 
digitnctu@gmail.com
Guest
Posts: n/a
 
      12-28-2007
On 1227, 10r05, (E-Mail Removed) wrote:
> On 1227, 4r40, "Gabriel Genellina" <(E-Mail Removed)>
> wrote:
>
>
>
> > En Wed, 26 Dec 2007 12:57:44 -0300, <(E-Mail Removed)> escribi:

>
> > > 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 ?



 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      12-28-2007
On Thu, 27 Dec 2007 23:59:18 -0800 (PST), http://www.velocityreviews.com/forums/(E-Mail Removed) declaimed
the following in comp.lang.python:


> 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 ?
>
>

What interactive environment are you running under? Opening a plain
command line shell and typing "python"? Running under IDLE's interactive
window? PythonWin's interactive window?

Note that you state this is a /callback/ function; as such it should
be called when some underlying code detects the event for which the
function is registered. Could it be that this underlying code does not
get to run when using interactive mode (perhaps because the interpreter
is blocked on a console read statement?) OR, more likely, looking at the
original post -- YOU are not giving the system time to react to anything
-- your "batch" version will block on a raw_input() call, which probably
will free up whatever underlying code triggers the callback. Your
"interactive" version creates AND DESTROYS the entire linkage at
whatever speed you can type them... Try stuffing a few time.sleep(5)
calls between each of the input statements... Or typing in what should
have been the first try:

import test
test.run(11060)
--
Wulfraed Dennis Lee Bieber KD6MOG
(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re: mmm-mode, python-mode and doctest-mode? John J Lee Python 0 08-07-2007 07:49 PM
re: mmm-mode, python-mode and doctest-mode? Edward Loper Python 0 08-07-2007 08:58 AM
Newbie: async mode dedicated versus async mode interactive!! Pink_Floyd Cisco 4 06-16-2006 12:16 AM
mmm-mode, python-mode and doctest-mode? John J Lee Python 3 12-01-2005 08:35 PM
is interactive mode same as calculator mode? Alex Python 1 09-09-2005 12:54 PM



Advertisments