Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16604 Discussions

Interacting with System-console from Python

Altera_Forum
Honored Contributor II
4,585 Views

I'm looking to make some integration with system console and Python 3.5 for a test that I'm running. What I would like to do is write some python that will use something like "subprocess" to bind to the system-console command line interface then write commands into stdin and read results out of stdout.  

 

I've found a few resources but have not been able to figure things out quite yet. I think that some active user here on the forum have experience with this. For example the user jksfiftyfive55 I think is the original author of the Stack Overflow question. 

 

http://www.alteraforum.com/forum/archive/index.php/t-48504.html 

 

and  

 

http://stackoverflow.com/questions/30133357/python-subprocess-popen-stdin-write/34776311#34776311 

 

Thanks in advance, I will update if I figure anything more out.
3 Replies
Altera_Forum
Honored Contributor II
2,999 Views

Well I am happy to say that I figured it out! Here is the code for everyones benefit: 

 

Tested in Windows 10, Python 3.5 and Quartus Prime 15.1 

import subprocess class altera_system_console: def __init__(self): sc_path = r'C:\altera_lite\15.1\quartus\sopc_builder\bin\system-console.exe --cli --disable_readline' self.console = subprocess.Popen(sc_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE) def read_output(self): rtn = "" loop = True i = 0 match = '% ' while loop: out = self.console.stdout.read1(1) if bytes(match,'utf-8') == out: i = i+1 if i==len(match): loop=False else: rtn = rtn + out.decode('utf-8') return rtn def cmd(self,cmd_string): self.console.stdin.write(bytes(cmd_string+'\n','utf-8')) self.console.stdin.flush() c = altera_system_console() print(c.read_output()) c.cmd('set jtag_master 0]') print(c.read_output()) c.cmd('open_service master $jtag_master') print(c.read_output()) c.cmd('master_write_8 $jtag_master 0x00 0xFF') print(c.read_output())
myoga1
Beginner
2,999 Views

At this point, you should have a working Python 3 interpreter at hand. If you need help getting Python set up correctly, please refer to the previous section in this tutorial series.

Here’s what you’ll learn in this tutorial: Now that you have a working Python setup, you’ll see how to actually execute Python code and run Python programs. By the end of this article, you’ll know how to:

  • Use Python interactively by typing code directly into the interpreter
  • Execute code contained in a script file from the command line
  • Work within a Python Integrated Development Environment (IDE)

 

 

 

 

0 Kudos
myoga1
Beginner
2,999 Views

Shell is a term, which is often used and often misunderstood. Like the shell of an egg, either hen or Python snake, or a mussel, the shell in computer science is generally seen as a piece of software that provides an interface for a user to some other software or the operating system. So the shell can be an interface between the operating system and the services of the kernel of this operating system. But a web browser or a program functioning as an email client can be seen as shell as well. 

 

Understanding this, it's obvious that a shell can be either

  • a command-line interface (CLI)
  • or
  • a graphical user interface (GUI)

But in most cases the term shell is used as a synonym for a command line interface (CLI). The best known and most often used shells under Linux and Unix are the Bourne-Shell, C-Shell or Bash shell. The Bourne shell (sh) was modelled after the Multics shell, and is the first Unix shell. 

Most operating system shells can be used in both interactive and batch mode.

 

http://www.trainingbangalore.in/python-training-in-bangalore.html

0 Kudos
Reply