Hi AG. I guess the attachment py_cb.7z was stripped. The statement below is 
correct, I am trying to register a Python function as the Callback 
(Confirmation)
For a C++ function in the .dll. When I register the call-back with 
prod_bat_vol_read_request I should get a machine readable 'token' from 
send_serial_data.tx_data. I send this token to the battery tester to start it. 
When the test is done, my_conf_func should be triggered.
The code is in line below. 

Section 15.17.1.17 is in the 2.6/library docs see the URL in the comments 
below. 

I tried several different ways without success. 

Thanks for your advice. 

Pete


#*********************************************************************************
''' bat_read_15_17_1_17
this program is attempting ot register a call back function the 
ProductionTest.dll
using the techniques outlined in section 15.17.1.17 of the python docs
https://docs.python.org/2.6/library/ctypes.html#module-ctypes
'''

'''open and register SendSerialData
this part looks like it's working
'''

from ctypes import *
pt_dll = pt_dll = cdll.LoadLibrary("c:/py_stuff/ProductionTest.dll")
reg_send_serial_data = pt_dll.RegSendSerialData
class SendSerialData_t(Structure):
    _fields_ = [("tx_data", c_void_p),
                ("size", c_uint8)]
send_serial_data = SendSerialData_t()
try:
    reg_send_serial_data(send_serial_data)
except:
    print "reg_send_serial_data fail"
    
print send_serial_data.tx_data
print send_serial_data.size

'''set up ProdBatVolRequest and register my_conf_func as the call back
this is NOT working.
'''

prod_bat_vol_read_request = pt_dll.ProdBatVolReadRequest

#MY_FUNC = CFUNCTYPE(None, POINTER(c_uint16),POINTER(c_uint8))
#MY_FUNC = CFUNCTYPE(None, c_uint16,c_uint8)
MY_FUNC = CFUNCTYPE(c_uint16,c_uint8)
#MY_FUNC = WINFUNCTYPE(c_uint16,c_uint8)
#MY_FUNC = WINFUNCTYPE(None, POINTER(c_uint16),POINTER(c_uint8))

def my_conf_func(bat_vol, status):
        print "my_conf_func", bat_vol, status
        #return 0

conf_func = MY_FUNC(my_conf_func)

print "breakpoint"

#prod_bat_vol_read_request(conf_func)

#prod_bat_vol_read_request(my_conf_func)

#prod_bat_vol_read_request(POINTER(my_conf_func)) 

#**************************************************************************


> -----Original Message-----
> From: Tutor [mailto:tutor-bounces+pete.wilson=atmel....@python.org] On
> Behalf Of Alan Gauld
> Sent: Thursday, October 16, 2014 5:24 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Registering callbacks and .DLL
> 
> On 17/10/14 00:35, Wilson, Pete wrote:
> > I'm having problems registering a call-back with a .DLL. Maybe
> someone
> > has some advice on registering call-backs from .dlls.
> >
> > I'm using Windows 7 and Python 2.6 (32-bits). The .DLL was written in
> > C++ is working with C++ apps calling it.
> 
> OK As I understand it, You are trying to register a Python function as
> a call back on a C++ function in a DLL is that correct?
> 
> Do you have any code? I don't see any attachment. Many lists/servers
> strip out binary attachments as potential viruses so it may not have
> made it through. Code is best included inline as text provided its not
> too long, or alternatively, in a pastebin.
> 
> > I tried the methods in section 15.17.1.17 with the qsort() and
> > CFUNCTYPE, but it is not working.  My code and the .dll are attached.
> 
> Section 15.17.1.17 of what? Not the tutorial, not the library reference
> and not the language reference. So what?
> 
> This question may be a tad too complex for the tutor list which is
> targeted to those learning Python, you probably want the main list for
> this. But you are going to have to provide some code and a more
> detailed description of what you are trying to do.
> 
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to