Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

format
Source Link
Cédric Julien
  • 81.2k
  • 16
  • 131
  • 134

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'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:

  1. changing file name from 'serial.py' to 'any_other_name.py' and vise versa
  2. deleting related .pyc file
  3. Installing 'pip install pyserial'
  4. 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

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:

  1. changing file name from 'serial.py' to 'any_other_name.py' and vise versa
  2. deleting related .pyc file
  3. Installing 'pip install pyserial'
  4. 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

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:

  1. changing file name from 'serial.py' to 'any_other_name.py' and vise versa
  2. deleting related .pyc file
  3. Installing 'pip install pyserial'
  4. 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

Source Link

Serial Communication: python

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:

  1. changing file name from 'serial.py' to 'any_other_name.py' and vise versa
  2. deleting related .pyc file
  3. Installing 'pip install pyserial'
  4. 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

lang-py

AltStyle によって変換されたページ (->オリジナル) /