コード例 #1
0
ファイル: myMagPrecision.js プロジェクト: kurakuradave/MyMag
joystick.on('axis', function( daAxis ){
    if( daAxis.number == 0 ) {
        if( daAxis.value > 1000 ) {
            serialPort.write( "stepRight", function(err, results) {
                console.log('err ' + err);
                console.log('results ' + results);
            });
        }
        else if( daAxis.value < -1000 ) {
            serialPort.write( "stepLeft", function( err, results ) {  
                console.log('err ' + err);
                console.log('results ' + results);
            } );
        }
    } else if( daAxis.number == 1 ) {
        if( daAxis.value > 1000 ) {
            serialPort.write( "stepDown", function(err, results) {
                console.log('err ' + err);
                console.log('results ' + results);
            });
        } else if( daAxis.value < -1000 ) {
             serialPort.write( "stepUp", function(err, results) {
                console.log('err ' + err);
                console.log('results ' + results);
            });       
        }
    }
});
コード例 #2
0
ファイル: index.js プロジェクト: SerialPort/node-serialport
 socket.on('message', msg => {
   console.log('Message received: ', msg)
   switch (msg) {
     case 'on':
       port.write(HIGH)
       break
     case 'off':
       port.write(LOW)
       break
     default:
       break
   }
 })
コード例 #3
0
ファイル: yaesu.js プロジェクト: granasat/GranaSATDashboard
 /**
   * Stop rotors
   * @param {positionCallback} cb - The callback that handles the response.
   */
 function stopRotor(callback) {
     s.write(new Buffer("S\n", "utf8"), function() {
         callback({
             status: "Done"
         });
     });
 }
コード例 #4
0
ファイル: UsbGpio.js プロジェクト: ryousuke2018/samplecode
portObj.open(function (error){
  if (error) {
    console.log('Failed to open port: ' + error);
  } else {
    console.log('Writing command gpio set 0 to port');
    portObj.write('gpio set 0\r', function(err) {
      if(err){
        console.log('Failed to write to port: '+ err);
      }
    });

    console.log('Waiting for two seconds');
    setTimeout(
      function() {
        console.log('Writing command gpio clear 0 to port');
        portObj.write('gpio clear 0\r', function(err) {
          if(err){
            console.log('Failed to write to port: '+ err);
          }
        });
        setTimeout(function() {
          process.exit(code=0);
        }, 1000);
      }, 2000);
  }
});
コード例 #5
0
setInterval(function(){
	string = 'S'+Math.round(steer)+'E'+Math.round(speed)+';';
	serialport.write(string);
	//console.log(string);
	IsBrake = 0;
	
},50);
コード例 #6
0
ファイル: xbee-obj.js プロジェクト: roachhuang/ehome
        return new Promise(function (resolve, reject) {
            var callback = function (receivedFrame) {
                let vm = this;
                console.log('inner');
                if (receivedFrame.id === frame.id) {
                    // This is our frame's response. Resolve the promise.
                    console.log('got correspondent response!: ', frame.id);
                    xbeeAPI.removeListener('frame_object', callback);
                    clearTimeout(timer);
                    if (receivedFrame.commandStatus === OK) {
                        console.log('resloved');
                        // The resolve() function is used to change the status of the promise from pending to fulfilled.
                        // The value that is passed inside the resolve() function becomes the fulfillment value of the promise.
                        resolve(receivedFrame);
                    }
                    else {
                        reject(new Error(receivedFrame.commandStatus));
                    }
                }
            };

            frame.id = xbeeAPI.nextFrameId();
            serialport.write(xbeeAPI.buildFrame(frame), function (err) {
                if (err) {
                    reject(new Error(err));
                }
                // Attach callback so we're waiting for the response
                xbeeAPI.on('frame_object', callback);
            });

            let timer = setTimeout(function () {
                xbeeAPI.removeListener('frame_object', callback);
                reject(new Error('timeout'));
            }, maxWait + 1000);
        });
