Start script from external program
Start script from external program
Hello.
I wonder if it is possible to start an Astroart script from an external program, a Python script, for example.
I have searched in this forum but i did not find anything.
Thank you.
David Cejudo.
I wonder if it is possible to start an Astroart script from an external program, a Python script, for example.
I have searched in this forum but i did not find anything.
Thank you.
David Cejudo.
Re: Start script from external program
Hello, it's possible with the Remote Control SDK.
In that SDK there are not examples with Python, but it's not difficult: just import the DLL and implement the "AASendCommand" function.
In that SDK there are not examples with Python, but it's not difficult: just import the DLL and implement the "AASendCommand" function.
Re: Start script from external program
Hello.
So i followed your indications and downloaded the Remote Control SDK.
I am not a programmer but after a not easy research and several tries i finally could build a Python script to launch AstroArt.
Very simple:
import ctypes
my_dll = ctypes.CDLL("C:/Users/yo/Desktop/AstroArt scripts/_The_DLL/64bit/AARemote.dll")
VAL=0
text = "None"
my_dll.AASendCommand.argtypes=[ctypes.c_int, ctypes.c_char_p]
my_dll.AASendCommand.restype = ctypes.c_int
my_dll.AASendCommand(VAL, text)
It works!
Running this script starts Astroart. Using other values for VAL, other tasks are done. For example, 1 terminates AstroArt, 11 stops a the script, 12 gets the status,...
But i got stuck in running a script. For that, VAL has to be set to 10 and the script has to be written as the "text" value.
Well, i got stuck on that one. How to do that? I tried a simple "print 1" script but it does not work.
If i am not wrong i need to compile the script, but i am not sure and i do not know how it is done.
Any hint would be welcome.
David Cejudo.
So i followed your indications and downloaded the Remote Control SDK.
I am not a programmer but after a not easy research and several tries i finally could build a Python script to launch AstroArt.
Very simple:
import ctypes
my_dll = ctypes.CDLL("C:/Users/yo/Desktop/AstroArt scripts/_The_DLL/64bit/AARemote.dll")
VAL=0
text = "None"
my_dll.AASendCommand.argtypes=[ctypes.c_int, ctypes.c_char_p]
my_dll.AASendCommand.restype = ctypes.c_int
my_dll.AASendCommand(VAL, text)
It works!
Running this script starts Astroart. Using other values for VAL, other tasks are done. For example, 1 terminates AstroArt, 11 stops a the script, 12 gets the status,...
But i got stuck in running a script. For that, VAL has to be set to 10 and the script has to be written as the "text" value.
Well, i got stuck on that one. How to do that? I tried a simple "print 1" script but it does not work.
If i am not wrong i need to compile the script, but i am not sure and i do not know how it is done.
Any hint would be welcome.
David Cejudo.
Re: Start script from external program
Hello, maybe the problem is that:
text = "None"
may be 16 bit Unicode, while a 8 bit ASCII string is expected. If this is the problem, here are a couple of solutions:
text = "None"
my_dll.AASendCommand(VAL, text.encode("ascii"))
or just for tests:
text = b"None"
my_dll.AASendCommand(VAL, text)
see:
https://stackoverflow.com/questions/238 ... s-c-char-p
https://stackoverflow.com/questions/669 ... unction-in
text = "None"
may be 16 bit Unicode, while a 8 bit ASCII string is expected. If this is the problem, here are a couple of solutions:
text = "None"
my_dll.AASendCommand(VAL, text.encode("ascii"))
or just for tests:
text = b"None"
my_dll.AASendCommand(VAL, text)
see:
https://stackoverflow.com/questions/238 ... s-c-char-p
https://stackoverflow.com/questions/669 ... unction-in
Re: Start script from external program
It worked!
I checked your links did some tests and found the solution.
I had to use the function text.encode()
Now the Python script is:
import ctypes
my_dll = ctypes.CDLL("C:/Users/yo/Desktop/AstroArt scripts/_The_DLL/64bit/AARemote.dll")
VAL = 10
text = "for i =1 to 10\n\tprint i\n\twait(1)\nNext i"
my_dll.AASendCommand.argtypes=[ctypes.c_int, ctypes.c_char_p]
my_dll.AASendCommand.restype = ctypes.c_int
my_dll.AASendCommand(VAL,text.encode())
Where text "for i =1 to 10\n\tprint i\n\twait(1)\nNext i" means:
for i=1 to 10
. print i
Next i
Thank you!!
David Cejudo.
I checked your links did some tests and found the solution.
I had to use the function text.encode()
Now the Python script is:
import ctypes
my_dll = ctypes.CDLL("C:/Users/yo/Desktop/AstroArt scripts/_The_DLL/64bit/AARemote.dll")
VAL = 10
text = "for i =1 to 10\n\tprint i\n\twait(1)\nNext i"
my_dll.AASendCommand.argtypes=[ctypes.c_int, ctypes.c_char_p]
my_dll.AASendCommand.restype = ctypes.c_int
my_dll.AASendCommand(VAL,text.encode())
Where text "for i =1 to 10\n\tprint i\n\twait(1)\nNext i" means:
for i=1 to 10
. print i
Next i
Thank you!!
David Cejudo.