So I'm working in Unity3D, programming in C#, and I heard that one can read data from a Bluetooth adaptor via SerialPort. I have several Bluetooth USB adaptors that I've tried to connect on my PC using this method. However, when I try to open the SerialPort, I get an error message that says port does not exist. I only included the code relevant to the question, but portI is a string ("COM11" or "COM12") and PortIn is of type SerialPort.
void OnGUI() {
GUI.Label(new Rect(btnX, btnY, btnW, btnH), "PortIn = " + portI);
if(!connected) {
for (int i = 0; i<ports.Length; i++) {
if(GUI.Button(new Rect(btnX, btnY + btnH + (btnH * i), btnW, btnH), ports[i])) {
portI = ports[i];
}
}
}
if(GUI.Button(new Rect(btnX + (btnW * 2 + 20), btnY, btnW, btnH), "Connect")) {
portIn = new SerialPort(portI, 9600);
portIn.ReadTimeout = 1000;
if (!portIn.IsOpen) {
portIn.Open();
}
connected = true;
}
}
}