Skip to content

Commit

Permalink
initalcommit
Browse files Browse the repository at this point in the history
  • Loading branch information
samofab committed Aug 5, 2015
1 parent b16d044 commit d1c24c2
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 9 additions & 20 deletions README.md
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
10 changes: 9 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<body>
<h1>NODE.JS INTERACTIVE IO</h1>

<input type="text" id="visaaddress" value="GPIB0::22::INSTR" />
<input type="text" id="visaaddress" value="GPIB0::12::INSTR" />
<input type="text" id="command" value="*IDN?" />
<button>SEND</button>
<h3>Receive Message</h3>
Expand All @@ -29,5 +29,13 @@ <h3>Receive Message</h3>
});

</script>
<p>Common commands for HP 662xA</p>
<ul>
<li>ID?</li>
<li>VOUT? 1</li>
<li>output 2 to 450mA: ISET 2,.450</li>
<li>To turn off output 1: OUT 1,0</li>
<li>common: VSET, ISET, VOUT?, IOUT?, OUT, OVSET, and OCP</li>
</ul>
</body>
</html>
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

var visa32test = require('./visa32test.js');
var visa32test = require('./nisa32.js');

//visa32test.Visa32TestQuery('GPIB0::22::INSTR','*IDN?');
// visa32test.Visa32TestQuery('GPIB0::12::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);
rcvMsg = visa32test.query(msg.addr,msg.cmd, function(err, result) {
if (err)
io.emit('recvmsg', err);
else
io.emit('recvmsg', result);
}
);
});
});

Expand Down
83 changes: 83 additions & 0 deletions nisa32.js
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);
}
35 changes: 35 additions & 0 deletions package.json
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"
}
}

0 comments on commit d1c24c2

Please sign in to comment.