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
Showing
3 changed files
with
178 additions
and
0 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,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>NODE.JS INTERACTIVE IO</title> | ||
</head> | ||
<body> | ||
<h1>NODE.JS INTERACTIVE IO</h1> | ||
|
||
<input type="text" id="visaaddress" value="GPIB0::22::INSTR" /> | ||
<input type="text" id="command" value="*IDN?" /> | ||
<button>SEND</button> | ||
<h3>Receive Message</h3> | ||
<script src="/socket.io/socket.io.js"></script> | ||
<script src="http://code.jquery.com/jquery-1.11.1.js"></script> | ||
<script> | ||
var socket = io(); | ||
$('button').click(function(){ | ||
var addr = $("#visaaddress").val(); | ||
var cmd = $("#command").val(); | ||
var msg = { | ||
addr : addr, | ||
cmd : cmd | ||
} | ||
socket.emit('sendmsg',msg); | ||
}); | ||
socket.on('recvmsg',function(data){ | ||
$('h3').text(data); | ||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |
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 @@ | ||
/************************************************************ | ||
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'); | ||
}); |
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,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?'); |