2017-07-26 75 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%的電話中工作..