Delta Tau Forums

Full Version: Starting gpascii programmatically via SSH
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a new PPMAC EtherLite that I can connect to with the IDE no issues. For my application, I need to connect programmatically from a Python application over either Telnet or SSH. I have Telnet working, but have hit a snag with SSH.

I can connect to the controller via either Telnet or SSH using PuTTY. I can log in, execute "ls" and other Linux commands, and I can finally start "gpascii" and talk to the controller.

I can also perform all of these operations programmatically from a Python application using the Python telnetlib module. No problems there.

When I try to connect from a Python application using the most common SSH library, paramiko, I am able to log in, execute "ls" and other Linux commands, but it hangs when I try to execute "gpascii". The command is sent but there is no reply, and it hangs when I try to read the output buffer. If I garble the "gpascii" string to say "gPascii", I get an error response such as:

['bash: gPascii: command not found\n']

I am about ready to give up on SSH, but that could pose problems for us if the PPMAC is later put on the external network. Any suggestions? Trying another development tool, C#/.NET or Java may be an option.
If you can log in and execute gpascii with PuTTy, then the problem is probably in your application.

A few years back, I wrote an app in C# that connected to a PPMAC via SSH and then used gpascii for sending commands. I ended up not using that app, but I don't think there's any inherent reason the same technique wouldn't work with python. SSH is SSH, so it should be the same.

Just to mix things up, you could try passing an argument to gpascii:

gpascii -2
I have gotten a bit further. I have determined that the gpascii command is getting to the controller, and that my code was hanging reading the output from stdout after transmitting the gpascii command. I have corrected that issue, but I now can see that gpascii is exiting as soon as it starts up, and I am not sure why.

Any suggestions?

I have ordered the PPMAC Dev Kit so that I can play around with the .NET examples.
These are the 5 lines of output I read after sending the gpascii command:

'STDIN Open for ASCII Input\n'



'// *** exit \n'

'UnlinkGatherThread: \r\n'
Correctio, I just receive the following 2 lines, and clearly gpascii is exiting as soon as it starts:

'STDIN Open for ASCII Input\n'

'// *** exit \n'
(09-22-2015, 12:39 AM)sgauthier Wrote: [ -> ]Hi,
I am just trying to use Paramiko and Python3 to communicate with PPMAC.

I have the same problem. I can only do 'ls' command but I can't change the directory. It stay in / directory, the 'ls' command returns the same list.

The 'gpascii -2' command hangs the communication...

Could you help me and give me what you do to execute all commands ?

I use python too, and I fork the to my github. You may have some good example codes in this python project.

Some Power PMAC Linux/Python tools
Path Description
cli/ IPython command line interface for Power PMAC
ppmac/ Python package with various utilities (gather, tune, etc.)
project/ Project creation/loading tools
misc/ Miscellaneous
fast_gather/ Raw gather data over TCP (C server, Python client)
Were you able to solve this issue using Paramiko and Python3?I am also able to run commands like "ls" but when I send the ''gpascii' command it hangs there. Any suggestions?
(08-10-2017, 02:21 PM)seanxyuan Wrote: [ -> ]but when I send the ''gpascii' command it hangs there. Any suggestions?

I would check to see how the python calls are intended to work. That is to say that some functions/methods act like a shell ... they start the program, wait for it to exit, and return the exit status. If this is the case for your python functions then calling gpascii will effectively "hang". You will need to be able to start the program with a function/method and then call other functions to write and read to stdin and stdout respectively and the gpascii program won't exit until it either crashes or you give it a cancel signal over stdin (CTRL-Z I think??). I hope that helps?


I've actually gotten it to work through Paramiko, but cannot share the code due to company restrictions. I can share some tips though.

Create the paramiko SSH client
Issue client.connect() with the PPMAC IP and port 22, default login and pass
To issue basic Linux shell commands (such as "ls" or "top", "one and done" commands that do not require a sequence of inputs), you can use client.exec_command()

To create a synchronous gpascii connection, it's a bit more tricky.



gpascii_client.send("gpascii -2\r\n")

wait a bit, about a second

response = gpascii_client.recv(2048)

response = response.decode() // need import sys
if you get "STDIN Open for ASCII Input" in the response, you succeeded. If not, you did not.

Then you can
stringToSend = command + "\r\n"
n = gpascii_client.send(stringToSend)

Wait a bit (technically you should wait for recv_ready() == True) and then you can

responseBytes = gpascii_client.recv(2048)

Decoding the response is a little confusing so here:

response = responseBytes.decode()
response = response[(n-2):] # remove echoed command
response = response.replace("\r","")
response = response.replace("\n","")
response = response.replace("\x06","")

response here should be the final, human-readable response to the command you issued.

If you issued echo 7 before, it might be easier to decode as it does some of the stripping for you.

Also multi-step operations, such as changing directories and navigating through the shell, also must use the invoke_shell(), send(), recv() approach used above.

Good luck and let me know if you have questions.
I know a lot of this thread is related to Python, but some of my lessons learned in Java certainly apply.

Here is a Java class to connect to the Power PMAC (uses JSch for SSH2) that starts the text interpreter and allows you to get/set parameters.

The pain points in building it were figuring out the response formats and waiting for correct bytes received after different commands are sent. The src code has lots of comments that may help you Python programmers get your Python scripts working.

I also had to create a shell as mentioned above.
how to use python to build and download project into power pmac? or using plc by python?
Using Python with the Power PMAC is not officially supported. You could use Python to simulate mouse clicks and button pushes, but there is no API that would allow it to control the IDE natively. You could have a Python script communicate to PMAC over GPASCII to do things like run a PLC once the project is downloaded.