Bin/bash - xmessage very slow

Hello,

I am showing the start of my script.
I am finding that 'xmessage' is taking about 12-15 seconds to show.
This in a terminal is very quick '/opt/vc/bin/vcgencmd get_camera'.
Is there any way to get 'camera not detected' to show faster.

Regards

#!/bin/bash

s=$(/opt/vc/bin/vcgencmd get_camera)
sb="supported=1 detected=1"
case $sb in
$s)
echo "Camera detected"
;;
*)
xmessage "Camera not detected !" -buttons ok
exit 1
;;
esac

It isn't xmessage nor bash that is taking so long, it is vcgencmd . With the path that you are using to invoke that command, we have to assume that this command is not a standard part your operating system and has been installed from a third party vendor or written by someone at your company.

Do you have a manual page for this utility? If so, does it saying anything about options or configuration parameters to shorten the time allowed for a device to respond to a probe?

Have you tried the commands:

/opt/vc/bin/vcgencmd -h

and:

/opt/vc/bin/vcgencmd -"?"

to see if there are any built-in help messages that might tell you?

If there is an option or configuration value that can be used to shorten the timeout that program uses before deciding that no camera is connected to your system, note that you may get false negatives if you shorten the time too much. Some devices take a while to warm up and be able to respond when they are probed. And, if the camera you're probing is a device that is accessed through a network (i.e., not directly attached to your computer), network delays can exacerbate any delays imposed by the device itself.

Hello,

Thanks for your reply.
I started my script by a different method and got a warning message.

Warning: Missing charsets in String to FontSet conversion

This I cured for the moment by adding 'LANG=C' before the call to xmessage.

#!/bin/bash

s=$(/opt/vc/bin/vcgencmd get_camera)
sb="supported=1 detected=1"
case $sb in
$s)
echo "Camera detected"
;;
*)
LANG=C
xmessage "Camera not detected !" -buttons ok
exit 1
;;
esac

The message box appears straight away.
I don't know what this change does to the system.
Is there a way of turning off 'LANG=C" or won't it mattter?
Perhaps saving the existing LANG to a variable and then re-instating.

Regards

You could save the setting of LANG before changing it and restore it later (but this is a little more complicated than it sounds), but the way your current script works, your setting of LANG only affects the behavior of your invocations of xmessage and exit (and exit doesn't care).

An easier way to set the value of LANG only for the execution of one command is to combine them like this:

LANG=C xmessage "Camera not detected !" -buttons ok

Doing it this way, LANG is set in the environment for that execution of xmessage and does change the setting of lang for any other code in your script.

1 Like

Hello,

Thanks for your help.

Regards