Comments (2)
@PeterStaev This is probably similar to #16, 1
is a valid JSON string. What I have seen and done in other python libraries is to look for at least open curly brace first. If yes, then attempt to parse JSON. If no, then print it out. You can do fancier logic to look for things like {"m":
from lego-spikeprime-mindstorms-vscode.
@PeterStaev A very "hacky" solution to show the cause of the problem.
constructor(location: string, logger: Logger) {
this._serialPort = new SerialPort(location, {
baudRate: 115200,
autoOpen: false,
});
this._serialPort.setDefaultEncoding("utf-8");
this._parser = this._serialPort.pipe(new SerialPort.parsers.Readline({ delimiter: "\r" }));
this._parser.on("data", (data: string) => {
let json: { [key: string]: any };
let print_data = false;
try {
if ((data.length >= 1 && data.charAt(0) === "{") ||
(data.length >= 2 && data.charAt(0) === "\n" && data.charAt(1) === "{")) {
json = JSON.parse(data);
}
else {
print_data = true;
}
}
catch (e) {
print_data = true;
}
if (print_data) {
// When data cannot be JSON parsed we re probably getting text from user's `print` command so we log it
if (data.length > 0 && data.charAt(0) === "\n") {
logger?.info(data.substring(1).replace(/\n/gi, "\n\r"));
}
else {
logger?.info(data.replace(/\n/gi, "\n\r"));
}
logger?.info("\n\r");
return;
}
from lego-spikeprime-mindstorms-vscode.
Related Issues (20)
- USB connection failed on Linux HOT 1
- How to make the program exit after it's finished HOT 4
- Importing self made modules. HOT 2
- How to download to the brick? HOT 3
- Can't Upload program when unplug USB cable and Plugged again HOT 4
- automatic saving in slot HOT 2
- List more advanced features :-) HOT 1
- Bluetooth not showing up on windows 10 HOT 4
- Cannot find imports. HOT 5
- FLL Coach here (not an actual "issue") HOT 1
- Is it works? HOT 2
- MemoryError when uploading and starting files multiple times HOT 5
- Support for HubOS 3 HOT 14
- question about usage HOT 2
- Enhance COM ports lists HOT 6
- Reconnection over BT fails after disconnect from VScode extension for some time
- spike prime new os connect HOT 1
- Trouble uploading code via VSC HOT 6
- Extension creates *.assembled.py file HOT 1
- Connection to Spike Prime HUB fails over USB without error message HOT 22
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lego-spikeprime-mindstorms-vscode.