Start script from external program

Scripts and programs to automate Astroart
Post Reply
Kaban
Posts: 10
Joined: 16 Sep 2021, 16:29

Start script from external program

Post by Kaban » 18 Jan 2024, 08:04

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.

fabdev
Posts: 503
Joined: 03 Dec 2018, 21:43

Re: Start script from external program

Post by fabdev » 19 Jan 2024, 16:12

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.

Kaban
Posts: 10
Joined: 16 Sep 2021, 16:29

Re: Start script from external program

Post by Kaban » 15 Feb 2024, 21:40

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.

fabdev
Posts: 503
Joined: 03 Dec 2018, 21:43

Re: Start script from external program

Post by fabdev » 16 Feb 2024, 01:09

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

Kaban
Posts: 10
Joined: 16 Sep 2021, 16:29

Re: Start script from external program

Post by Kaban » 16 Feb 2024, 07:43

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.

Post Reply