收藏 分销(赏)

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

上传人:精**** 文档编号:3992891 上传时间:2024-07-24 格式:DOC 页数:3 大小:30.04KB
下载 相关 举报
基于Python的串口通信(2).doc_第1页
第1页 / 共3页
基于Python的串口通信(2).doc_第2页
第2页 / 共3页
基于Python的串口通信(2).doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、基于Python的串口通信(2)Pyvisa1.1 安装pyvisa1.1.1 source安装(1) 下载pyvisa 说明文档:http:/pyvisa。readthedocs。org/en/latest/ 下载链接:https:/github。com/hgrecco/pyvisa(2) 解压 命令解压cd /xxx/xxx/pyvisamaster。zip(切换到相关文件所在目录)tar zxvf pyvisamaster。zip 手动解压(Mac下像。zip类的格式一般会在Safari下载完成后自动解压)(3) 安装visa modulecd /xxx/xxx/pyvisamaster

2、(切换到解压后的文件所在目录)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 安装NIVISApyvisa是基于NIV

3、ISA库的,所以要正常的使用,还需要安装NI的VISA库:http:/www。ni。com/visa/下载链接:http:/1.3 visa通信测试1.3.1 USB模式在IDLE中进行如下测试: import visa rm = visa。ResourceManager() rm。list_resources()(uUSB0:0x0957:0x1A07::MY53203784:INSTR,) my_instrument = rm.open_resource(USB0:0x0957::0x1A07:MY53203784:INSTR) print(my_instrument。query(*IDN

4、?))Agilent Technologies,34461A,MY53203784,A。01。09-02。2501。0900.35-0101附:一个简单的测试脚本(。py文件)visa#!/usr/bin/env python * coding: utf-8 -*import visafrom pyvisa.resources。usb import USBInstrumentfrom pyvisa.constants import *rm = visa。ResourceManager()res = rm.list_resources()print rmprint resprint(len(re

5、s))if len(res) 0: # print(res0) 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(res0) idn = usb_res。query(”IDN?”) print(idn) print(over) #关闭串口 usb_res.close() else: print(other res

6、ources”)else: print(”no dev found)1.3.2 LAN模式在IDLE中进行如下测试: import visa rm = visa。ResourceManager() rm。list_resources()(uTCPIP0:A-34461A03784.local::inst0::INSTR,) my_instrument = rm.open_resource(TCPIP0::A-34461A03784.local::inst0:INSTR) print(my_instrument。query(IDN?))Agilent Technologies,34461A,MY

7、53203784,A.01.0902.2501。0900。350101附:一个简单的测试脚本(。py文件) visa!/usr/bin/env python *- coding: utf8 -import sys, os, visa, threading, timePM = 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。

8、join(”。”, ”read_pm.txt) if os。path。isfile(”read_pm.txt”): read_pm() os。remove(read_pm。txt”) returndef 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() returndef 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()

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

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

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

关于我们      便捷服务       自信AI       AI导航        获赠5币

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

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

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

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服