55
66
77class Rect (BaseModel ):
8- x : Annotated [int , Field (default = 0 , ge = 0 )]
9- y : Annotated [int , Field (default = 0 , ge = 0 )]
10- width : Annotated [int , Field (default = 0 , gt = 0 )]
8+ x : Annotated [int , Field (default = 0 , ge = 0 )]
9+ y : Annotated [int , Field (default = 0 , ge = 0 )]
10+ width : Annotated [int , Field (default = 0 , gt = 0 )]
1111 height : Annotated [int , Field (default = 0 , gt = 0 )]
1212
1313
1414class UEyeCamera (Thing ):
15-
1615 def get_aoi (self ) -> Rect :
1716 """Get current AOI from camera as Rect object (with x, y, width, height)"""
1817 rect_aoi = ueye .IS_RECT ()
19- ret = ueye .is_AOI (self .handle , ueye .IS_AOI_IMAGE_GET_AOI ,
20- rect_aoi , ueye .sizeof (rect_aoi ))
18+ ret = ueye .is_AOI (
19+ self .handle , ueye .IS_AOI_IMAGE_GET_AOI , rect_aoi , ueye .sizeof (rect_aoi )
20+ )
2121 assert return_code_OK (self .handle , ret )
2222 return Rect (
23- x = rect_aoi .s32X .value ,
24- y = rect_aoi .s32Y .value ,
25- width = rect_aoi .s32Width .value ,
26- height = rect_aoi .s32Height .value
27- )
23+ x = rect_aoi .s32X .value ,
24+ y = rect_aoi .s32Y .value ,
25+ width = rect_aoi .s32Width .value ,
26+ height = rect_aoi .s32Height .value ,
27+ )
2828
2929 def set_aoi (self , value : Rect ) -> None :
3030 """Set camera AOI. Specify as x,y,width,height or a tuple
@@ -35,69 +35,73 @@ def set_aoi(self, value: Rect) -> None:
3535 rect_aoi .s32Width = ueye .int (value .width )
3636 rect_aoi .s32Height = ueye .int (value .height )
3737
38- ret = ueye .is_AOI (self .handle , ueye .IS_AOI_IMAGE_SET_AOI ,
39- rect_aoi , ueye .sizeof (rect_aoi ))
38+ ret = ueye .is_AOI (
39+ self .handle , ueye .IS_AOI_IMAGE_SET_AOI , rect_aoi , ueye .sizeof (rect_aoi )
40+ )
4041 assert return_code_OK (self .handle , ret )
4142
42- AOI = Property (fget = get_aoi , fset = set_aoi , model = Rect ,
43- doc = "Area of interest within the image" ,) # type: Rect
43+ AOI = Property (
44+ fget = get_aoi ,
45+ fset = set_aoi ,
46+ model = Rect ,
47+ doc = "Area of interest within the image" ,
48+ ) # type: Rect
4449
4550
4651import ctypes
4752from picosdk .ps6000 import ps6000 as ps
4853from picosdk .functions import assert_pico_ok
4954
5055trigger_schema = {
51- ' type' : ' object' ,
52- ' properties' : {
53- ' enabled' : { ' type' : ' boolean' },
54- ' channel' : {
55- ' type' : ' string' ,
56- ' enum' : ['A' , 'B' , 'C' , 'D' , ' EXTERNAL' , ' AUX' ]
56+ " type" : " object" ,
57+ " properties" : {
58+ " enabled" : {" type" : " boolean" },
59+ " channel" : {
60+ " type" : " string" ,
61+ " enum" : ["A" , "B" , "C" , "D" , " EXTERNAL" , " AUX" ],
5762 # include both external and aux for 5000 & 6000 series
5863 # let the device driver will check if the channel is valid for the series
5964 },
60- ' threshold' : { ' type' : ' number' },
61- ' adc' : { ' type' : ' boolean' },
62- ' direction' : {
63- ' type' : ' string' ,
64- ' enum' : [' above' , ' below' , ' rising' , ' falling' , ' rising_or_falling' ]
65+ " threshold" : {" type" : " number" },
66+ " adc" : {" type" : " boolean" },
67+ " direction" : {
68+ " type" : " string" ,
69+ " enum" : [" above" , " below" , " rising" , " falling" , " rising_or_falling" ],
6570 },
66- 'delay' : { 'type' : 'integer' },
67- 'auto_trigger' : {
68- 'type' : 'integer' ,
69- 'minimum' : 0
70- }
71+ "delay" : {"type" : "integer" },
72+ "auto_trigger" : {"type" : "integer" , "minimum" : 0 },
7173 },
72- "description" : "Trigger settings for a single channel of the picoscope" ,
74+ "description" : "Trigger settings for a single channel of the picoscope" ,
7375}
7476
77+
7578class Picoscope (Thing ):
79+ trigger = Property (doc = "Trigger settings" , model = trigger_schema ) # type: dict
7680
77- trigger = Property (doc = "Trigger settings" ,
78- model = trigger_schema ) # type: dict
79-
8081 @trigger .setter
81- def set_trigger (self , value : dict ) -> None :
82+ def set_trigger (self , value : dict ) -> None :
8283 channel = value ["channel" ].upper ()
8384 direction = value ["direction" ].upper ()
8485 enabled = ctypes .c_int16 (int (value ["enabled" ]))
8586 delay = ctypes .c_int32 (value ["delay" ])
86- direction = ps .PS6000_THRESHOLD_DIRECTION [f'PS6000_{ direction } ' ]
87- if channel in ['A' , 'B' , 'C' , 'D' ]:
88- channel = ps .PS6000_CHANNEL ['PS6000_CHANNEL_{}' .format (
89- channel )]
87+ direction = ps .PS6000_THRESHOLD_DIRECTION [f"PS6000_{ direction } " ]
88+ if channel in ["A" , "B" , "C" , "D" ]:
89+ channel = ps .PS6000_CHANNEL ["PS6000_CHANNEL_{}" .format (channel )]
9090 else :
91- channel = ps .PS6000_CHANNEL [' PS6000_TRIGGER_AUX' ]
91+ channel = ps .PS6000_CHANNEL [" PS6000_TRIGGER_AUX" ]
9292 if not value ["adc" ]:
93- if channel in ['A' , 'B' , 'C' , 'D' ]:
94- threshold = int (threshold * self .max_adc * 1e3
95- / self .ranges [self .channel_settings [channel ]['v_range' ]])
93+ if channel in ["A" , "B" , "C" , "D" ]:
94+ threshold = int (
95+ threshold
96+ * self .max_adc
97+ * 1e3
98+ / self .ranges [self .channel_settings [channel ]["v_range" ]]
99+ )
96100 else :
97- threshold = int (self .max_adc / 5 )
101+ threshold = int (self .max_adc / 5 )
98102 threshold = ctypes .c_int16 (threshold )
99103 auto_trigger = ctypes .c_int16 (int (auto_trigger ))
100- self ._status [' trigger' ] = ps .ps6000SetSimpleTrigger (self . _ct_handle ,
101- enabled , channel , threshold , direction ,
102- delay , auto_trigger )
103- assert_pico_ok (self ._status [' trigger' ])
104+ self ._status [" trigger" ] = ps .ps6000SetSimpleTrigger (
105+ self . _ct_handle , enabled , channel , threshold , direction , delay , auto_trigger
106+ )
107+ assert_pico_ok (self ._status [" trigger" ])
0 commit comments