Last active
February 12, 2022 06:56
-
-
Save rezonn/f12ce1e16f95deddfd8e50b90ac2519f to your computer and use it in GitHub Desktop.
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
const SerialPort = require('serialport'); | |
const port = new SerialPort('/dev/cu.usbserial-1420', {baudRate: 115200}) | |
// port.write('G0 Z10\n', function(err) { | |
port.write('M114\n', function(err) { | |
if (err) { | |
return console.log('Error on write: ', err.message) | |
} | |
//console.log('message written') | |
}) | |
// Open errors will be emitted as an error event | |
port.on('error', function(err) { | |
console.log('Error: ', err.message) | |
}) | |
// Read data that is available but keep the stream in "paused mode" | |
port.on('readable', function () { | |
port.read() | |
}) | |
// Switches the port into "flowing mode" | |
port.on('data', function (data) { | |
console.log('Data:', data.toString()) | |
}) | |
// Pipe the data into another stream (like a parser or standard out) | |
const Readline = require('@serialport/parser-readline') | |
const lineStream = port.pipe(new Readline()) |
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
import serial | |
serialPort = serial.Serial('/dev/cu.usbserial-1420', 115200, exclusive = True) | |
line = "G0 X10" #go to x=10 | |
line = "M114" #go home | |
line = line + "\n" | |
serialPort.write(line.encode()) | |
lines = serialPort.read(serialPort.in_waiting).decode().splitlines(False) | |
print(lines) |
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
xcode-select --install | |
npm install serialport |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment