Create and save Windows Powershell script
create a powershell script called
readscale.ps1 and save in folder c:\ScaleIntegration
if you have decided to call a python script similar to STEP 2, use below script
<#PSScriptInfo
.VERSION 1.0
#>
c:\path_to_pythonhome\python.exe c:\ScaleIntegration\getweight.py
OR if you are capturing directly from a serial port and intend to call directly from powershell, you may use below sample script
<#PSScriptInfo
.VERSION 1.0
#>
$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.Open()
$port.ReadLine()
Create and save nodejs script
create a nodejs script called
readscaleapp.js and save in folder c:\ScaleIntegration,
Ensure the right parameter values are retrieved sent to the nodejs url e.g
http://localhost:8099/?appsession=&APP_SESSION .&record=&P7_RECORD_ID . , use below script
/*Author: Kehinde Adeyemi*/
var http = require('http');
var url = require('url');
var spawn = require("child_process").spawn,child;
console.log("Powershell initializing: ");
child = spawn("powershell.exe",["c:\\ScaleIntegration\\readscale.ps1"]);
child.stdout.on("data",function(data){
console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
console.log("An Error occurred, please check if scale is connected and/or port is open");
});
child.on("exit",function(){
console.log("Powershell Script initialized...");
});
child.stdin.end();
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
/*Use the url module to turn the querystring into an object:*/
var q = url.parse(req.url, true).query;
var spawn = require("child_process").spawn,child;
console.log("Powershell starting: ");
child = spawn("powershell.exe",["c:\\ScaleIntegration\\readscale.ps1"]);
child.stdout.on("data",function(data){
console.log("Powershell Data in : " + data + q.appsession + " " + q.recordid);
var txt = data;
res.write('' + txt + '
');
res.write('Record Weight');
res.end();
});
child.stderr.on("data",function(data){
console.log("An Error occurred, please check if scale is connected and/or port is open");
var txt = "An Error occurred, please check if scale is connected and/or port is open";
res.end(txt);
});
child.on("exit",function(){
console.log("Powershell Script finished");
});
child.stdin.end();
}).listen(8099);
Create a batch file
create a batch file to execute the nodejs script called readscaleapp.js and save as
readscale.bat in folder c:\ScaleIntegration
cd c:\ScaleIntegration
node readscaleapp.js
Create a scheduled task to launch the batch file and you may also create it as a windows service