billhsu / jUART

Cross platform browser plugin for serial port communication from JavaScript
202 stars 76 forks source link

Can't reconnect to device #49

Open X-Y opened 7 years ago

X-Y commented 7 years ago

System: Ubuntu 16.04 LTS Browser: Firefox plugin version: downloaded from bin/Linux_x86_64/npjUART.so at commit 979c040 Test process: Have an Arduino board constantly sending data to serial port connected to computer. With the following code, the data will be displayed to the console. However, if the device is disconnected and reconnected, calling ser.is_open() will return true, but no message can be received anymore

<html>
    <head>
        <title>test page for object fbcontrol</title>
    </head>
    <script type="text/javascript">
        var ser;
        function plugin0()
        {
            return document.getElementById('plugin0');
        }
        plugin = plugin0;

        function recv(bytes, size)
        {
            console.log(bytes);
        }

        function pluginLoaded() 
        {
            ser = plugin().Serial;// Get a Serial object
            ser.open("/dev/ttyACM0");// Open a port
            ser.set_option(115200,0,8,0,0);// Set port options 
            ser.recv_callback(recv); // Callback function for recieve data
        }

        setInterval(function() {
            if(!plugin().Serial.is_open()){
                console.log("reconnecting");
                pluginLoaded();
            }
        }, 1000);
    </script>
    <body onload="load()">
        <object id="plugin0" type="application/x-juart" width="0" height="0" >
            <param name="onload" value="pluginLoaded"  />
        </object><br />
        <h1>jUART Serial Port Echo Test</h1><br/>
        This test will echo the data you sent through serial port.
    </body>
</html>