Error Opening Serial Port

Information
OS - Windows 7
Arduino - Arduino Uno r3

Details - So I tried running a small piece of code on the arduino, everything was working fine. Then towards the end of uploading, a message popped up. It said, Error opening serial port. And there was a drop down asking e to pic a different com port. I went to Devices and printers and the arduino was responsive and was shown as com port 11. I tried again but to no avail. Please help. Any responses are appreciated.

Here is the code I was running. It's the basic sweep example with a small modification.
// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.

#include <Servo.h>

Servo myservo;
Servo myservo2;// create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}

void loop()
{
for(pos = 0; pos < 360; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos);
myservo2.write(pos);// tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos);
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

usman204:
Details - So I tried running a small piece of code on the arduino, everything was working fine. Then towards the end of uploading, a message popped up. It said, Error opening serial port. And there was a drop down asking to pick a different com port. I went to Devices and printers and the arduino was responsive and was shown as com port 11. I tried again but to no avail. Please help. Any responses are appreciated.

In your Arduino IDE, click "Tools". When that pops open, click "Serial port".

The port that your Arduino board is on should be listed in the dropdown. In your case, there should be a listing of "COM11" (and possibly others). Select COM11 and try again.

Sometimes, Windows and/or certain motherboards don't properly support higher com port numbers. If the above doesn't work, try this:

Go into your Windows device manager and find a LOW com port number that isn't being used. Maybe you have an existing COM1 and COM2, but COM3 and above are free. If so, go to your COM11 (Arduino) port "Properties" and change it's port number to COM3 (or whatever LOW com number is available).

Go back to your Arduino IDE Tools / Serial port option. COM3 (or whatever you used) should now show up. Select that port and try the upload again.

Hope this helps... that's all I can think of for now.

It seems as a problem with an USB ports. Try to connect the device to other usb ports.