Ejemplo n.º 1
0
        public BluetoothConnection()
        {
            port      = null;        //if a new SerialPort is instantiated here for some reason the portName is always "COM1" even if that's not a valid port on the PC so we make this nullable instead.
            bluetooth = new Bluegiga.BGLib();

            discoveredDevices = new List <BluetoothDevice>();
            tappyBuffer       = new List <byte>();
            isConnected       = false;

            bufferLock = new object();

            // Bluegiga Events

            bluetooth.BLEEventATTClientAttributeValue += DataReceivedFromTappy;
            bluetooth.BLEEventConnectionDisconnected  += Bluetooth_BLEEventConnectionDisconnected;
        }
Ejemplo n.º 2
0
        public void Connect_to_BLE_Device(string Addr, Bluegiga.BGLib bglib, SerialPort serialAPI, char symbol)
        {
            string[] AddrSplited = Addr.Split(symbol);
            byte[]   addr        = new byte[6];
            int      add         = 0;
            int      value       = 0;
            string   hex         = null;

            for (int i = 0; i < AddrSplited.Length - 1; i++)
            {
                value = Convert.ToInt32(AddrSplited[i], 16);
                byte charValue = (byte)value;
                addr[add++] = charValue;
            }


            //BLECommandGAPConnectDirect
            bglib.SendCommand(serialAPI, bglib.BLECommandGAPConnectDirect(addr, 0x00, 10, 250, 300, 0));
        }
Ejemplo n.º 3
0
        public BluetoothConnection()
        {
            port = new SerialPort();
            port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            port.Handshake     = Handshake.RequestToSend;
            port.BaudRate      = 115200;
            port.DataBits      = 8;
            port.StopBits      = StopBits.One;
            port.Parity        = Parity.None;

            bluetooth = new Bluegiga.BGLib();

            discoveredDevices = new List <BluetoothDevice>();
            tappyBuffer       = new List <byte>();
            isConnected       = false;

            bufferLock = new object();

            // Bluegiga Events

            bluetooth.BLEEventATTClientAttributeValue += DataReceivedFromTappy;
            bluetooth.BLEEventConnectionDisconnected  += Bluetooth_BLEEventConnectionDisconnected;
        }
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="portName">シリアルポート名</param>
 /// <param name="data">送信データ</param>
 /// <param name="isContinuationMode">自動継続モードにするかしないか</param>
 public SerialCommProcess(string portName, List<PLEN.MFX.BLEMfxCommand> mfxCommandList, bool isContinuationMode)
 {
     // シリアルポート初期化
     serialPort = new SerialPort();
     serialPort.PortName = portName;
     serialPort.Handshake = System.IO.Ports.Handshake.RequestToSend;
     serialPort.BaudRate = 115200;
     serialPort.DataBits = 8;
     serialPort.StopBits = System.IO.Ports.StopBits.One;
     serialPort.Parity = System.IO.Ports.Parity.None;
     serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(SerialDataReceived);
     // 送信モーションコマンドリストを登録
     sendMfxCommandList = mfxCommandList;
     // bgLib初期化.イベント登録.
     bgLib = new Bluegiga.BGLib();
     bgLib.BLEEventGAPScanResponse += new Bluegiga.BLE.Events.GAP.ScanResponseEventHandler(bgLib_BLEEventGAPScanResponse);
     bgLib.BLEEventConnectionStatus += new Bluegiga.BLE.Events.Connection.StatusEventHandler(bgLib_BLEEventConnectionStatus);
     bgLib.BLEEventATTClientProcedureCompleted += new Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventHandler(bgLib_BLEEventATTClientProcedureCompleted);
     IsContinuationMode = isContinuationMode;
 }