0

Why I need to emphasized the web module.

Because when I used the code just communicate with terminal

import serial
import time
ser = serial.Serial('COM3', 9600, timeout=0)
var = raw_input("Enter something: ")
ser.write(var)
while 1:
    try:
        print ser.readline()
        time.sleep(1)
        except ser.SerialTimeoutException:
        print('Data could not be read')

It can works fine and output the humidity data.

But when I use another sketch with GET/POST the data by web it will output

could not open port 'COM3': WindowsError(5, 'Access is denied')

On the web

import serial
import web

ser = serial.Serial('COM3', 9600, timeout=10)

urls = (
    '/', 'index',
)

class index:

    def GET(self):
        return "Hello , World!!"



if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

And I got in localhost:8080 the Traceback

    C:\Python27\lib\site-packages\serial\serialwin32.py in open 
          raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError())) ...
    C:\Python27\lib\site-packages\serial\serialutil.py in __init__           
          self.open() ...
    C:\Python27\lib\site-packages\serial\serialwin32.py in __init__
          super(Serial, self).__init__(*args, **kwargs) 
    C:\Users\linda\about paper\raw\web_2.py in <module>
           ser = serial.Serial('COM3', 9600, timeout=10) 

enter image description here

If I commented the code on line 4

ser = serial.Serial('COM3', 9600, timeout=10)

It works and output "hello world", but I need to get the data on Arduino sensor.

I have try to use the super user for chrome and terminal, I still have some problem.

And somebody told maybe is terminal use the port, but if didn't use terminal to open Python how can I use it. I have tried multiple variations of this, but none of them seem to work. Any ideas?

gre_gor
  • 6,669
  • 9
  • 47
  • 52
sk87125
  • 1
  • 1
  • 1

0 Answers0