コード例 #7
0
ファイル: server.js プロジェクト: PedroLopes/openEMSstim
//First validates a command, then if valid, sends it to the openEMSstim
function send_command(channel, intensity, duration) {
	var command = ""
	if (is_numeric(channel) && is_numeric(intensity) && is_numeric(duration)) {
		if (channel == 1 || channel == 2) {
			command = "C" + (channel -1);
		} else {
			console.log("ERROR: Command malformatted, will not send to openEMSstim");
			return null;
		}
		if (intensity >= 0 && intensity <= 100) {
			command += "I" + intensity; 
		} else {
			console.log("ERROR: Command malformatted, will not send to openEMSstim");
			return null;
		}
		if (duration >= 0) {
			command += "T" + duration + "G";
		} else {
			console.log("ERROR: Command malformatted, will not send to openEMSstim");
		}
		console.log("sending: " + command);
		openEMSstim.write(command);
	} else {
		console.log("ERROR: Command malformatted, will not send to openEMSstim");
		return null;
	}
}
コード例 #8
0
ファイル: app.js プロジェクト: jewkesy/fapfapsquirt
port.on('open', function() {
  port.write('main screen turn on', function(err) {
    if (err) {
      return console.log('Error on write: ', err.message);
    }
  });
});
コード例 #9
0
ファイル: yaesu.js プロジェクト: granasat/GranaSATDashboard
    /**
      * Set the position of the antennas
      * @param {Object} data - Where you want to rotate the antennas.
      * @param {number} data.ele - Elevation.
      * @param {number} data.azi - Azimuth.
      * @param {positionCallback} cb - The callback that handles the response.
      */
    function setPosition(data, cb) {
        if (data.ele < 0) {     //Elevation can not be negative!
            data.ele = 0;
        }
        var elevation = leftPad(Math.round(data.ele), 3, 0);      //The format that will be send to yaesu must have 3 digits
        var azimuth = leftPad(Math.round(data.azi), 3, 0);

        if (elevation != "" && azimuth != "") {
            s.write(new Buffer("W" + azimuth + " " + elevation + "\n", "utf8"), function(err) {
                if (err) {
                    log("Error writing to Yaesu Rotors : " + err.message, "error");
                    cb({
                        error: "Serial Write"
                    });
                } else {
                    cb({
                        status: "Done"
                    });
                }

            });
        } else {
            log("Bad azimuth or elevation", "error")
            callback({
                status: "Error"
            });
        }
    }
コード例 #10
0
ファイル: test.js プロジェクト: lizeqiangd/AsgardSystem
port.open(function (err) {
  if (err) {
  	console.log('Error opening port: ', err.message);
    return ;
  }
  port.write('^main screen turn on|');  
  // write errors will be emitted on the port since there is no callback to write
});
コード例 #11
0
function writeSerial(message) {
	port.write(message, function(err) {
	if (err) {
	  return console.log('Error on write: ', err.message);
	}
	console.log('message written:\n' + JSON.stringify(message));
	});
}
コード例 #12
0
ファイル: server.js プロジェクト: subhajitnag2805/Edge_Light
	client.on("generate", function (data) {
		let status = data.status;
		if (status == "OK") {
			var buffer = new Buffer(1);
			buffer.writeInt8(5);
			serialport.write(buffer);
		}
	});
コード例 #13
0
client.on('data', function (data) {
    serialPort.write(data.toString());
    	if (DECIMALEVENTS==1) {
            console.log(relativeTime() + USB_PORT + ' USB4 Received: ' + data);
            displayDataString(data);
        } else {
            console.log(USB_PORT + ' USB4 Received: ' + data);
        }
});
コード例 #14
0
ファイル: myMagPrecision.js プロジェクト: kurakuradave/MyMag
joystick.on('button', function( daButton ) {  
    if( daButton.number == 0 ) {
        if( daButton.value == 1 ) {  
            serialPort.write( "stepDec", function(err, results) {} );
        }
    } else if( daButton.number == 2 ) {
        if( daButton.value == 1 ) {
            serialPort.write( "stepInc", function(err,results) {} );
	}
    } else if( daButton.number == 1 ) {
        if( daButton.value == 1 ) {
            serialPort.write( "motionDecAcc", function(err,results){} );
	}
    } else if( daButton.number == 3 ) {
        if( daButton.value == 1 ) {
            serialPort.write( "motionIncAcc", function(err,results){} );
	}
    }
} );
コード例 #15
0
ファイル: index.js プロジェクト: tsukuroom/kakashi-biscuit
 setTimeout(() => {
   port.write('monitor 50\n', (err) => {
     if (err) {
       debug(err);
       return;
     }
     
     debug('written');
   }, 2000);
 });
コード例 #16
0
ファイル: UsbGpio.js プロジェクト: ryousuke2018/samplecode
 function() {
   console.log('Writing command gpio clear 0 to port');
   portObj.write('gpio clear 0\r', function(err) {
     if(err){
       console.log('Failed to write to port: '+ err);
     }
   });
   setTimeout(function() {
     process.exit(code=0);
   }, 1000);
 }, 2000);
コード例 #17
0
ファイル: Imst.js プロジェクト: tobiasrask/wmbus-client
 serialPort.on("open", () => {
     this._enabled = true;
     this.emit("connected");
     console.log('Connection opened');
     //setup the wbus reader for Link mode: C1 TF-B,  Device mode:Other, Send RSSI:no, Send Timestamp: no
     var configBuff = Buffer.alloc(12, "A501030800030007b0000000", "hex");
     serialPort.write(configBuff);
     serialPort.on('data', (data) => {
         // Push data to telegram stream
         telegramStream.write(data);
     });
 });
