1

I am trying to interface with my com ports, specifically an XBee connected to thi using this code.

from xbee import XBee
from serial import Serial

PORT = 'COM3'
BAUD = 9600

ser = Serial(PORT, BAUD)

xbee = XBee(ser)
# Send the string 'Hello World' to the module with MY set to 1
xbee.tx(dest_addr='\x00\x01', data='Hello World')

# Wait for and get the response
print(xbee.wait_read_frame())

ser.close()

However, this error keeps arising.

SerialException: could not open port 'COM3': WindowsError(5, 'Access is denied.'). It goes away when I restart my computer, buts it keeps returning. I'd prefer to understand why its happening so I don't need to keep restarting my computer. Would really appreciate any help, thanks. I am working through the IDLE interface with python 2.7 just in case that is relevant.

1 Answer 1

1

A serial port can be "open" in only one application at a time. Once application "A" opens the port, application "B" will get an Access Denied error when it tries to open the same port. In your case, you need to figure out what other application is holding the port and close it first.

Sign up to request clarification or add additional context in comments.

2 Comments

I exited XCTU program, and I am not getting the error anymore, but how can I have the program running and use the XBees?
I've never heard of XBees. But the OS cannot logically allow two different applications to use the same port simultaneously, just as it cannot allow two applications to write to the same disk file simultaneously. There is no way to prevent data corruption in case of collisions. If your XBees library is controlling the serial port, you need to work with its API and forget about PySerial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.