| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- var fs = require('fs');
- var path = require('path');
- const net = require('net');
- var exec = require('child_process').exec;
- const {
- spawn
- } = require('child_process');
- const {
- fork
- } = require('child_process');
- const {
- Readable
- } = require('stream');
- const { execSync } = require('child_process');
- const io = require('socket.io')();
- var data;
- var cla;
- var size = 5;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //Initialize codes.
- AutoLoadPlugins();
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //You can load the plugins in global field, if the next line codes are uncommented.
- AutoLoadGlobalPlugins();
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //Sample codes.
- exports.Test = function() {
- console.log("Hi, I'm a model test funciton");
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //Put you codes here
- exports.setCla = function(input){
- cla = input;
- };
- exports.getCla = function(){
- return cla;
- };
- exports.setSize = function(input){
- size = input;
- };
- exports.getSize = function(){
- return size;
- };
- exports.call = function(cb) {
- var input = ['D:/dcip/dcip/dcip/dcip/comx_sdk.node/unit/ADIGA/data/iga01.kms\n'];
- var iterator = input[Symbol.iterator]();
- const input_readable = Readable.from(iterator);
- var cp = spawn('D:/dcip/dcip/dcip/dcip/comx_sdk.node/unit/ADIGA/data/DE_Quadr_Wmi.exe');
- input_readable.pipe(cp.stdin);
- cp.stdout.on('data', data => {
- cb(data.toString());
- });
- };
- exports.getPID = function() {
- return process.pid;
- };
- exports.getCurrentDirectory2 = () => {
- var currentWorkingDirectory = process.cwd();
- var twoLevelsUpDirectory = path.join(currentWorkingDirectory, '..', '..', '..', '..');
- return twoLevelsUpDirectory;
- };
- exports.startSubProcess = function(cb, on_msg, on_msg01, cmd, cwds) {
- //let cmd = path.join("d:\\", 'QDebugTest.exe').replace(/\\/g, '/');
- //let cmd = path.join("d:\\", 'dcip\\dcip\\dcip\\dcip\\comx_sdk.node\\unit\\ERIGAS\\src\\QStructure.exe').replace(/\\/g, '/');
- //let cmd = "D:/dcip/dcip/dcip/dcip/comx_sdk.node/unit/ERIGAS/src/QStructure.exe";
- //let cp = spawn(cmd, ['hide'], {cwd : "D:\\Qt\\Qt-5.15.2\\bin"});
- let cp = spawn(cmd, ['hide'], {
- //cwd: "D:\\dcip\\dcip\\dcip\\dcip\\comx_sdk.node\\unit\\ERIGAS\\src"
- cwd: cwds
- });
- io.on('connection', client => {
- client.on('ready', () => {
- if (cb) {
- cb(cp.pid);
- }
- });
- client.on('message', msg => {
- if (on_msg) {
- on_msg(msg);
- }
- });
- client.on('message01', msg01 => {
- if (on_msg01) {
- on_msg01(msg01);
- }
- });
- });
- io.listen(3000);
- return io;
- };
- exports.setData = function(input){
- data = input;
- };
- exports.getData = function(){
- return data;
- };
- exports.getCurrentDirectory = () => {
- var currentWorkingDirectory = process.cwd();
- var twoLevelsUpDirectory = path.join(currentWorkingDirectory, '..', '..', '..', 'unit', 'variant', '/');
- return twoLevelsUpDirectory;
- };
- exports.write = function(fname, path) { //写文件
- var ws = fs.createWriteStream(path);
- ws.on('open', () => {
- console.log('打开流');
- });
- ws.write(fname);
- ws.on('close', () => {
- console.log('关闭流');
- });
- ws.end();
- };
- exports.spawn = function(path, cb) {
- var cp = spawn(path);
- cp.stdout.on('data', data => {
- cb(data.toString());
- });
- cp.stderr.on('data', data => {
- cb(data.toString());
- });
- };
- exports.spawns1 = function(path, processNumber, processNumber2, cb){
- let cp = spawn(path, [processNumber, processNumber2]);
- cp.stdout.on("data", data => {
- cb(data.toString());
- });
-
- cp.on('exit', code => {
- if(cb){
- //cb(true);
- }
- });
- };
- exports.exec = function(path, cb) {
- exec(path, (error, stdout, stderr) => {
- if (error) {
- //console.error(`exec error: ${error}`);
- cb(`exec error: ${error}`);
- return;
- }
- //console.log(`stdout: ${stdout}`);
- //console.error(`stderr: ${stderr}`);
- cb(`stdout: ${stdout}`);
- cb(`stderr: ${stderr}`);
- });
- };
- exports.execs = function(path, cb) {
- exec(path, (error, stdout, stderr)=>{
- if(error) {
- console.error(`exec error: ${error}`);
- if(cb){cb(false);}
- return;
- }
-
- cb(`stdout: ${stdout}`);
- cb(`stderr: ${stderr}`);
- if(cb){cb(true);}
- });
-
- };
- function runAbbExe(param, path) {
- return new Promise((resolve, reject) => {
- const exePath2 = path + 'src/MainPrj.exe';
- console.log(exePath2);
- exec(`${exePath2} ${param}`, (error, stdout, stderr) => {
- if (error) {
- reject(error);
- } else {
- resolve(stdout);
- }
- });
- });
- }
- // 并行执行 abb.exe 的函数
- exports.runAbbExeParallel = async function(path, sec_num) {
- const promises = [];
-
- for (let i = 0; i < sec_num; i++) {
- console.log(11111);
- const argv1 = path + "src/project1/project" + i;
-
- const argv2 = 0;
- const argv3 = 1;
- const argv4 = 1;
- const param = `${argv1} ${argv2} ${argv3} ${argv4}`;
- console.log(param);
- promises.push(runAbbExe(param, path));
- }
- const results = await Promise.allSettled(promises);
- results.forEach((result, index) => {
- if (result.status === 'fulfilled') {
- console.log(`Execution ${index} succeeded:`, result.value);
-
- //getstp();
-
- } else {
- console.log(`Execution ${index} failed:`, result.reason);
- }
-
- });
- var p = path + "src/Get_step.exe " + path + '/ ' + path + "/data/beam_shell " + path + '/data/beam_shell/M_shell.stp ' + data;
- getstp(p);
- };
- function getstp(path){
-
- exec(path, (error, stdout, stderr) => {
- if (error) {
- console.error(`exec error: ${error}`);
- //cb(`exec error: ${error}`);
- return;
- }
- console.log(`stdout: ${stdout}`);
- console.error(`stderr: ${stderr}`);
- //cb(`stdout: ${stdout}`);
- //cb(`stderr: ${stderr}`);
- });
- console.log('变体后处理完成!');
- return;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // AutoLoadPlugins Function Implement Start.
- function AutoLoadPlugins() {
- var plugin_dir = (__dirname + '/../addon/');
- if(!fs.existsSync(plugin_dir)) {
- return;
- }
-
- var files = fs.readdirSync(plugin_dir);
- files.forEach(function(filename){
- var filedir = path.join(plugin_dir, filename);
- var stats = fs.statSync(filedir);
- if(!stats.isDirectory()) {
- if(filedir.indexOf('-linux.node') !== -1 && require('os').platform() === 'linux') {
- require(filedir);
- }
-
- if(filedir.indexOf('-win.node') !== -1 && require('os').platform() === 'win32') {
- require(filedir);
- }
- }
- });
- }
- function AutoLoadGlobalPlugins() {
- var plugin_dir = (process.env.COMX_SDK + 'addon/');
- if (!fs.existsSync(plugin_dir)) {
- return;
- }
- var files = fs.readdirSync(plugin_dir);
- files.forEach(function(filename) {
- var filedir = path.join(plugin_dir, filename);
- var stats = fs.statSync(filedir);
- if (!stats.isDirectory()) {
- if (filedir.indexOf('-linux.node') !== -1 && require('os').platform() === 'linux') {
- require(filedir);
- }
- if (filedir.indexOf('-win.node') !== -1 && require('os').platform() === 'win32') {
- require(filedir);
- }
- }
- });
- }
- var g_wait_form = false;
- exports.wait = () => {
- var cmd = (unit.dir + '_entry.js');
- g_wait_form = fork(cmd, ['wait']);
- //g_wait_form.send('wait_cueline', 'test');
- };
- exports.cueline = (info) => {
- if (g_wait_form && g_wait_form.send) {
- //g_wait_form.send('wait_cueline', '' + info);
- //exports.ide_info(info);
- g_wait_form.send({
- type: 'wait_cueline',
- info: info
- });
- }
- };
- exports.stop = () => {
- var timeID = setInterval(() => {
- if (g_wait_form) {
- clearInterval(timeID);
- g_wait_form.send({
- type: "close",
- form: 'wait'
- });
- g_wait_form = false;
- }
- }, 100);
- };
- exports.updateGeometry = (geometry) => {
- if (g_wait_form) {
- g_wait_form.send({
- type: "setGeometry",
- geometry: geometry,
- form: 'wait'
- });
- }
- };
- //AutoLoadPlugins Function Implement End.
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // ide_info Function Implement Start.
- exports.ide_info = (msg) => {
- if (process.send) {
- process.send({
- type: 'debug',
- info: msg
- });
- }
- };
- //ide_info Function Implement End.
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|