コード例 #18
0
ファイル: index.js プロジェクト: harttu/LAMPPU
function paivitaLeditArduinolle(ledit) {
console.log("Paivita ledit arduinolle");
console.dir(ledit[0].vari[0]);
var l = ledit[0];
console.log("l:");
console.dir(l);

console.log("l.vari:");
// [ '#AB2567', '#AB2567', '#12f445', '#f31200', '#AB2567' ]
console.dir(l.vari);
var variLista;
var varit = [];
for( var i = 0; i < l.vari.length; i++ ) { // Käy jokaisen noden läpi
   var komento = l.vari[i].slice(1); // Otetaan ensimmäinen merkki '#' pois
   console.log("Kasitellaan komento:"+komento);
      
   var R = (('00' + parseInt(komento.slice(0,2),16)).slice(-3));
   var G = (('00' + parseInt(komento.slice(2,4),16)).slice(-3))
   var B = (('00' + parseInt(komento.slice(4,6),16)).slice(-3))
   varit.push([R,G,B]);
}
/* Varit sisältävät esim
//  Rät    Get   Bet
[ '171', '037', '103' ]
[ '171', '037', '103' ]
[ '018', '244', '069' ]
[ '243', '018', '000' ]
[ '171', '037', '103' ]
*/

console.dir("------>"+varit);
console.log("------>"+varit[1]);
console.log("------>"+varit[1][1]);
// Pitää käydä varit läpi ja muotoilla seuraavat lauseet:
//#1R171171018243171
//#1G037037244018037
//#1B103103069000103
   var lauseet = ["#1R","#1G","#1B"];
   for( var t = 0; t < 3; t++) {
   	for( var j = 0; j < varit.length; j++ ) {
		
		console.log("Yhdistän "+varit[j][t]+" lauseeseen "+lauseet[t]);
		lauseet[t] += varit[j][t];   
	}
   }
  console.dir("lauseet:"+lauseet);
  console.log("Lahetetaan:");
  for(var i = 0; i < lauseet.length; i++) {	
	port.write(lauseet[i]);
}
  console.dir(varit);
}
コード例 #19
0
ファイル: index.js プロジェクト: jaeg/udooneo-robot-client
	client.get("FromUI", function(err, reply) {
		var command = reply.toString();
		if (lastCommand !== command) {
			port.write(command, function(err) {
			if (err != undefined) {
					console.log(err)
				}
			});
			console.log(command);
			lastCommand = command;
		}

	});
コード例 #20
0
ファイル: server.js プロジェクト: mikhailrojo/scanner
port.on('open', function() {
  port.write('main screen turn on', function(err) {
    if (err) {
      return console.log('Error on write: ', err.message);
    }
    console.log('message written');
  });

  port.on("data", function(e){
      var data = e.toString();
      //console.log(data);
      io.sockets.emit("message", data);
      data = "";
  })
});
コード例 #21
0
ファイル: serialport-basic.js プロジェクト: 1i7/snippets
function writeData(data) {
    console.log("write: " + data);
    port.write(data,
        function(err) {
            if(!err) {
                // данные ушли ок
                console.log("write ok");
            } else {
                // ошибка записи в порт 
                // (например, порт открыт, но не хватает прав на запись)
                console.log("write error: " + err);
            }
        }
    );
    
    // после первого вызова повторять бесконечно в цикле
    //setTimeout(writeData, 1000);
}
コード例 #22
0
ファイル: serialTermGW.js プロジェクト: domomib/sandbox
	sp.on('data', function(data, callback) {
		debug(data);
		// data = node-id;child-sensor-id;message-type;ack;sub-type;payload
		var donnees = data.split(';');	

		let chaine = 'id : '+ donnees[0] + ' -  ' + donnees[1];
		// message type
		switch ( donnees[2] ){
			case '0': //presentation
				chaine += ' => Presentation - > ' + presentation[donnees[4]] ;
				break;

			case '1': // set
				chaine += ' => Set - ' + setRequest[donnees[4]];
				break;

			case '2':  // req
				chaine += ' => Req. - ' + setRequest[donnees[4]];
				break;

			case '3': // internal
				chaine += ' => ' + internal[donnees[4]];
				// Ajouter proprement une gestion des  nodes avec persistances
				if ( donnees[4] == 3 ){
					//nodeId++; 
					var resp = donnees.slice(0,4).concat(4, nodeId, '\n');

					sp.write( resp.join(';') , function () {
    					sp.drain(callback)
    				});
  					
					console.log('envoi nouvel id pour le noeud' + nodeId + " " + resp.join(';'));
				}
				break;

			case '4': // stream
				chaine += ' => Stream ' ;
				break;

		}
		chaine += ' --> ' + donnees[5];
		console.log(chaine + ' === ' + data	+ ' ===')

	});
