I am trying to access a BlueSentry wireless bluetooth module, which is normally accessible through a virtual serial port. I managed to receive the data in Visual C# Express 2010, using the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
namespace BluetoothTest
{
class Program
{
static void Main(string[] args)
{
SerialPort sp = new SerialPort("COM13", 9600, Parity.None, 8, StopBits.One);
sp.Open();
sp.Write("2");
char[] strm = new char[15];
while (true)
{
sp.Write("*");
sp.Read(strm, 0, 15);
if (strm[0] == '-')
{
for (int i = 0; i < strm.Length; i++)
{
Console.Write(strm[i]);
if (i == strm.Length - 1)
{
Console.Write(strm[i] + "\n");
}
}
}
}
}
}
}
However, when I tried accessing the device through Unity, I got the following exception:
IOException: The port `COM13' does not exist.
The C# scipt I am using is the following:
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
public class Bluetooth : MonoBehaviour {
SerialPort sp;
char[] strm = new char[15];
void Start(){
sp = new SerialPort("COM13", 9600, Parity.None, 8, StopBits.One);
sp.Open();
sp.Write("2");
}
void Update(){
sp.Write("*");
sp.Read(strm, 0, 15);
if (strm[0] == '-')
{
for (int i = 0; i < strm.Length; i++)
{
Debug.Log(strm[i]);
if (i == strm.Length - 1)
{
Debug.Log(strm[i] + "\n");
}
}
}
}
}
I would appreciate any input.