I am trying to send information from my python script through bluetooth to another system. In the code I am need to give the COM port for connecting. But, even though both the laptops are connected I am unable to send information from the script.
I am getting the following error: "could not open port 'COM3': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)"
I used the following code:
import serial
def send_data_via_bluetooth(device_port, data):
try:
with serial.Serial(device_port, baudrate=9600) as ser:
ser.write(data.encode())
print("Data sent successfully.")
except Exception as e:
print(f"Error sending data: {e}")
# Replace "COM3" with the appropriate COM port for your Bluetooth device
target_device_port = "COM3"
data_to_send = "Hello, Bluetooth!"
send_data_via_bluetooth(target_device_port, data_to_send)