Comments (7)
@ws1088 I dont think \n
is an option. It might fix the "simple" print option but from what i have seen JSON from the RPC are separated by \r
so I prefer to have correct working JSON RPC than to make "simple" print not print empty lines :)
from lego-spikeprime-mindstorms-vscode.
@ws1088 , I've noticed the different behaviors, but sadly not much can be done since there are cases where I get the value with a new line inside (not sure why) and in some cases there is no ending new line. That's why I decided to leave the extra new line just so it does not end on the same line as the previous print.
from lego-spikeprime-mindstorms-vscode.
@PeterStaev It's most likely because of how we are splitting the lines while reading the serial communications:
this._parser = this._serialPort.pipe(new SerialPort.parsers.Readline({ delimiter: "\r" }));
imagine we are parsing the content in the serial buffer:
line_1\r\nline2\r\nline3\r\n
and if we split the above by \r
then will will get the following
line_1
\nline2
\nline3
\n <- this one might be a valid JSON so we will not see this?
we should be splitting by \n
and removing trailing \r
(or splitted by \r\n
if possible), so that we will get:
line_1
line_2
line_3
and add '\r\n'
to each.
if we want to handle print('hello', ends='')
we might need to do something more...
from lego-spikeprime-mindstorms-vscode.
@PeterStaev If my theory is right (haven't debug into it), that \n
is a valid JSON, we can make sure data
have more than 3 characters and the first non-space character is {
(see #19). That way last \n
can be printed.
from lego-spikeprime-mindstorms-vscode.
from lego-spikeprime-mindstorms-vscode.
@PeterStaev ok, how about this?
this._parser.on("data", (data: string) => {
let json: { [key: string]: any };
try {
json = JSON.parse(data);
}
catch (e) {
// 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.
@ws1088 I will review this and the other print problem (#19), but for the time being I consider those a nice to have and i want to avoid "hacks" that might break the main JSON RPC communication. In the end if users want to have better printing they can always use the LEGO provided one which shouldn't have such problems.
from lego-spikeprime-mindstorms-vscode.
Related Issues (20)
- 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
- Inlcude a screen shot of the run buttons
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.