I am having problems passing a pointer and uint8 to a .DLL. I have been successful registering call -backs with this .DLL. So it is all 32-bit and ctypes are working. Everything is working up to the line #set-up ProcessingIncomingSerialData. I tried the direct approach and then morphing the call-back style but yummy_thing is not so yummy... The python code is below..
The definition from the .DLL header is [cid:[email protected]] # Python code starts here..... ''' read_bat.py ''' from serial import * from string import * from time import * system_state = "G2G" ''' --- REMOVED Set-up the COMM port ---- print("Enter COM port number") user_comm_port = raw_input() try: dut_serial_port = Serial(port="COM"+user_comm_port, baudrate=115200, timeout=1) except: system_state = "FUBAR" print "Serial Port Problem" try: dut_serial_port.isOpen() print("COM" + user_comm_port + " is open") except: print "Serial Port Problem" system_state = "FUBAR" -------------------------------------------''' #Set-up and register cb_send_serial_data from ctypes import * pt_dll = CDLL("c:/py_stuff/ProductionTest.dll") SendSerialData_t = CFUNCTYPE(None, POINTER(c_uint8), c_uint8) reg_send_serial_data = pt_dll.RegSendSerialData reg_send_serial_data.argtypes = [SendSerialData_t] reg_send_serial_data.restype = None global new_serial_tx_data global new_serial_size def send_serial_data(tx_data, size): # testing print "tx_data = ", tx_data print "size = ", size print "tx_data[:size] = ", tx_data[:size] global new_serial_tx_data new_serial_tx_data = tx_data[:size] global new_serial_size new_serial_size = size cb_send_serial_data = SendSerialData_t(send_serial_data) global cb_send_serial_data reg_send_serial_data(cb_send_serial_data) print "reg_send_serial_data done" #Set-up and register cb_bat_vol_read #this triggers send_serial_data when it is registered. BatVolReadRequest_t = CFUNCTYPE(None, c_uint16, c_uint8) prod_bat_vol_read_request = pt_dll.ProdBatVolReadRequest prod_bat_vol_read_request.argtypes = [BatVolReadRequest_t] prod_bat_vol_read_request.restype = None def bat_vol_read(bat_vol, status): print "bat_vol_read()" # testing print bat_vol, status cb_bat_vol_read = BatVolReadRequest_t(bat_vol_read) prod_bat_vol_read_request(cb_bat_vol_read) print "prod_bat_vol_read_request done" ''' ------------REMOVED serial access for example ----- #push new_serial_tx_data out the serial port to the DUT. print new_serial_tx_data dut_serial_port.write(new_serial_tx_data) dut_serial_port.write("\r \n") sleep(1) #and check to see the DUT's reply... global new_serial_rx_data #new_serial_rx_data ="" global rx_buf rx_buf = [] try: string_buf = dut_serial_port.readline() except: system_state = "FUBAR" print "serial read problem" rx_buf = list(string_buf) print "string_buf = ", string_buf print "rx_buf = ", rx_buf -----------------------------------------------''' #set-up ProcessingIncomingSerialData print "breakpoint" class rx_data_t: def _init_(self): #self.ret = None self.data = [] self.size = '' fake_rx_data = rx_data_t() fake_rx_data.data = ['\x01', '\x05', '\x00', '\x1c', '\x00', '\x99', '\x0c', '\x04'] fake_rx_data.size = 8 print "fake_rx_data.data = ", fake_rx_data.data print "fake_rx_data.size = ", fake_rx_data.size ProcessIncomingSerialData_t = CFUNCTYPE(None, POINTER(c_uint8), c_uint16) process_incoming_serial_data = pt_dll.ProcessIncomingSerialData process_incoming_serial_data.argtypes = [ProcessIncomingSerialData_t] #process_incoming_serial_data.argtypes = [POINTER(c_uint8), c_uint16] process_incoming_serial_data.restype = None yummy_thing = ProcessIncomingSerialData_t(fake_rx_data)passing pointers to process_incoming_serial_data(yummy_thing) #process_incoming_serial_data(fake_rx_data) print "Done." print "system_state = ", system_state #print "Closing COM port", user_comm_port #dut_serial_port.close()
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
