tiagocoutinho / linuxpy

Human friendly interface to linux subsystems using python
https://tiagocoutinho.github.io/linuxpy/
GNU General Public License v3.0
33 stars 5 forks source link

How to set values dynamically or during runtime?? #18

Closed Dipankar1997161 closed 3 months ago

Dipankar1997161 commented 4 months ago

I have passed a json file with predefined values of the control settings which works fine. but now few of the settings I wish to run dynamicaly or change under cli or other arguments. Is that actually possible?

Is there a way to activate the flags since it returned 'inactive' ERROR:

   Control value: IntegerControl  focus_absolute min=0 max=1023 step=1 default=0 value=160 flags=inactive focus_absolute
Traceback (most recent call last):
  File "/home/dipankar/Desktop/Camera_test/camera_operator_new.py", line 142, in <module>
    co.saveImg(imgindex=0)
  File "/home/dipankar/Desktop/Camera_test/camera_operator_new.py", line 117, in saveImg
    self.SetCamParams(cam)
  File "/home/dipankar/Desktop/Camera_test/camera_operator_new.py", line 37, in SetCamParams
    cam.controls[cval].value = controlvals[cval]
  File "/home/dipankar/miniconda3/envs/camera_test/lib/python3.10/site-packages/linuxpy/video/device.py", line 998, in value
    self._set_control(v)
  File "/home/dipankar/miniconda3/envs/camera_test/lib/python3.10/site-packages/linuxpy/video/device.py", line 899, in _set_control
    raise AttributeError(f"{self.__class__.__name__} {self.config_name} is not writeable: {', '.join(reasons)}")
AttributeError: IntegerControl focus_absolute is not writeable: inactive

CODE:

if __name__ == "__main__":

parser = argparse.ArgumentParser(description="Camera Control Script")
parser.add_argument("--exposure", type=int, help="Set exposure time in microseconds")
parser.add_argument("--focus", type=int, help="Set focus absolute value")
args = parser.parse_args()

co = CamControl()
print("End of Initialization")

for cam in co.cams:
    if args.exposure is not None:
        co.setExposureTime(cam, args.exposure)
    if args.focus is not None:
        co.setFocusAbsolute(cam, args.focus)

def setExposureTime(self, cam, exposure_time):
  cam.controls['exposure_time_absolute'].value = exposure_time
  print(f"Setting exposure_time_absolute to {exposure_time}")

def setFocusAbsolute(self, cam, focus_absolute):
    cam.controls['focus_absolute'].value = focus_absolute
    print(f"Setting focus_absolute to {focus_absolute}")

Thank you in advance

tiagocoutinho commented 3 months ago

I think this is a bug. I thought I fixed it before. It should be possible to set the value of an inactive control. I'll make a PR to fix

tiagocoutinho commented 3 months ago

It should be fixed in master Also on the new 0.12.0 available on pypi

Dipankar1997161 commented 3 months ago

We are able to set values to the variables where the flags are inactive. For that, one has to first change the mode to Manual Mode before setting the values