Created
April 8, 2020 13:18
-
-
Save vladaman/3c60b08d457348c1c6b49abd68c65397 to your computer and use it in GitHub Desktop.
EFTPOS - Protocol test connection V. 3.00 (revision:07) - https://en.wikipedia.org/wiki/EFTPOS - simple test to communicate with MyPAX S800 Terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var HOST = '192.168.9.111'; | |
var PORT = 20008; | |
const STX = 0x02; // Start transaction | |
const ETX = 0x03; // End transaction | |
const SEP = 0x1C; // Field separator | |
var client = new net.Socket(); | |
client.connect(PORT, HOST, function() { | |
console.log('CONNECTED TO: ' + HOST + ':' + PORT); | |
let str = "POST03S00A234567890123456KSTEST06 123412340000"; | |
let c = Buffer.from(str); | |
let msg = Buffer.concat([c, Buffer.from([ETX])]); | |
let d = Buffer.concat([Buffer.from([STX]), msg]); | |
let lrcByte = calculateLRC(msg); | |
let payload = Buffer.concat([d, Buffer.from([lrcByte])]); | |
console.log(payload.toString('hex')); | |
client.write(payload); | |
}); | |
// Add a 'data' event handler for the client socket | |
// data is what the server sent to this socket | |
client.on('data', function(data) { | |
console.log('DATA RESPONSE: ', data.toString('hex')); | |
// Close the client socket completely | |
client.destroy(); | |
}); | |
// Add a 'close' event handler for the client socket | |
client.on('close', function() { | |
console.log('Connection closed'); | |
}); | |
function calculateLRC(bytes) { | |
var lrc = 0; | |
for (var i = 0; i < bytes.length; i++) { | |
lrc ^= bytes[i]; | |
} | |
return lrc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment