I am using Python Anaconda 2.7. I would like to toggle the port using serial communication, But I am getting error: AttributeError: 'module' object has no attribute 'Serial'
My sample program is:
import serial
import time
#remember to adjust “COM3”
port = serial.Serial("COM3", 19200, timeout=0.5)
#turn on port 2, sleep 2 seconds, turn off port 2
port.write(b"\nF2\r")
time.sleep(2.0)
port.write(b"\nF2\r")
#turn on port 2 and 7, sleep 2 seconds, turn off port 2 and 7
port.write(b"\nF2\r\nF7\r")
time.sleep(2)
port.write(b"\nF2\r\nF7\r")
#close the port
port.close()
I have tried many solutions:
- changing file name from 'serial.py' to 'any_other_name.py' and vise versa
- deleting related .pyc file
- Installing 'pip install pyserial'
- Doing From serial import serial
When I run the same program from psychopy, it is working really fine. I don't know How to solve it. If some one can give me suggestions that It would be great help for me. Thanking you in advance.
Ravi