CWのメッセージ(固定文もしくは任意文)を、あなたのローカルPCから、リモートホストに接続されたIC-7410に送信します。
remote host % node index.js
index.js
var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); var port = process.env.PORT || 3000; var SerialPort = require('serialport'); var serial = new SerialPort('/dev/ttyUSB0',{ baudrate:19200 }); const buf1 = new Buffer('fefe80e0174351fd' , 'hex'); // CQ const buf2 = new Buffer('fefe80e01751525a3ffd', 'hex'); // QRZ? const buf3 = new Buffer('fefe80e017' , 'hex'); // preamble const buf4 = new Buffer('fd' , 'hex'); // postamble http.listen(3000,function(){ console.log('now listening to the port 3000..'); }); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); serial.on('open',function(){ console.log('serial port /dev/ttyUSB0 is opened.'); }); io.on('connection', function(socket){ socket.on('message1', function(){ serial.write(buf1); }); socket.on('message2', function(){ serial.write(buf2); }); socket.on('your message', function(msg){ serial.write(buf3); serial.write(msg); serial.write(buf4); io.emit('your message', msg); }); });
index.html
<!doctype html> <html> <head> <title>IC-7410 Rig Control</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font: 13px Helvetica, Arial; } form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } #messages { margin-bottom: 40px } </style> </head> <body> <h1>IC-7410 Rig Control</h1> <button id="btn1">CQ</button> <button id="btn2">QRZ?</button> <ul id="messages"></ul> <form action=""> <input id="m" autocomplete="off" /><button>Send</button> </form> <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> <script src="https://code.jquery.com/jquery-1.11.1.js"></script> <script> var socket = io(); $('#btn1').click(function(){ socket.emit('message1'); }); $('#btn2').click(function(){ socket.emit('message2'); }); socket.on('recvmsg',function(data){ $('h1').text(data); }); </script> <script> $(function () { var socket = io(); $('form').submit(function(){ socket.emit('your message', $('#m').val()); $('#m').val(''); return false; }); socket.on('your message', function(msg){ $('#messages').append($('<li>').text(msg)); window.scrollTo(0, document.body.scrollHeight); }); }); </script> </body> </html>