收藏 分销(赏)

基于Python的串口通信(2).doc

上传人:精**** 文档编号:3992891 上传时间:2024-07-24 格式:DOC 页数:3 大小:30.04KB 下载积分:5 金币
下载 相关 举报
基于Python的串口通信(2).doc_第1页
第1页 / 共3页
基于Python的串口通信(2).doc_第2页
第2页 / 共3页


点击查看更多>>
资源描述
基于Python的串口通信(2) Pyvisa 1.1 安装pyvisa 1.1.1 source安装 (1) 下载pyvisa ① 说明文档: http://pyvisa。readthedocs。org/en/latest/ ② 下载链接: ❶https://github。com/hgrecco/pyvisa  ❷ (2) 解压 ① 命令解压 cd /xxx/xxx/pyvisa—master。zip(切换到相关文件所在目录) tar zxvf pyvisa—master。zip ② 手动解压(Mac下像。zip类的格式一般会在Safari下载完成后自动解压) (3) 安装visa module cd /xxx/xxx/pyvisa—master(切换到解压后的文件所在目录) sudo python setup。py install(加sudo以避免权限问题:”Permission denied.。。”) 注:pyvisa 是依托于enum34的,如果是首次安装,还需要先下载enum34并安装: https://pypi.python。org/pypi/enum34/1。0.4 安装方法同上: 1.1.2 pip安装 sudo pip install pyvisa 注:上图中之所以写成pip3。5(pip/pip3)是因为系统里除了自带的Python2外,还装了Python3(pip3为默认pip). 1.2 安装NI—VISA pyvisa是基于NI—VISA库的,所以要正常的使用,还需要安装NI的VISA库: http://www。ni。com/visa/ 下载链接: http:// 1.3 visa通信测试 1.3.1 USB模式 在IDLE中进行如下测试: >〉〉 import visa 〉〉〉 rm = visa。ResourceManager() 〉〉〉 rm。list_resources() (u’USB0::0x0957::0x1A07::MY53203784::INSTR',) 〉〉〉 my_instrument = rm.open_resource('USB0::0x0957::0x1A07::MY53203784::INSTR’) 〉〉〉 print(my_instrument。query('*IDN?’)) Agilent Technologies,34461A,MY53203784,A。01。09-02。25—01。09—00.35-01—01 〉〉> 附:一个简单的测试脚本(。py文件) visa#!/usr/bin/env python # —*— coding: utf-8 -*— import visa from pyvisa.resources。usb import USBInstrument from pyvisa.constants import * rm = visa。ResourceManager() res = rm.list_resources() #print rm #print res #print(len(res)) if len(res) 〉 0: # print(res[0]) for dev in res: dev_name = str(dev) if dev_name。startswith("USB"): print(”usb resource”) usb_res = USBInstrument(rm, dev_name) usb_res。open() #usb_res = rm。open_resource(res[0]) idn = usb_res。query(”*IDN?”) print(idn) print("over") #关闭串口 usb_res.close() else: print("other resources”) else: print(”no dev found") 1.3.2 LAN模式 在IDLE中进行如下测试: >〉〉 import visa >〉〉 rm = visa。ResourceManager() 〉〉〉 rm。list_resources() (u'TCPIP0::A-34461A—03784.local::inst0::INSTR',) 〉〉> my_instrument = rm.open_resource('TCPIP0::A-34461A—03784.local::inst0::INSTR') 〉>〉 print(my_instrument。query('*IDN?’)) Agilent Technologies,34461A,MY53203784,A.01.09—02.25—01。09—00。35—01—01 〉〉〉 附:一个简单的测试脚本(。py文件) visa#!/usr/bin/env python # —*- coding: utf—8 —*- import sys, os, visa, threading, time PM = visa.instrument("TCPIP0::192。168。1。70::inst0::INSTR”) def check_read():    #currentdir = os。curdir    #fullname = os。path.join(currentdir, ”read_pm。txt”)    #fullname = os。path。join(”。”, ”read_pm.txt")    if os。path。isfile(”read_pm.txt”):      read_pm()      os。remove("read_pm。txt”)     return def read_pm():    PM.write("FETCh:CW:POWer?")    # Write file    fpm_read = open(”pm_read_ok。txt",”w”)    fpm_read。write(PM。read())    fpm_read.close()    return def main():    # Display ID    print PM.ask("*IDN?")    # Init PM    PM.write("*CLS")    # Main loop    while 1:      time。sleep(1)      check_read() if __name__ == ’__main__’:    main()
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服