2017-07-26 80 views
0

我想通过使用Python 2.7的远程设备来控制Frequency Synthesizer。无法使用paramiko从其他设备获取USB输出

直接使用来自Rapberry Pi的USB端口的通信是通过Terminal进行的。在手册中可以找到这些命令。有两种类型的命令,设置和获取,如:

echo 0E > /dev/ttyACM0 # 0E is the code to reset 
echo 04 > /dev/ttyACM0|head</dev/ttyACM0 # 04 will return the frequency 

我使用下面的代码让我的树莓在Python输出:

print(os.popen(echo 04 > /dev/ttyACM0|head</dev/ttyACM0)) 

的终端命令可以使用ssh来执行从另一个设备。

现在,当我尝试使用Python时,我可以使用set命令而不使用probelms,但get命令不会带来正确的输出。

我用下面的功能:

import paramiko 
ssh = paramiko.SSHClient() 
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
global Con # nected 
con=0 


     def SSHConnection(): 
      global con 
      while True: 
       try: 
        ssh.connect(IP,username=User,password=Password) 
        con=1 
        break 
       except: 
        tkMessageBox.showwarning("Error!", "Device not found or wrong Login") 
        break 

     def outin(command): 
      global con 
      output="sudo echo "+command+"> /dev/ttyACM0|head</dev/ttyACM0" 
      if remote.get()==0: # switches between remote and direct output 
       answer=os.popen(output).readlines() 
      else: 
       if con==0: # checks wether a connection has already 
        SSHConnection() # connects 
       else: 
        pass 
       stdin,stdout,stderr = ssh.exec_command(output) 
       answer=stdout.read() 
      return answer 

我在网上找到这是我执行命令之前,我的功能可能会做的.read()。 我在网上找到的所有解决方案都使用channel.recv_exit_status()功能,这让我陷入了一个循环。

如果有人能帮助我,我会很高兴。

编辑: 错误的输出实际上是0x0096 = 150这没有错,但通常是我发送的最后一个请求。

回答

0

问题是某种时机。 我通过调用远程设备上的python代码来将输出保存在不同的文件中,然后调用该文件,从而实现了一种解决方法。 在约98%的电话中工作..