forked from 7m4mon/visa32test
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
samofab
committed
Aug 5, 2015
1 parent
b16d044
commit d1c24c2
Showing
6 changed files
with
146 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,16 @@ | ||
# visa32test.js | ||
# node-nisa32 | ||
|
||
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). | ||
nisa32 is another prototype for using VISA 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) . | ||
I tested this code on Windows 8.1 (64bit), Keysight IO Library (17.1), node.js | ||
|
||
Please test on your insturment (e.g. GPIB, RS232, LAN etc...) and fork me, and develop complete VISA module. (like pyVISA) | ||
Talked to HP 6623A... | ||
|
||
``` | ||
> npm install nisa32 | ||
to use... | ||
``` | ||
|
||
> npm install ffi | ||
Original Author : 7M4MON | ||
|
||
> npm install ref | ||
> npm install ref-array | ||
> node visa32test.js | ||
|
||
|
||
Author : 7M4MON | ||
|
||
Licence : MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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 byte = ref.types.byte; | ||
var ByteArray = ArrayType(byte); | ||
|
||
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] ] | ||
}); | ||
|
||
/* idea: | ||
module.exports = function(visaAddress) { | ||
return new nisa32(visaAddress); | ||
} | ||
function nisa32() { | ||
var self = this; // Reference to "this" that won't get clobbered by some other "this" | ||
// Private state variables | ||
var tempPath; | ||
// Public method: initialize the object | ||
self.init = function(options, callback) { ... } | ||
function private() { ... } | ||
} | ||
*/ | ||
|
||
exports.query = function (visaAddress, queryString, callback){ | ||
return nisaQuery(visaAddress, queryString, callback); | ||
}; | ||
|
||
function nisaQuery(visaAddress, queryString, callback){ | ||
|
||
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'); | ||
if (viError) { | ||
callback(viError); | ||
} | ||
|
||
console.log("ADDR : " + visaAddress + " SEND : " + queryString); | ||
viError = visa32.viOpen('256', visaAddress, '0', '2000', '256'); | ||
if (viError) { | ||
return callback(viError); | ||
} | ||
viError = visa32.viPrintf('1', queryString + "\n"); | ||
if (viError) { | ||
return callback(viError); | ||
} | ||
|
||
viError = visa32.viScanf('1', "%s", replyBuff); | ||
if (viError) { | ||
return callback(viError); | ||
} | ||
visa32.viClose(resourceManager); | ||
|
||
// make reply string | ||
counter = 0; | ||
while(replyBuff[counter] != 0){ | ||
replyString += String.fromCharCode( replyBuff [counter] ); | ||
counter ++; | ||
} | ||
console.log("RECV : " + replyString); | ||
callback(null, replyString); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "node-nisa32", | ||
"version": "1.0.0", | ||
"description": "A simple npm module for interfacing with GPIB instruments ", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/samofab/node-nisa32.git" | ||
}, | ||
"keywords": [ | ||
"gpib", | ||
"hpib" | ||
], | ||
"author": "Samo Fabcic <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/samofab/node-nisa32/issues" | ||
}, | ||
"homepage": "https://github.com/samofab/node-nisa32#readme", | ||
"dependencies": { | ||
"express": "^4.13.3", | ||
"ffi": "^1.3.2", | ||
"http": "0.0.0", | ||
"ref": "^1.0.2", | ||
"ref-array": "^1.1.1", | ||
"socket.io": "^1.3.6" | ||
}, | ||
"files": { | ||
"nisa32.js" | ||
} | ||
} |