<commit_before>/*
  Simple example that takes a command line provided serial port destination and routes the output to a file of the same name with .log appended to the port name.
  
  usage: node logger.js /dev/tty.usbserial <baudrate>
  
*/

var SerialPort = require("serialport");
var fs = require("fs");
var port = process.argv[2];
var baudrate = process.argv[3];
var active = false;

function attemptLogging(fd, port, baudrate) {
  fs.write(fd, "\n------------------------------------------------------------\nOpening SerialPort: "+target+" at "+Date.now()+"\n------------------------------------------------------------\n");  
  var serialPort = new SerialPort.SerialPort(port, {
    baudrate: baudrate
  });
  serialPort.on("data", function (data) {
    fs.write(fd, data.toString());
  });
  serialPort.on("close", function (data) {
    active = false;
    fs.write(fd, "\n------------------------------------------------------------\nClosing SerialPort: "+target+" at "+Date.now()+"\n------------------------------------------------------------\n");  
  });
}

if (!port) {
  console.log("You must specify a serial port location.");
} else {
  var target = port.split("/");<commit_msg>Reorder output statement to ensure that it has opened.<commit_after>/*
  Simple example that takes a command line provided serial port destination and routes the output to a file of the same name with .log appended to the port name.
  
  usage: node logger.js /dev/tty.usbserial <baudrate>
  
*/

var SerialPort = require("serialport");
var fs = require("fs");
var port = process.argv[2];
var baudrate = process.argv[3];
var active = false;

function attemptLogging(fd, port, baudrate) {
  var serialPort = new SerialPort.SerialPort(port, {
    baudrate: baudrate
  });
  fs.write(fd, "\n------------------------------------------------------------\nOpening SerialPort: "+target+" at "+Date.now()+"\n------------------------------------------------------------\n");  
  serialPort.on("data", function (data) {
    fs.write(fd, data.toString());
  });
  serialPort.on("close", function (data) {
    active = false;
    fs.write(fd, "\n------------------------------------------------------------\nClosing SerialPort: "+target+" at "+Date.now()+"\n------------------------------------------------------------\n");  
  });
}

if (!port) {
  console.log("You must specify a serial port location.");
} else {
  var target = port.split("/");
{'fraction_non_alphanumeric': 0.32482503087690406, 'fraction_numerical': 0.0016467682173734047, 'mean_word_length': 1.7551020408163265, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3468255', 'n_tokens_mistral': 640, 'n_tokens_neox': 639, 'n_words': 197}