利用cwinstr.ocx操作GPIB设备

By admin at 2020-07-27 • 0人收藏 • 1732人看过

image.png

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=434;bottom=234)
winform.add(
button={cls="button";text="about";left=6;top=207;right=88;bottom=233;z=1}
)
/*}}*/

import console
console.open()

/* 一些常量
CWParsePatternType={
	cwNumberParser=0;
	cwUserDefined=1
};

CWGPIBTimeoutValues={
	cwGPIBTimeoutTNone=0;
	cwGPIBTimeoutT30ms=8;
	cwGPIBTimeoutT30us=2;
	cwGPIBTimeoutT10ms=7;
	cwGPIBTimeoutT10us=1;
	cwGPIBTimeoutT300ms=10;
	cwGPIBTimeoutT300us=4;
	cwGPIBTimeoutT3ms=6;
	cwGPIBTimeoutT100s=15;
	cwGPIBTimeoutT100us=3;
	cwGPIBTimeoutT1ms=5;
	cwGPIBTimeoutT100ms=9;
	cwGPIBTimeoutT3s=12;
	cwGPIBTimeoutT10s=13;
	cwGPIBTimeoutT1s=11;
	cwGPIBTimeoutT30s=14
};

CWGPIBNotifyMask={
	cwGPIBCMPL=256;
	cwGPIBEND=8192;
	cwGPIBTIMO=16384;
	cwGPIBNone=0;
	cwGPIBRQS=2048
};

*/


var gpibObj = com.CreateObject("CWInstrumentControlLib.CWGPIB.1");
//只读
console.log( gpibObj.DeviceID );
//
gpibObj.Reset();
//gpibObj.Stop();
//gpibObj.Trigger();
//console.log( gpibObj.Wait(0) );
//gpibObj.Write( "*IDN?" );
//gpibObj.WriteAsync( "*IDN?" );
//gpibObj.WriteFromFile( "C:\Users\Administrator\Desktop\gpib\demo.txt" );
console.log( gpibObj.Unaddressing );
gpibObj.setTimeoutValue(11);
console.dump( gpibObj.Tasks );
console.log( gpibObj.SwapBytes );
gpibObj.setSwapBytes(true);
//console.log( gpibObj.SerialPoll() );
//gpibObj.ReadToFile("C:\Users\Administrator\Desktop\gpib\cc.txt");
//console.log( gpibObj.ReadAsync(100) );//同步读
//console.log( gpibObj.Read(100) ); 
gpibObj.setPrimaryAddress(1);
console.log( gpibObj.PrimaryAddress );
console.log( gpibObj.SecondaryAddress );
 
//gpibObj.ParallelPollConfig(5); 
//console.log( gpibObj.ParallelPoll() );
gpibObj.setNotifyMask(0);
console.log( gpibObj.getNotifyMask() );
//gpibObj.Notify()
//gpibObj.GotoLocal();
//console.log( gpibObj.IsOnline() )
//gpibObj.ExportStyle("C:\Users\Administrator\Desktop\gpib\aa.txt");
//gpibObj.ImportStyle("C:\Users\Administrator\Desktop\gpib\aa.txt"); 
gpibObj.setExceptionOnError(true);
gpibObj.setEOTMode(true);
gpibObj.setEOSEndsRead(true);
gpibObj.setEOSChar('\r\n');
gpibObj.setEOIWithEOS(true);
gpibObj.setDefaultBufferSize(5000);
console.log( gpibObj.DefaultBufferSize );
gpibObj.setDataAsString(true);
console.log(gpibObj.DataAsString)
//gpibObj.setBoardNumber(1);
//gpibObj.Configure()
gpibObj.setCompare8Bits(false);
console.log(gpibObj.Compare8Bits)
//gpibObj.Clear();

console.log( gpibObj.BytesWritten ); 
//gpibObj.ChangePrimaryAddress(0);
//gpibObj.ChangeSecondaryAddress(1);

winform.button.oncommand = function(id,event){
	gpibObj.AboutBox()
}

winform.show();
win.loopMessage();

以上, 被//注释掉的, 都是需要你电脑上有GPIB设备的情况下才能调用的.

cwinstr.zip


可能会用到的一些系统dll和H头文件

gpib-32.zip


5 个回复 | 最后更新于 2020-10-20
2020-08-22   #1

刚好有了可以测试的设备, 测试了下这个, 还不错, 比直接调用gpib.dll要好用很多, 因为很多属性和方法这个ocx已经又重新进行了封装,用起来更方便了.

常用的功能如下:

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=434;bottom=234)
winform.add(
button={cls="button";text="about";left=6;top=207;right=88;bottom=233;z=1};
button2={cls="button";text="IDN";left=263;top=77;right=345;bottom=103;z=2};
button3={cls="button";text="PE";left=264;top=112;right=346;bottom=138;z=3};
button4={cls="button";text="Dp";left=265;top=153;right=347;bottom=179;z=4};
)
/*}}*/

import console
console.open()

var gpibObj = com.CreateObject("CWInstrumentControlLib.CWGPIB.1");
gpibObj.Reset();
//设置超时1s
gpibObj.setTimeoutValue(11);
//设置: 地址BN,PAD,SAD
gpibObj.setBoardNumber(0);
gpibObj.setPrimaryAddress(1);
gpibObj.setSecondaryAddress(0);
//是否开启异常处理错误提示
gpibObj.setExceptionOnError(true);
gpibObj.setEOTMode(true);
gpibObj.setEOSEndsRead(true);
gpibObj.setDefaultBufferSize(5000);
gpibObj.setDataAsString(true);
gpibObj.Configure()
 //只读
console.log("DeviceID", gpibObj.DeviceID );
console.log("IsOnline", gpibObj.IsOnline() )

winform.button.oncommand = function(id,event){
	gpibObj.AboutBox()
}

winform.button2.oncommand = function(id,event){
    gpibObj.Write( "*IDN?" );
	var ret = gpibObj.Read(100);
	console.log( ret ); 
	console.log( #ret ); 
}

winform.button3.oncommand = function(id,event){
	gpibObj.Write( "PE" );
	var ret = gpibObj.Read(100);
	console.log(ret );
	console.log( #ret ); 
}

winform.button4.oncommand = function(id,event){
	gpibObj.Write( "DP" );
	var ret = gpibObj.Read(100);
	console.log(ret );
	console.log( #ret ); 
}


winform.show();
win.loopMessage();


2020-10-16   #2

楼主你好,  cwinstr.ocx(GPIB  VB6.0控件)  中的使用方法有吗?    特别是此控件的 方法 属性 事件 等详细介绍。英文的也行 

2020-10-16   #3

这个是图片GPIB.JPG

2020-10-16   #4

回复#3 @雄鹰 :

我没有, 你可以到NI官方看看 , 下载它的nistudio里面就包含了这个控件, 也许里面有文档, 希望不大, 你也可以找个labview的同事, 用软件打开看看里面的接口的定义和解释

2020-10-20   #5

回复#3 @雄鹰 :

https://www.ni.com/pdf/manuals/321170c.pdf

你参考下这个文档

DataAsString—Use the DataAsString property to specify whether data is returned in a string or byte array format. If this property is True, data is returned as a string. If this property is False, data is returned as an array of bytes. You can set this property from the property pages of each control or programmatically as in the following example.

CWGPIB1.DataAsString = True

SwapBytes—Some instruments return data in which the least significant byte appears first. This format is known as Little Endian. Other instruments return data starting with the most significant byte of the word, or in Big Endian format. Check your instrument documentation to determine if the instrument returns data in Big or Little Endian format. If your instrument returns data in Big Endian format, set SwapBytes to True.


ExceptionOnError—The Instrument controls handle error checking in two different ways. When an error occurs, each Instrument control generates an exception that your programming environment handles (default action). You can disable the generation of exceptions using theExceptionOnError property of each Instrument control. If you disable exceptions on errors, the control fires an OnError event in response to an error condition and passes the error information to the OnError event handler. For some error conditions, such as those that occur during asynchronous operations, the control fires OnError events regardless of the value of ExceptionOnError.


The GPIB object has GPIB-specific properties, such as BoardNumber,PrimaryAddress, and SecondaryAddress, that you use to specify the instrument. You can set these properties through the property pages or in your program, as in the following code.

CWGPIB1.BoardNumber = 0
CWGPIB1.PrimaryAddress = 2
CWGPIB1.SecondaryAddress = 0

Other properties include Timeout, EOTMode, EOSCharacter,Compare8Bits, EOSEndsRead, EOIWithEOS, Unaddressing, andNotifyMask, although not all instruments require you to set these properties. See the online reference for all properties and their uses.


To control a GPIB instrument, use the Configure method. This method initializes the GPIB instrument and configures it with the settings you specified for the control. You must call the Configure method in the following cases:

• Before calling any other control methods 

• After changing any properties (for new properties to take effect) 

• After calling the Reset method, before performing any GPIB I/O

Private Sub ConfigureDevice_Click()
CWGPIB1.Configure
End Sub
Private Sub ResetDevice_Click()
CWGPIB1.Reset
End Sub

Synchronous I/O

You perform synchronous I/O using the Read and Write methods of the CWGPIB control. Read accepts an optional parameter that specifies the buffer size. Unlike the Read method on CWTask, the Read method on CWGPIB does not perform any parsing of the data.


The following example displays the identification string returned by many GPIB instruments. The control first writes the command *IDN? to the instrument and then reads back and displays the response in a text box in the program.

CWGPIB1.Write “*IDN?”
Text1.Text = CWGPIB1.Read

Asynchronous I/O

You use the ReadAsynch and WriteAsynch methods to perform asynchronous I/O operations. These methods start a read or write operation, respectively, and then return immediately. When an asynchronous read is complete, the control generates a DataReady event and passes the data to your event handler. When an asynchronous write is complete, the control generates a WriteComplete event.

CWGPIB1.ReadAsynch
Private Sub CWGPIB1_DataReady(taskNumber as Short,data As Variant)
Text1.Text = data
End Sub

Unlike the ReadAsynch and WriteAsynch methods on CWTask, theReadAsynch and WriteAsynch methods on CWGPIB do not perform any parsing of the data.


The GPIB control has methods to perform basic operations such as serial polling, parallel polling, triggering, and clearing the instrument. You can perform these methods with the following syntax.

CWGPIB1.SerialPoll
CWGPIB1.ParallelPoll
CWGPIB1.Trigger
CWGPIB1.Clear


登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...