[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Oct 02, 2022 1:03 am
An error occurred in the input " (double quotes) .
Is there any improvement?
connection.send('cmd:immediatxd$="'+ e + '"');
What format is "cmd"?
cmd:immediatex d$=xx ?
xx:double quotes code """ is bad
WiFitermTest02.jpg
The command cmd: is the way I implemented to transfer commands from javascript to the basic.
cmd:immediatx enables to send command lines as if executed directly from the interpreter.
In this case, the line that is sent is
d$="x" where x is the code of the key typed in the terminal; obviously if the code is " then the line will be d$=""" that gives a syntax error.
What you can do is to use the | as string separator like this :
cmd:immediatxd$='|'+ e + '|');
Code: [Local Link Removed for Guests]
A$ = A$ + " connection.send('cmd:immediatxd$=|'+ e + '|'); "
Obviously you'll have the same issue on the key | so, another way, could be to check if the string received contains " and send alternatively the " or the | as separator
Another problem is linked to the character new line '\n' or chr$(10) that is used as line separator so will generate another problem.
You can filter them in the basic like below
Code: [Local Link Removed for Guests]
cls
'loads the javascript
jsexternal "/xterm.js"
pause 2000 ' a little pause for loading the javascript
A$ = ||
A$ = A$ + |<!doctype html>|
A$ = A$ + | <html>|
A$ = A$ + | <head>|
A$ = A$ + | <link rel="stylesheet" href="/xterm.css" />|
A$ = A$ + | </head>|
A$ = A$ + | <body>|
A$ = A$ + | <H1> Wifi Xterm Test </H1>|
A$ = A$ + | <div id="terminal"></div>|
A$ = A$ + | </body>|
A$ = A$ + | </html>|
html a$
a$ = ||
A$ = A$ + | term = new Terminal();|
A$ = A$ + | term.open(document.getElementById('terminal'));|
A$ = A$ + | term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ');|
A$ = A$ + | term.onData(async function(e) { |
A$ = A$ + | console.log("onData:", e); |
' this line is for the esp32
'A$ = A$ + | connection.send("cmd:setvarxd$="+ e); | ' send what received in the variable d$
' this line is for the esp8266
'A$ = A$ + | connection.send('cmd:immediatxd$="'+ e + '"'); | ' send what received in the variable d$
'A$ = A$ + " connection.send('cmd:immediatxd$=|'+ e + '|'); "
A$ = A$ + | if (e.includes('"')) |
A$ = A$ + " connection.send('cmd:immediatxd$=|'+ e + '|'); " ' send what received in the variable d$ using |
A$ = A$ + | else|
A$ = A$ + | connection.send('cmd:immediatxd$="'+ e + '"'); | ' send what received in the variable d$ using "
A$ = A$ + | });|
jscript a$
OnHtmlChange Jump1 'will jump to Jump1 when a variable changes on the web page
onSerial serialIn ' will jump to serialIn when data received on the serial port
Wait 'pause waiting for the event
Jump1:
d$ = replace$(d$, chr$(10), chr$(10) + chr$(13))
Print d$; 'print the characters received in the serial port
Return
serialIn:
k$ = serial.input$
k$ = replace$(k$, chr$(10), "\n")
k$ = replace$(k$, chr$(13), "\r")
jscall |term.write('| + k$ + |');| 'send what received in the web terminal
return