Workaround to open COM port for serial communication on client-side (preferably in Python)
<h2>Goal</h2>

<p>I have made a website using the Flask framework and am fairly comfortable with HTML, CSS, JS, Python. My goal is to connect an arduino to the <strong>client's</strong> PC's usb port and use serial.write() to send a number to it.</p>

<h2>Notes</h2>

<p>I have a working example of <a href="http://playground.arduino.cc/Interfacing/Python" rel="nofollow">interfacing with python</a> if arduino was connected to the server. </p>

<pre><code>import serial
ser = serial.Serial('COM4', 9600)
ser.write('5')
</code></pre>

<p>Now I want to run these exact 3 lines on the client side. </p>

<p><strong>Is this even doable?</strong> I have researched a lot and it seems that this is not doable due to security reasons? (I'm hoping somebody proves me wrong here.) That is why I'm looking for a workaround. But before that I must mention, I don't need any of the data (numbers) to come from the server. Once the webpage is loaded all serial communication that I need is on the client side.</p>

<p><strong>Client side python</strong>: I have looked into writing python on the client side and read about skulpt and PyPyjs but am not sure how I could run the mentioned 3 lines with them on client side(neither seems to support <em>pyserial</em> needed for <em>import serial</em> or at least I have not had any luck finding documentation)</p>

<p>I also looked into arduino documentation for <a href="http://playground.arduino.cc/Main/InterfacingWithSoftware" rel="nofollow">interfacing with software</a> but it seems that all the languages mentioned are server side. If you know of any possible direction languages that could help, I'd be happy to know and go learn them. I saw many forums mentioning Node.js but my understanding is that would also only do the job on the server side.</p>

<p>I'd appreciate any help on where else/other topics I should look into. Thanks in advance.</p>

<blockquote>
  <p>Is this even doable? I have researched a lot and it seems that this is not doable due to security reasons? </p>
</blockquote>

<p>You are correct. There is no ability for browsers to access a COM port. It doesn't matter what language or framework you pick, a browser isn't going to give you that access.</p>

<p>You would need to make a standalone desktop application. You <em>can</em> use HTML and JavaScript to access serial ports, just not in a browser. Chrome <em>Apps</em> (which are actually going away) can do it, as well as an App that uses Electron.</p>

python arduino serial-port pyserial client-side-scripting