Ubuntu start camera as a service

Hi all,

I have a problem when trying to start camera as a service on Ubuntu 18.04. The service script is as follows:


[Unit]
Description=CVB service script
After=network-online.target
Requires=network-online.target
[Service]
ExecStart=/home/user/startCam.sh
[Install]
WantedBy=multi-user.target

The actual sh script:


#!/bin/bash
source /home/user/anaconda3/etc/profile.d/conda.sh
conda activate py37
python3.7 /home/user/script.py

And this crashes on:


vin_device = cvb.DeviceFactory.open(cvb.install_path() + 'drivers/GenICam.vin')

giving an error:


RunTimeError: {C-API call failed} ({LoadImageFile})

If I run the shell script “manually” everything works as expected, but fails when trying to start as a service on boot. Any ideas how to fix this?

Best regards,
G

Hi @gizzy,

have you made sure, that all services are already running?
Also the complete py script might be interesting, or at least break the python script down to the part that causes the error.

Usually you get the error you are seeing, when there is no camera configured, the camera is already in use, the path you try to load the driver from is wrong or you have a missmatch within x86 and x64 processes.

Maybe this might also be interesting for you

Dynamically find device
import cvb  

interface_flags = cvb.DiscoverFlags.UpToLevelInterface | cvb.DiscoverFlags.IgnoreGevSD 
all_interfaces = cvb.DeviceFactory.discover_from_root(interface_flags) 
broadcast_flags = cvb.DiscoverFlags.IgnoreVins | cvb.DiscoverFlags.IncludeInaccessible 
all_devices = [] 

for interface in all_interfaces: 
    cvb.DiscoveryInformation.set_genapi_feature(interface, "TLInterface", "DisableSubnetMatch", "1") 
    cvb.DiscoveryInformation.set_genapi_feature(interface, "TLInterface", "AllowBroadcastDiscoveryResponse", "1") 
    found_devices = cvb.DeviceFactory.discover_from_level(interface.access_token, broadcast_flags) 

    for dev in found_devices: 
        all_devices.append(dev) 

for dev in all_devices: 
    # Check devices access status etc.: 
    # dev.read_property(cvb.DiscoveryProperties.DeviceAccessStatus) 

with cvb.DeviceFactory.open(all_devices[0].access_token) as device: # open first camera found (check accessibility before!) 

    # work with camera... 

Cheers
Chris