GPIB-USB-HS与S232进行通信
目录
1、准备工作
2、测试GPIB-USB-HS
3、代码展示(仅限python方法)
1、准备工作
先在NI官网上下载对应的驱动以及要使用的包,对应地址:搜索结果 - NI
2、测试GPIB-USB-HS
在官网上查找关于NI-MAX的使用方法,对应网址:GPIB仪器控制教程 - NI
看是否能够正常读取数据(我所使用的设备不能正常读取,因此避免去读)
3、代码展示(仅限python方法)
注意引入对应的包:
#
#此为测试是否能够正常通信关于s232与GPIB-USB-HS
#
#
import pyvisa
import serial#打开s232串口,在电脑的管理处也可以查看对应的端口
ser = serial.Serial('COM8',9600,timeout=1)
#写入数据
data1 = b'hello'
#data1= [0x01,0x02,0x03]
ww= ser.write(data1)
#从s232读
responce = ser.read(100)
print('232 responce',responce)#打开GPIB设备
rm = pyvisa.ResourceManager()
#此处是要显示现在电脑所有连接的串口为了查出GPIB0::0::INSTR此处是由nimax进行查找
print(rm.list_resources())
instrument = rm.open_resource('GPIB0::0::INSTR')
#此处是因为有一个超时的错误,听说这样写就不会报错
instrument.write_termination = "\\n"
instrument.read_termination = "\\n"
#发送信息但是自身不能读出来,但是可由s232进行对应读写
w=instrument. write("hello")
print("111111111111")
#xx= instrument.query(ww)
xx= ser.read(w)print('232 responce',responce)
print('GPIB result', xx)
#关闭连接
instrument.close()
ser.close()
这只是进行简单的通信,复杂功能还是要进行去文档分析,刚开始学习,要是有错,欢迎订正。