コード例 #23
0
ファイル: yaesu.js プロジェクト: granasat/GranaSATDashboard
    /**
      * This callback type is called `positionCallback` and is displayed as a global symbol.
      * @callback positionCallback
      * @param {string} data
      */

    /**
      * Get the position of the antennas
      * @param {positionCallback} cb - The callback that handles the response.
      */
    function getPosition(cb) {
        var p = new Promise.defer();

        var f = readPosition(p);
        s.on('data', f);

        s.write(new Buffer("C2\n", "utf8"));

        setTimeout(function() {
            p.resolve({
                error: "Timeout"
            });
        }, 1000);

        p.promise.then(function(data) {
            s.removeListener('data', f);
            cb(data);
        });
    }
コード例 #24
0
    /**
      * This callback type is called `frequencyCallback` and is displayed as a global symbol.
      * @callback frequencyCallback
      * @param {string} data
      */

    /**
      * Get the frequency of kenwoodts2000
      * @param {frequencyCallback} cb - The callback that handles the response.
      */
    function getFrequency(cb) {
        var p = new Promise.defer();

        var f = readFreq(p);
        s.on('data', f);

        s.write("TC 1;FA;FB;FC;TC 0;");

        setTimeout(function() {
            p.resolve({
                error: "Timeout"
            });
        }, 1000);

        p.promise.then(function(data) {
            s.removeListener('data', f);
            cb(data);
        });
    }
コード例 #25
0
      parser.on('data', function(jsondata) {
        console.log('Got data');
        var data
        try{
          data = JSON.parse(jsondata);
          
          if (data.Group){
            var filename = "sd_" + Date.now() + ".json"
            var sampleSet = {}
            sampleSet.group = data;
            sampleSet.depth = self.depth;
            sampleSet.temp = self.temp;
            fs.appendFile(path.join("/usr/share/cockpit/analogsensor",filename),JSON.stringify(sampleSet));
          }
          
          console.dir(data);
          console.log("Group=",data.Group)
          if (data.Group == 50){
            serialPort.write('b');              //  signal microcontroller to start "b" for begin
            console.log('wrote b');            
          }
        }catch(e){
          //ignore data, not valid json
          
          console.warn("Bad json found from serial port", jsondata);
        }
        //console.log(data.ToString())
        
/*        //parseStatus turns data in to an object of name,value pairs {name:"value",name2,"value2"}
        var status = reader.parseStatus(data);
        console.log(status);
        //var status = {name:"value",name2,"value2"};
        self.globalBus.emit('mcu.status',status);
*/
//          console.log(data);     //  seems to overflow things, get beeps from ROV and no logging
      });
コード例 #26
0
    /**
      * Set the frequency
      * @param {Object} freq - The frequency.
      * @param {number} freq.VFOA - To change the Variable Frequency Oscillator A.
      * @param {number} freq.VFOB - To change the Variable Frequency Oscillator B.
      * @param {number} freq.VFOC - To change the Variable Frequency Oscillator C.
      * @param {statusCallback} cb - Response of the result
      */
    function setFrequency(freq, cb) {

        s.write(new Buffer("03", "hex"));
        s.write("TC 1;");

        if (freq.VFOA) {
            var VFOA = leftPad(Math.round(freq.VFOA), 11, 0);
            s.write("FA" + VFOA + ";");
        }
        if (freq.VFOB) {
            var VFOB = leftPad(Math.round(freq.VFOB), 11, 0);
            s.write("FB" + VFOB + ";");
        }
        if (freq.VFOC) {
            var VFOC = leftPad(Math.round(freq.VFOC), 11, 0);
            s.write("FC" + VFOC + ";");
        }
        s.write("TC 0;");
        cb({
            status: "Done"
        });
    }
コード例 #27
0
ファイル: index.js プロジェクト: GreyMage/GreyMage.github.io
			setTimeout(()=>{
				port.write('?', function () {
					port.drain();
				});
			},1000)
コード例 #28
0
/* eslint-disable node/no-missing-require */

// Open event example
const SerialPort = require('serialport')
const port = new SerialPort('/dev/tty-usbserial1')

port.on('open', () => {
  console.log('Port Opened')
})

port.write('main screen turn on', err => {
  if (err) {
    return console.log('Error: ', err.message)
  }
  console.log('message written')
})

port.on('data', data => {
  /* get a buffer of data from the serial port */
  console.log(data.toString())
})
コード例 #29
0
ファイル: app.js プロジェクト: fxp528/DPM
			setTimeout(function(){
				port.write(s.Read);
			}, interval / slaves.length * i);
コード例 #30
0
ファイル: index.js プロジェクト: harttu/LAMPPU
app.get('/testSerial', (req,res) => {
	port.write('#1G000000000000255');
	port.write('#1R000000000000255');
	port.write('#1B000000000000255');
});