我在 Windows 7 上安装了(免费)Lattice Diamond 3.7,我想从命令行运行综合作业。我生成了一个 *.prj 文件,其中包含所有相关的命令行选项,例如 part、toplevel 和所有源文件。
然后我pnmainc.exe
从我的 PowerShell 开始并执行:synthesis -f arith_prng.prj
-a "ECP5UM"
-top arith_prng
-logfile D:\git\PoC\temp\lattice\arith_prng.lse.log
-lib poc
-vhd D:/git/PoC/tb/common/my_project.vhdl
-vhd D:/git/PoC/tb/common/my_config_KC705.vhdl
-vhd D:/git/PoC/src/common/utils.vhdl
-vhd D:/git/PoC/src/common/config.vhdl
-vhd D:/git/PoC/src/common/math.vhdl
-vhd D:/git/PoC/src/common/strings.vhdl
-vhd D:/git/PoC/src/common/vectors.vhdl
-vhd D:/git/PoC/src/common/physical.vhdl
-vhd D:/git/PoC/src/common/components.vhdl
-vhd D:/git/PoC/src/arith/arith.pkg.vhdl
-vhd D:/git/PoC/src/arith/arith_prng.vhdl
合成过程开始并结束。接下来,我尝试使用包装 Python 脚本实现相同的行为,控制子进程的 STDIN 和 STDOUT。
我可以执行一些命令,但synthesis
报告为未知命令。它没有在帮助中列出。我想,那是因为综合.exe 是一个外部程序。
例如,如果我发送help
,则显示所有帮助主题。
如何从 Python 为 Diamond 运行 Tcl 命令?
这是我在 Tcl-Shell 包装器上试验的 Python 代码。
from subprocess import Popen as Subprocess_Popen
from subprocess import PIPE as Subprocess_Pipe
from subprocess import STDOUT as Subprocess_StdOut
class Executable:
_POC_BOUNDARY = "====== POC BOUNDARY ======"
def __init__(self, executablePath):
self._process = None
self._executablePath = executablePath
@property
def Path(self):
return self._executablePath
def StartProcess(self, parameterList):
parameterList.insert(0, str(self._executablePath))
self._process = Subprocess_Popen(parameterList, stdin=Subprocess_Pipe, stdout=Subprocess_Pipe, stderr=Subprocess_StdOut, universal_newlines=True, bufsize=16, shell=True)
def Send(self, line):
print(" sending command: {0}".format(line))
self._process.stdin.write(line + "\n")
self._process.stdin.flush()
def SendBoundary(self):
print(" sending boundary")
self.Send("puts \"{0}\"\n".format(self._POC_BOUNDARY))
def GetReader(self):
for line in iter(self._process.stdout.readline, ""):
yield line[:-1]
tclShell = Executable(r"D:\Lattice\diamond\3.7_x64\bin\nt64\pnmainc.exe")
print("starting process: {0!s}".format(tclShell.Path))
tclShell.StartProcess([])
reader = tclShell.GetReader()
iterator = iter(reader)
# send boundary and wait until pnmainc.exe is ready
tclShell.SendBoundary()
for line in iterator:
print(line)
if (line == tclShell._POC_BOUNDARY):
break
print("pnmainc.exe is ready...")
tclShell.Send("help")
tclShell.SendBoundary()
for line in iterator:
print(line)
if (line == tclShell._POC_BOUNDARY):
break
print("pnmainc.exe is ready...")
tclShell.Send("synthesis -f arith_prng.prj")
tclShell.SendBoundary()
for line in iterator:
print(line)
if (line == tclShell._POC_BOUNDARY):
break
print("pnmainc.exe is ready...")
print("exit program")
tclShell.Send("exit")
print("reading output")
for line in iterator:
print(line)
print("done")