2014-09-26 3 views
0

나는 phisiological 매개 변수를 얻을 수있는 센서를 구입했습니다; 내 컴퓨터에 블루투스 프로토콜로 연결되어 있으므로 직렬 포트 (예 : 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 포트의 선택에 대한 비 정적 절차를 가질 것 : 내 생각이다 주기 내 모든 PC에서 감지하고 블루투스 어댑터가있는 포트만 선택하십시오.

아이디어가 있습니까?

감사

안드레아

답변

0

미끄러운 경사를 직렬 장치입니다 자동 감지. 당신이 절대적으로, 나는 그냥 (안된) 이런 식으로 뭔가를 보이는 새로운 헬퍼 클래스를 만들 것해야하는 경우

class MyAutoDetector 
{ 
    public MyAutoDetector(){} 

    public SewDevice AutoDetect() 
    { 
     SerialPort comPort; 
     SewDevice myDevice = null; 
     eErrorClassOpcodes reply; 

     foreach(string portName in SerialPort.GetPortNames().ToList()) 
     { 
      comPort = new SerialPort("COM10"); 
      myDevice = new SewDevice(ref comPort); 

      reply = myDevice.StartStreaming(); 
      if (reply == eErrorClassOpcodes.Ok) 
      { 
       // ok device is connected and streaming is started 
       break; 
      } 
     } 
     return myDevice; 
    } 

나는 SewLib에 대해 알고하지 않습니다하지만 당신은 그 전송 속도, 비트, 인코딩 등을 확인해야합니다 일반적으로 직렬 포트를 다음과 같이 구성합니다 .... 그러나 SewLib이이를 수행합니다. 당신이 고유 PID/VID를 알고 일이면

또 다른 옵션, 여기에 대한 답변 : How do I get serial Port device id?