473,500 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1742
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 12ÔÂ27ÈÕ, ÏÂÎç4•r40·Ö, "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 12ÔÂ27ÈÕ, ÏÂÎç10•r05·Ö, digitn...@gmail.com wrote:
On 12ÔÂ27ÈÕ, ÏÂÎç4•r40·Ö, "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1289
by: Steve Menard | last post by:
I have a strange problem with Python command-line interactive mode. Problem has been observed on every 2.3 version where it was tested, from 2.3 alpha to 2.3.4 Test is run on windows XP and 2000...
1
1740
by: Darren Dale | last post by:
Hello, I use Python for interactive data analysis, coming recently from Matlab. One thing I am missing is a variable browser. The problem with vars() is that it lists everything loaded in the...
24
3104
by: Jean-Baptiste PERIN | last post by:
Hi, I'm trying to make a windows dll reachable from a python script .. and I'm encountering troubles during link step .. I use "lcc" to compile and link I use python 2.3 under win XP ...
0
1041
by: David S. | last post by:
If you are using ipython on Windows then you will have made sure you have Gary Bishop's readline library as instructed in the ipython install directions found at: http://ipython.scipy.org/ ...
20
2417
by: Joe | last post by:
When you run "python -i scriptname.py" after the script completes you left at the interactive command prompt. Is there a way to have this occur from a running program? In other words can I...
2
7788
by: Charles Krug | last post by:
List: I'm trying to us pylab to see what I'm doing with some DSP algorithms, in case my posts about convolution and ffts weren't giving it away. I've been using pylab's plot function, but I'm...
1
3280
by: Alex | last post by:
Loking at Rossum's tutorial I've seen that he sometimes uses the expression "interactive mode" and sometimes "calculator mode". Or these concepts same? I've made the following assertion. ...
3
2396
by: Pankaj | last post by:
I am facing a very basic problem as any new bie would face. I know perl and now i want to use python In perl, it is very simple , just "perl scriptname.pl" will execute the script. But i...
11
2574
by: diffuser78 | last post by:
I was a C Programmer for a while. Lately started to learn Python for one small project at school. I joined a small company where they use C++ for development. Can we use Python and C together ?...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.