<commit_before>/**
 * Before use this, you should execute a following command as root.
 *   # echo BB-UART4 > /sys/device/bone_capemgr.8/slots
 */
var Gpio = require('onoff').Gpio
  , serialport = require('serialport')
  , SerialPort = serialport.SerialPort
  // , enablePort = new Gpio(5, 'out')            // P9.5(GPIO)
  ;

// i don't know how to set low value...
// console.log('enable RFID reader');
// enablePort.writeSync(0);

console.log('open tty to read RFIDs');
var inputSerial = new SerialPort("/dev/ttyO4", {  // P9.22(Serial)
  baudrate: 2400,
  databits: 8,
  stopbits: 1,
  parity: 'none',
  parser: serialport.parsers.readline("\n"), 
});

inputSerial.on("open", function() {
  console.log("opened tty");
  inputSerial.on('data', function(data) {
    console.log("data: " + data);
  });
});

var exit = function() {
  console.log('begin unexport');
  enablePort.unexport();
  console.log('end unexport');
  process.exit();
};
// process.on('SIGINT', exit);<commit_msg>remove white spaces from read data<commit_after>/**
 * Before use this, you should execute a following command as root.
 *   # echo BB-UART4 > /sys/device/bone_capemgr.8/slots
 */
var Gpio = require('onoff').Gpio
  , serialport = require('serialport')
  , SerialPort = serialport.SerialPort
  // , enablePort = new Gpio(5, 'out')            // P9.5(GPIO)
  ;

// i don't know how to set low value...
// console.log('enable RFID reader');
// enablePort.writeSync(0);

console.log('open tty to read RFIDs');
var inputSerial = new SerialPort("/dev/ttyO4", {  // P9.22(Serial)
  baudrate: 2400,
  databits: 8,
  stopbits: 1,
  parity: 'none',
  parser: serialport.parsers.readline("\r"), 
});

inputSerial.on("open", function() {
  console.log("opened tty");
  inputSerial.on('data', function(data) {
    console.log("data: " + data.replace(/^\s*|\s*$/g, ""));
  });
});

var exit = function() {
  console.log('begin unexport');
  enablePort.unexport();
  console.log('end unexport');
  process.exit();
};
// process.on('SIGINT', exit);
{'fraction_non_alphanumeric': 0.18790282597917699, 'fraction_numerical': 0.015865146256817054, 'mean_word_length': 3.5863636363636364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5459739', 'n_tokens_mistral': 730, 'n_tokens_neox': 710, 'n_words': 160}