Hai Shanti,
Thanks for your reply! I didn't notice jsdb is single threaded anyway, this because I didn't use any fancy stuff before, just reply to the (single) request which is working fine. I made some.audio fileservers in the past, pretty good.
I understand now that websockets is impossible, because it is single threaded. However is it possible to open a continuous stream with the client? This to eliminate connection delays by polling the server.
About your provided solution, your solution is nice, I discovered two problems with a comport stream:
a) When I call system.wait( <stream var>, <delay> ); get an error "is not a function", meaning the stream is not a function when still created;
b) The comport stream.canRead returns allways false even when there is data on the bus. If I call stream.getByte() I get bytes (also a null byte or sometimes smilies (ASCII character 2) when there is no data (still stream.canRead is false before calling getByte()), memory allocation problem when there are smilies?)
When I call system.wait( <server var>, <delay> );it is working fine. I use this in my server.update() function.
Here is an example how I use it (server class):
this.update = function()
{
if( !this.running )
{ return false; }
if( !system.wait( this.http, 0 ) )
{ return false; }
if( !this.http.anyoneWaiting )
{ return false; }
system.gc();
var client = this.http.accept();
if( client == null || !client.canRead )
{
return false;
}
.......................
.......................
etc....
}
And the main loop looks like this:
while (!system.kbhit())
{
if( !server.update() )
{
serial.update();
}
}
However, I can't use
system.wait( <stream var>, <delay> ); at serial.update() function and cannot use
serial.stream.canRead to determine there is any data because it always returns false.
i decided to use a workaround by calling stream.getByte() however this
cause a performance delay because the serial port is initialized with a
timeout, however this depends on current port settings. JSDB only gets
the current config and configures the baudrate and that's it?
Now I am using stream = new Stream('COM'+comPort+'://'+baudRate, "rwactb" ); and there is no exceptional delay when using stream.getByte(), however I need to run another program that sets the port settings to the correct settings and then create the com stream, this works as expected.
I created a batch file (windows) to set the com parameters before creating the stream.
setcom.bat
@echo off
mode COM%1 baud=%2 parity=n data=8 stop=1 to=off xon=off odsr=off octs=off dtr=off rts=off idsr=off >NUL
To give you some idea how I use it:
function serialStream = function()
{
...........................
...........................
this.open = function( iComPort, iBaudRate )
{
this.close();
this.comPort = __ifUndef( iComPort , 1 );
this.baudRate = __ifUndef( iBaudRate, TSS_DEFAULT_BAUD );
system.execute( 'setcom.bat', this.comPort+' '+this.baudRate );
sleep( 1000 ); // Need some delay to execute, avoid port is in use.
try { this.stream = new Stream('COM'+this.comPort+'://'+this.baudRate, "rwactb" ); }
catch( e ) { this.stream = false; }
return ( this.isConnected() );
};
.......................
......................
}
Anyway, any idea why the stream.canRead always return false (also tried "rwactb+") ?And, althought my comport solution works fine, is there more elegant way to do this?
Some info JSDB:
system builddate: May 17 2012, release: 1.8.0.7, js-version: 1.8
OS:
Windows 7 Ultimate, 64bit, 16GB ram
Thank for any reply, kind regards,
codebeat
Op woensdag 25 juli 2018 18:46:42 UTC+2 schreef Shanti Rao: