From efe521240c0e3a73cc32f61381ffd626252f9c3e Mon Sep 17 00:00:00 2001
From: 7m4mon <7m4mon@gmail.com>
Date: Fri, 24 Apr 2015 21:04:20 +0900
Subject: [PATCH] visa32test
---
index.html | 33 +++++++++++++++
index.js | 35 ++++++++++++++++
visa32test.js | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 178 insertions(+)
create mode 100644 index.html
create mode 100644 index.js
create mode 100644 visa32test.js
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..5b323f0
--- /dev/null
+++ b/index.html
@@ -0,0 +1,33 @@
+
+
+
+
+ NODE.JS INTERACTIVE IO
+
+
+ NODE.JS INTERACTIVE IO
+
+
+
+
+ Receive Message
+
+
+
+
+
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..0f95141
--- /dev/null
+++ b/index.js
@@ -0,0 +1,35 @@
+/************************************************************
+
+ NODE.JS INTERACTIVE IO
+
+This is WEB interface for visa32test.js.
+
+Author : 7M4MON
+Date : 2015/04/24
+Licence : MIT
+
+************************************************************/
+
+
+var app = require('express')();
+var http = require('http').Server(app);
+var io = require('socket.io')(http);
+
+var visa32test = require('./visa32test.js');
+
+//visa32test.Visa32TestQuery('GPIB0::22::INSTR','*IDN?');
+
+app.get('/',function(req,res){
+ res.sendfile('index.html');
+});
+var rcvMsg;
+io.on('connection',function(socket){
+ socket.on('sendmsg',function(msg){
+ rcvMsg = visa32test.Visa32TestQuery(msg.addr,msg.cmd);
+ io.emit('recvmsg', rcvMsg);
+ });
+});
+
+http.listen(3000,function(){
+ console.log('listen 3000 port');
+});
diff --git a/visa32test.js b/visa32test.js
new file mode 100644
index 0000000..6539bbd
--- /dev/null
+++ b/visa32test.js
@@ -0,0 +1,110 @@
+/************************************************************
+
+ VISA32TEST.JS
+
+visa32test.js is a prototype for using VISA ( Virtual Instrument Software Architechture)
+library in node.js.
+
+This is a wrapper for visa32.dll ( in your system32 folder).
+
+I tested this code on Windows 7 (32bit), Keysight IO Library (17.1), node.js(0.10.26) .
+
+Please test on your insturment (e.g. GPIB, RS232, LAN etc...) and fork me, and
+develop complete VISA module. (like pyVISA)
+
+to use...
+
+> npm install ffi
+> npm install ref
+> npm install ref-array
+> node visa32test.js
+
+Author : 7M4MON
+Date : 2015/04/24
+Licence : MIT
+
+************************************************************/
+
+
+var ref = require('ref');
+var ffi = require('ffi');
+var ArrayType = require('ref-array')
+
+// typedef
+var ViError = ref.types.int;
+var ViSession = ref.types.int;
+
+//var ViRsrc = ref.types.CString;
+//var ViAccessMode = ref.types.int;
+//var ViUint32 = ref.types.int;
+
+// for viScanf
+var byte = ref.types.byte;
+var ByteArray = ArrayType(byte);
+
+// not used
+//var StrArray = ArrayType(stringAry);
+//var StrArrayPtr = ref.refType(StrArray);
+//var replyString = ref.types.CString;
+//var replyStringPtr = ref.refType(replyString);
+
+var visa32 = ffi.Library('visa32', {
+ 'viOpenDefaultRM': [ViError, ['string'] ] , //viOpenDefaultRM(sesn)
+ 'viOpen' : [ViError, ['int', 'string', 'int', 'int', 'string'] ], //viOpen(sesn, rsrcName, accessMode, timeout, vi)
+ 'viPrintf' : ['int',['int', 'string']],
+ 'viScanf' : ['int',['int', 'string', ByteArray]],
+ 'viClose' : ['int', [ViSession] ]
+});
+
+
+exports.Visa32TestQuery = function (visaAddress, queryString){
+ return Visa32TestQuery(visaAddress, queryString);
+};
+
+function Visa32TestQuery(visaAddress, queryString){
+
+ var resourceManager = '0';
+ var viError = 0;
+ var session = 0;
+ var replyString = '';
+
+ // intialize Buffer
+ var replyBuff = new ByteArray(256);
+ var counter;
+ for (counter = 0 ; counter < 256 ; counter++){
+ replyBuff [counter] = 0 ;
+ }
+
+
+ viError = visa32.viOpenDefaultRM('0');
+
+ //console.log(viError);
+
+ //var visaAddress;
+ //visaAddress = 'GPIB0::22::INSTR'
+
+ console.log("ADDR : " + visaAddress);
+ viError = visa32.viOpen('256', visaAddress, '0', '2000', '256');
+
+ //var queryString;
+ //queryString = "*IDN?";
+ viError = visa32.viPrintf('1', queryString + "\n");
+
+ console.log("SEND : " + queryString);
+
+ viError = visa32.viScanf('1', "%s", replyBuff);
+ visa32.viClose(resourceManager);
+
+ // make reply string
+ counter = 0;
+ while(replyBuff[counter] != 0){
+ replyString += String.fromCharCode( replyBuff [counter] );
+ counter ++;
+ }
+
+ console.log("RECV : " + replyString);
+ return replyString;
+}
+
+// if you use as module, please comment out below:
+//Visa32TestQuery('GPIB0::22::INSTR','*IDN?');
\ No newline at end of file