473,598 Members | 3,486 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.dl l")
def evCb(ev, clData, caData):
print "event: ", ev,"=>" , string_at(caDat a)

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.libCltAddEv entCallback(lib inf,"AllEvents" ,evfptr(evCb),0 )
result = c_char_p()
libbuf = raw_input("lib> ")
while libbuf != "quit":
lib.libCallComm and(libinf,libb uf,0,pointer(re sult))
print "result: ",result.va lue
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.dl l")
def evCb(ev,clData, caData):
print "event: ", ev,"=>" , string_at(caDat a)
libinf = lib.libCreate(0 )
lib.libConnect( libinf, 11060, 0,0)
evfptr = CFUNCTYPE(None, c_char_p, c_void_p,c_void _p)
lib.libCltAddEv entCallback(lib inf,"AllEvents" ,evfptr(evCb),0 )
result = c_char_p()
lib.libCallComm and(libinf,"som ecmd",0,pointer (result))
lib.libDestroy( libinf)
Dec 26 '07 #1
4 1756
En Wed, 26 Dec 2007 12:57:44 -0300, <di*******@gmai l.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...@gmai l.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.libCallComm and(libinf,libb uf,0,pointer(re sult))
print "result: ",result.va lue
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.a r>
wrote:
En Wed, 26 Dec 2007 12:57:44 -0300, <digitn...@gmai l.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 andinteractivem ode ?

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
1294
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 I have written a ptyhon extension module called jpype, and run the following code D:\>python
1
1743
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 session. Try using the excellent matplotlib package and you'll see my dilemma. Could another namespace could be added on the python search path, one that only held variables created by the user (as opposed to imported by modules)? Or does...
24
3126
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 Here's the compile command which seems to work well : -----------------------------------------------------
0
1051
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/ Even if you use the standard commandline tool, installing readline makes the basic command line a lot easier to use. (For some reason, I much prefer it to IDLE or any of the other GUI-wrapped
20
2436
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 just run scriptname.py (NOT python -i scriptname.py) and inside of scriptname.py I decide that I want to fall back to the interactive prompt? I've searched and so far the only thing I've come up with is to use pdb, but
2
7800
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 finding it a bit cumbersome. It works, but if I switch from the interactive window to the plot window and back, the plot window gets trashed.
1
3299
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. "When Python prompts for the next command with the primary prompt ">>> ", the interpreter is said to be in an interactive mode, or in a calculator mode. In interactive mode, the Python interpreter acts as a simple calculator: you can type an...
3
2404
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 think python is worse than perl
11
2590
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 ? I mean create some classes in Python and some number crunching algorithms coded in C (for speed) and integreate both of them. Could somebody just show a real small example or give pointers to the same.
0
7991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8265
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
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 we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.