【发布时间】:2014-09-27 04:28:53
【问题描述】:
我买了一个能够获取生理参数的传感器;它通过蓝牙协议连接到我的电脑,所以当它连接时,会分配一个串行端口(例如 COM10)。 现在我正在编写一个简单的例程来实时读取数据:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SewLib;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SewDevice myDevice;
SerialPort comPort;
public Form1()
{
InitializeComponent();
comPort = new SerialPort("COM10");
myDevice = new SewDevice(ref comPort);
myDevice.OnSamplesReceived += new ReceivedSamplesHandler(ReceiveData);
}
private void btstart_Click(object sender, EventArgs e)
{
eErrorClassOpcodes reply = myDevice.StartStreaming();
if (reply == eErrorClassOpcodes.Ok)
{
// ok device is connected and streaming is started
}
}
这对我有用,但现在我需要一个非静态程序来选择 com 端口:我的想法是在我的电脑检测到的所有端口之间循环,并只选择带有蓝牙适配器的端口。
你有什么想法吗?
谢谢
安德烈亚
【问题讨论】:
标签: bluetooth serial-port cycle