Home > OS >  ctypes.ArgumentError: argument 10: <class 'TypeError'>: expected LP_c_double instanc
ctypes.ArgumentError: argument 10: <class 'TypeError'>: expected LP_c_double instanc

Time:12-06

I use the a_in_scan function as exposed in the uldaq library (I marked the point where I use it so it should be easy to find)

import wx
from PIL import Image
import matplotlib.pyplot as pyplot
import uldaq
import time
from decimal import Decimal

main_sizer = wx.FlexGridSizer(2, 3, 10, 10)
num = []
out=[]
for x in range(100):
    num.append(x)
    out.append(0)
pool = uldaq.get_daq_device_inventory(7)
my_daq = uldaq.DaqDevice(pool[0])
my_daq.connect()
I_channell = my_daq.get_ai_device()
out = []
class MyGrid(wx.Panel):
    
    def __init__(self, parent):
        super().__init__(parent)
        dlg = wx.TextEntryDialog(None, "inserisci Vrms")
        dlg.ShowModal()
        p = float(dlg.GetValue())
        attendance_pos = []
        attendance_neg = [] 
        for x in range(100):
            attendance_pos.append(p)
            attendance_neg.append(-p)
        pyplot.plot(num, attendance_pos, color = 'blue', label = 'Attendance')
        pyplot.plot(num, attendance_neg, color = 'blue', label = 'Attendance')
        pyplot.legend(loc='upper left', frameon=True)
        
        button = wx.Button(self, label='Press Me')
        button.Bind(wx.EVT_BUTTON, self.on_button1)
        
        self.staticbitmap = wx.StaticBitmap(self)
        main_sizer.Add(self.staticbitmap, 1, wx.EXPAND)
        main_sizer.Add(button, flag=wx.LEFT)
        self.SetSizer(main_sizer)
    def on_button1(self, event):
        prova = [2.3,5.4]
 ->     I_channell.a_in_scan(0,0,2,5,200,50000,0,0,prova)
        pyplot.plot(num, out, color = 'green', label = 'Marks')
        url = "prova.png"
        pyplot.savefig(url)
        self.staticbitmap.SetBitmap(wx.Bitmap(url))
class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title='Hello World')
        panel = MyGrid(self)
        self.Show()
if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MyFrame()
    app.MainLoop()

last parameter should be an "Array[float]" so I thought that just creating an empty array would be ok but apparently is not. I also tried different things like using a matrix and (following the suggestion in the "data" section of https://www.mccdaq.com/PDFs/Manuals/UL-Linux/python/api.html#uldaq.AiDevice.a_in_scan) to use the "create_float_buffer()" function which should be a global method but when I tried to use it as

out = create_float_buffer(1,200)

it says the function is not defined:

NameError: name 'create_float_buffer' is not defined

finally I also tried using

I_channell.a_in_scan(0,0,2,5,200,50000,0,0,ctypes.c_double(out))

and in that case the error is

TypeError: must be real number, not list

any idea on how to solve this problem?

CodePudding user response:

It is a global function, but global to the uldac module. Use:

out = uldac.create_float_buffer(1, 200)
  • Related