WS eigene Datei

This commit is contained in:
chk
2026-04-23 17:27:52 +02:00
parent 3787d5b92e
commit 8ed6b67574
11 changed files with 559 additions and 122 deletions

View File

@@ -1,53 +0,0 @@
module.exports = class PythonSender {
constructor(p = 9875){
const WebSocket = require('ws');
this.sockets = [];
this.server = new WebSocket.Server({port: p});
this.server.on('connection', (socket) => this.connectThis(socket));
}
msgThis(msg){
console.log("message:" + msg.toString())
this.sockets.forEach(s => s.send(msg));
}
closeThis(socket){
console.log("Python Receiver is closing the connection");
this.sockets = this.sockets.filter(s => s !== socket);
}
connectThis(socket) {
console.log("Python Receiver is connected")
this.sockets.push(socket);
// When you receive a message, send that message to every socket.
socket.on('message', (msg) => this.msgThis(msg));
// When a socket closes, or disconnects, remove it from the array.
socket.on('close', () => this.closeThis(socket));
}
send(m){
if((this.sockets.length) > 0){
this.sockets.forEach( s => s.send(m));
}
else{ console.warn("No sockets connected. Can't send the Message.");}
}
/*
if(this.pythonSender != null){
var strJSON = CANCreator.cmdMovement(this.motorPositionOld, this.motorPosition);
if(strJSON != '{"message":"empty"}'){
this.pythonSender.send(strJSON);
}
}
*/
}

View File

@@ -107,8 +107,6 @@ class Robot{
/** @type {boolean} Relative oder absolute Bewegung (true = relativ) */
this.moveRelative = true;
/** @type {Object|null} Python-Sender-Instanz für GCode-Kommunikation */
this.pythonSender = null;
/** @type {Object[]} Array von Kommando-Empfängern */
this.cmdReceivers = [];
}