You are not logged in.

#1 2020-07-20 14:20:38

tomres
Member
Registered: 2020-06-23
Posts: 9

python code and [[Exec ]]

I'm currently running build 3342.

I'm trying to control my projector using some python code.

When I ssh into my raspberry pi I can run python code without issue. I have 4 scripts: turn the projector on/off and turn the LED on/off.
I've added custom buttons on the projector calibration page using "[[Exec python /home/pi/printer/pythonScripts/projectorLEDOff.py]]"
When I run the script this way I don't see the corresponding behavior as when I run it through ssh, and I get the following in the application log: "Execute Command Without Waiting For the Result python /home/pi/printer/pythonScripts/projectorLEDOff.py"

Is [[Exec ]] broken? Am I doing something wrong?

Any ideas?

Last edited by tomres (2020-07-22 19:19:26)

Offline

#2 2020-07-26 05:30:16

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

Change Exec to ExecReturn, then check activity log on dashboard to see why it does not run correctly

Offline

#3 2020-07-26 15:20:54

tomres
Member
Registered: 2020-06-23
Posts: 9

Re: python code and [[Exec ]]

Using [[ExecReturn ]]
I have this message:
Debug    0    2020-07-26 16:17:51.353706    Gcode    Execute Command and Return the Result python /home/pi/printer/pythonScripts/p_OFF.py

running the same script over ssh using "python p_OFF.py" turns the projector off, through nanoDLP there is no behavior.

Offline

#4 2020-07-26 19:20:47

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

So it does not throw any error? May I check you python source code.

Offline

#5 2020-07-28 14:22:59

tomres
Member
Registered: 2020-06-23
Posts: 9

Re: python code and [[Exec ]]

No errors.
This is my python code to turn the projector off:

#!/usr/bin/python

import os
import sys
import re
import struct

import ctypes
from ctypes import *

USB3DPrinter = ctypes.CDLL('/home/pi/printer/pythonScripts/LibUSB3DPrinter.so')

USB3DPrinter.CloseUsbDevice()
USB3DPrinter.OpenUsbDevice()

USB3DPrinter.PowerOnOff(2)
USB3DPrinter.Delay10Ms(3000)

USB3DPrinter.CloseUsbDevice()


This is taken from a sample python script provided by the projector manufacturer, and as I've mentioned, this works when I run it over ssh.

Offline

#6 2020-07-29 13:35:33

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

Try add sh -c before your command see if does help or not.

Offline

#7 2020-07-29 13:38:31

tomres
Member
Registered: 2020-06-23
Posts: 9

Re: python code and [[Exec ]]

Tried the following:

[[Exec sh -c python /home/pi/printer/pythonScripts/projectorLEDOff.py]]

with no change.. Is that the correct usage of sh -c?

Last edited by tomres (2020-07-29 15:22:21)

Offline

#8 2020-07-30 06:08:48

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

Yes it is correct, try add bash script and call bash script instead of python.
Also instead of python use full path /usr/bin/python
The issue probably something to do with how binary being called.

Offline

#9 2020-07-31 18:53:11

tomres
Member
Registered: 2020-06-23
Posts: 9

Re: python code and [[Exec ]]

Tried using full path to python with no result.

Added a bash script that calls the python script. Just contains the following:

#!/bin/sh
python /home/pi/printer/pythonScripts/p_OFF.py

had to adjust permissions using sudo chmod +x p_OFF.sh

Added a button that calls the shell script (is this the correct usage?):
[[ExecReturn /home/pi/printer/pythonScripts/p_OFF.sh]]

No errors in application log, again just says "Execute Command and Return the Results /home/pi/printer/pythonScripts/p_OFF.sh"
No results.

added sh -c before calling the bash script, no result.

tried:
[[ExecReturn bash /home/pi/printer/pythonScripts/p_OFF.sh]]

still no result.

Would love to get to the bottom of this issue!

Let me know if you have any other ideas.

Offline

#10 2020-08-01 06:41:08

Yianni-VJ
Member
Registered: 2016-05-24
Posts: 95

Re: python code and [[Exec ]]

I think I have the same situation, I can play wav files using putty, but not from inside nanoDLP, this was not a problem some versions ago.

But it gets weirder, I can execute some python scripts that control the light engine from inside nanoDLP.
There is one python script (not written by me) that tells the light engine to flip the image. I am guessing it has stopped working because I just noticed that letters print in reverse. (I remedy this now with the new options in machine settings)

I also hope you can identify and fix this problem, UV light engines are sensitive to improper shutdown, I have many blown pixels.

Offline

#11 2020-08-02 05:44:09

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

Tom,

Maybe you have not used full path as I advised above.
[[ExecReturn /usr/bin/python /home/pi/printer/pythonScripts/p_OFF.py]]

I also another reason could be how it get run by systemd. Disable nanodlp service and run it manually
cd /home/pi/printer
sudo ./printer

If it works you need to adjust nanodlp systemd service file.
https://wiki.archlinux.org/index.php/systemd

Offline

#12 2020-08-22 14:25:42

tomres
Member
Registered: 2020-06-23
Posts: 9

Re: python code and [[Exec ]]

Hi Shahin, sorry for delay in testing this.
I tried using the full path and also tried your suggestion to disable the nanoDLP service. Neither of these resulted in the python script executing. Please let me know if you have other suggestions!

Offline

#13 2020-08-27 00:52:43

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

Can I have a sample python script which I can run (does not require special library) and see if I could find the issue?

Offline

#14 2020-09-04 15:07:19

tomres
Member
Registered: 2020-06-23
Posts: 9

Re: python code and [[Exec ]]

Hi Shahin,

here is the python example I received from the manufacturer (which works over SSH)
https://we.tl/t-6maEXBdvIm

It does require a custom library (which I have included)

Offline

#15 2020-11-10 09:43:44

Shahin
Administrator
Registered: 2016-02-17
Posts: 3,546

Re: python code and [[Exec ]]

Tom,

Sorry I missed this thread. Try remove python itself.
[[ExecReturn /home/pi/printer/pythonScripts/p_OFF.py]]

Offline

Board footer

Powered by FluxBB