What is the problem?
I have a 'cooler' attached to the extruder, and i'm trying to connect to the port i pluged the cooler in via USB cable in order to send/receive data.
I developed an Octoprint plugin that is supposed to control the fan speed of the cooler and some other features, this is my plugin struture:
- assistant_plugin
-- /init.py
-- /templates/pluginGUI.jinja2
-- /static/js/gui_functions.js
I'm trying to implement the connection logic in the 'gui_functions.js' JavaScript file, i have done some research and what i found is, to connect to the port there are three main steps:
1- in my Raspberry Pi run "npm install serialport"
2- at the top of my javascript add "const { SerialPort } = require('serialport')"
3- then create a port "const port = new SerialPort({ path: '/dev/ttyUSB0', baudRate: 115200 });"
but all my tries are failing so far, it keeps showing this error in the console tab: "caught ReferenceError: require is not defined". I'm kinda new to this whole thing so my developing knowledge is little. any help is appreciated!
this is my JS code snippet for reference:
__
const { SerialPort } = require('serialport');
function PortConnectionViewModel(parameters) {
var self = this;
self.connect = function() {
const serialPort = new SerialPort({ path: '/dev/ttyUSB0', baudRate: 115200 });
serialPort.open(function(error) {
if (error) {
console.log(error);
return;
}
console.log("Connected to serial port");
});
serialPort.on('data', function(data) {
console.log('Received data:', data);
});
}
self.disconnect = function() {
if (serialPort) {
serialPort.close(function(error) {
if (error) {
console.error('Error closing port:', error.message);
} else {
console.log('Port is closed');
}
});
} else {
console.error('Serial port not open or not available');
}
}
}
__
What did you already try to solve it?
WRITE HERE
Have you tried running in safe mode?
yes
Did running in safe mode solve the problem?
no since safe mode disables plugins.
Systeminfo Bundle
You can download this in OctoPrint's System Information dialog ... no bundle, no support!)
WRITE HERE
Additional information about your setup
What kind of hardware precisely, OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible
WRITE HERE