利用cwinstr.ocx操作GPIB设备

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

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


1 个回复 | 最后更新于 27 天前
27 天前   #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();


登录后方可回帖

登 录
信息栏
本站永久域名:HtmLayout.Cn
纯私人站,当笔记本用的,学到哪写到哪,目前正在学aardio+halcon机器视觉.
Sciter中文在线文档Sciter在线学习文档
本 站 主 站:Stm32cube中文网
Aardio 官方站:Aardio官方
Aardio最新功能:Aardio官方更新日志
aardio在线手册Aardio在线手册
C大Aardio论坛:Aar爱好者论坛
简码教程网:简码编程
AARDIO语言QQ群:70517368
赞助商:才仁机械
下载站:非凡软件站
Loading...