Python Forum
Picamera2 commands between modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Picamera2 commands between modules
#1
Hi all, please be patience, I'm a newbie
I started to write a simple program to allow comunication and control between App Inventor and Python on RPi4 with Camera, via Bluetooth.
Comunication seems to work just fine. Now, I'm facing with variables implementation issues. Basically, I have a glvars.py file:
from picamera2 import Picamera2, Preview

# Camera init
cam = Picamera2()
camera_config = cam.create_preview_configuration()
cam.configure(camera_config)
cam.start_preview(Preview.DRM, x=0, y=0, width=1024, height=600)
cam.start()
cam.stop_preview()
for 'global' variables (I'm not sure this is a good or bad idea) and a myModules.py file with:
import glvars

def camExec(*args): # Camera commands
    clientSock = args[0]
    cmd = args[1]
    # line with Picamera2 commands follows
my App Inventor app send strings to RPi via bluetooth and the running python scripts should interpret these strings as Picamera2 commands. For example, if I send the string 'start_preview(True)' (cmd = args[1] variable above), the resulting command for Picamera2 should be:
    glvars.cam.start_preview(True)
that works just fine, but
glvars.cam.cmd
doesn't.
EDIT:
def camExec(*args): # Camera commands
    clientSock = args[0]
    cmd = args[1]
    # glvars.cam.start_preview(True) # works
    return getattr(glvars.cam, cmd)
give me the error:
AttributeError: 'Picamera2' object has no attribute 'start_preview(True)'
I tried several string formatting methods but no success. How should I format the final command line in Python?
Thanks
Reply


Messages In This Thread
Picamera2 commands between modules - by GigiG - Apr-30-2025, 11:16 AM
RE: Picamera2 commands between modules - by GigiG - May-05-2025, 09:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 4,507 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 10,203 May-25-2017, 08:15 AM
Last Post: wavic
  import commands modules not working in python 3.6.0 bmohanraj91 2 19,739 May-01-2017, 10:59 AM
Last Post: bmohanraj91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020