Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem running functions from a DLL file using ctypes in Object-oriented Python
    text
    copied!<p>I sure hope this won't be an already answered question or a stupid one. Recently I've been programming with several instruments. Trying to communicate between them in order to create a testing program. However I've encoutered some problems with one specific instrument when I'm trying to call functions that I've "masked" out from the instruments DLL file. When I use the interactive python shell it works perfectly (although its alot of word clobbering). But when I implement the functions in a object-oriented manner the program fails, well actually it doesn't fail it just doesn't do anything. This is the first method that's called: (ctypes and ctypes.util is imported)</p> <pre><code> def init_hardware(self): """ Inits the instrument """ self.write_log("Initialising the automatic tuner") version_string = create_string_buffer(80) self.error_string = create_string_buffer(80) self.name = "Maury MT982EU" self.write_log("Tuner DLL path: %s", find_library('MLibTuners')) self.maury = WinDLL('MlibTuners') self.maury.get_tuner_driver_version(version_string) if (version_string.value == ""): self.write_log("IMPORTANT: Error obtaining the driver version") else: self.write_log("Version number of the DLL: %s" % version_string.value) self.ThreeTypeLong = c_long * 3 </code></pre> <p>Now that works swell, everything is perfect and I get perfect log-entries. But when I try to run a method further into the program called:</p> <pre><code>def add_tuner_and_controller(self, name, serial_number, tuner_number=0): """ Adds the tuner to the driver object, controller is inside the tuner """ self.write_log("Adding tuner %d and the built-in controller" % tuner_number) TempType = self.ThreeTypeLong() self.maury.add_controller(c_short(tuner_number), c_char_p(self.file_path), c_char_p(name), c_int(0), c_int(0), c_long(0), c_short(serial_number), self.error_string) self.maury.add_tuner(c_short(tuner_number), c_char_p(name), c_short(serial_number), c_short(0), c_short(1), pointer(c_double()), TempType, pointer(c_double()), pointer(c_double()), pointer(c_double()), self.error_string) </code></pre> <p>The program suddenly stops working/keeps running , nothing happenes when the "self.maury"-line is called. When I place everything in the init_hardware method it works perfectly so I'm guessing there's a slight memory "error" or something with the objective oriented structure. I really want it to remain this way, is there anyway to isolate the functions in this manner? or do I have to restrict myself to a big chunk of code?</p> <hr> <p><strong>EDIT:</strong><br> <em>Documentation info</em>:<br> [Legend: The stars indicate pointers and the brackets indicate arrays]</p> <p><strong>The add_tuner function adds or updates one tuner in the tuner driver object.</strong></p> <pre><code>short add_tuner(short tuner_number, char model[ ], short serial_number, short ctlr_num, short ctlr_port, short *no_of_motors, long max_range[ ], double *fmin, double *fmax, double *fcrossover, char error_string[ ]) </code></pre> <p><strong>Output</strong>: <code>no_motors, max_range (array of three numbers), fmin, fmax, fcrossover,error_string (80+ characters long), function-return-&gt;Error flag</code></p> <p><br> <br> <strong>The add_controller function adds or updates one controller in the tuner driver object</strong></p> <pre><code>short add_controller(short controller_number, char driver[ ], char model[ ], int timeout, int address, long delay_ms, char error_string[ ]) </code></pre> <p><strong>Output</strong>: <code>error_string, function-return-&gt;Error flag</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload