Ejemplo n.º 1
0
    void BGW_ReceiveData(object CustomData, UnityBackgroundWorkerArguments e)
    {
        try
        {
            //if(BTM_IsReceiving())
            //{
            //    Disconnect();
            //    Connect();
            //}

            while (true && BTM_IsConnected())
            {
                Debug.Log("BGW_ReceiveData");
                DataCommunicationHelper temp = (DataCommunicationHelper)CustomData;
                temp.receivedData = Marshal.PtrToStringAnsi(BTM_ReceiveDataFast(temp.dataToSend));
                e.Progress++;
                Thread.Sleep(1000);
            }
        }
        catch (Exception error)
        {
            e.HasError     = true;
            e.ErrorMessage = error.Message;
        }
    }
Ejemplo n.º 2
0
    void BGW_DeviceFinder(object CustomData, UnityBackgroundWorkerArguments e)
    {
        try
        {
            if (!isBTDevicesSearching)
            {
                isBTDevicesSearching = true;

                DeviceFinderHelper temp = (DeviceFinderHelper)CustomData;

                do
                {
                    if (temp.performFastFind)
                    {
                        temp.transferedText = Marshal.PtrToStringAnsi(BTM_GetDevicesNamesFast());
                    }
                    else
                    {
                        temp.transferedText = Marshal.PtrToStringAnsi(BTM_GetDevicesNames());
                    }
                    e.Progress++;
                } while (isBTDevicesSearching && temp.performLoopFind);
            }
        }
        catch (Exception error)
        {
            e.HasError     = true;
            e.ErrorMessage = error.Message;
        }
    }
Ejemplo n.º 3
0
 /**
  * Cherche les devices et tente un connexion
  * @param    CustomData  information lié au Bluetooth
  * @param    e           indique au thread qu'il y a eu une modification
  */
 void FindDevicesBegin(object CustomData, UnityBackgroundWorkerArguments e)
 {
     try {
         DeviceFinderHelper temp = (DeviceFinderHelper)CustomData;
         temp.transferedText = Marshal.PtrToStringAnsi(BTM_GetDevicesNamesFast());
         string[] devicesList = temp.transferedText.Split('\n');
         foreach (var device in devicesList)
         {
             if (device.Length != 0 && !(listDeviceChecked.Contains(device)))
             {
                 if (device.Contains(BEGIN_NAME_DEVICE))
                 {
                     if (checkBLSDevice(device, temp))
                     {
                         AddDeviceBLS(device, temp.surnameDevice);
                     }
                 }
                 else
                 {
                     listDeviceChecked.AddFirst(device);
                 }
             }
         }
         e.Progress++;
     }
     catch (Exception error) {
         e.HasError     = true;
         e.ErrorMessage = error.Message;
     }
 }
Ejemplo n.º 4
0
 void BGW_SendAndReceiveData(object CustomData, UnityBackgroundWorkerArguments e)
 {
     try
     {
         DataCommunicationHelper temp = (DataCommunicationHelper)CustomData;
         Debug.Log(temp.dataToSend);
         temp.receivedData = Marshal.PtrToStringAnsi(BTM_SendAndReceiveDataFast("WEL_REF"));
         e.Progress++;
     }
     catch (Exception error)
     {
         e.HasError     = true;
         e.ErrorMessage = error.Message;
     }
 }
Ejemplo n.º 5
0
    void BGW_DeviceConnector(object CustomData, UnityBackgroundWorkerArguments e)
    {
        try
        {
            DeviceConnectionHelper temp = (DeviceConnectionHelper)CustomData;
            temp.status = "Connecting to the device";
            e.Progress++;

            temp.status = Marshal.PtrToStringAnsi(BTM_ConnectToDevice(ddDevices.options[ddDevices.value].text));
            e.Progress++;
        }
        catch (Exception error)
        {
            e.HasError     = true;
            e.ErrorMessage = error.Message;
        }
    }
Ejemplo n.º 6
0
    void BGW_ReceiveByteData(object CustomData, UnityBackgroundWorkerArguments e)
    {
        try
        {
            //if (BTM_IsReceiving())
            //{
            //    Disconnect();
            //    Connect();
            //}

            while (true && BTM_IsConnected())
            {
                ByteDataCommunicationHelper temp = (ByteDataCommunicationHelper)CustomData;
                byte[] receivedArray             = new byte[temp.maxLength];
                int    byteArrayLength           = BTM_ReceiveByteDataFast(receivedArray, receivedArray.Length);

                if (byteArrayLength == -1)
                {
                    Debug.Log("BGW_ReceiveByteData data error");
                    return;
                }

                temp.receivedData = new byte[byteArrayLength];
                for (int i = 0; i < byteArrayLength; i++)
                {
                    temp.receivedData[i] = receivedArray[i];
                }

                //for (int i = 0; i < byteArrayLength; i++)
                //{
                //    Debug.Log(temp.receivedData[i] + " ");
                //}

                e.Progress++;

                Thread.Sleep(1000);
            }
        }
        catch (Exception error)
        {
            e.HasError     = true;
            e.ErrorMessage = error.Message;
        }
    }
Ejemplo n.º 7
0
        /**
         * parcours la liste des devices et effectu un connexion en recuperant son contenu.
         * @param    CustomData  information lié au Bluetooth
         * @param    e           indique au thread qu'il y a eu une modification
         */
        void CheckDeviceBegin(object CustomData, UnityBackgroundWorkerArguments e)
        {
            LinkedList <CommunicationDeviceBLS> ldb = new LinkedList <CommunicationDeviceBLS>(fdb.GetListDevicesBLS());
            string data;

            hm.MonitorIn();
            foreach (var device in ldb)
            {
                if (!device.isRunning)
                {
                    try {
                        Thread.Sleep(50);
                        string status = Marshal.PtrToStringAnsi(BTM_ConnectToDevice(device.nameDevice));
                        Debug.Log("Check " + status);
                        if (status.Contains("Connected"))
                        {
                            DataCommunicationHelper temp = (DataCommunicationHelper)CustomData;
                            // on va vider le buffer totalement du module bluetooth
                            // BTM_ReceiveDataFast ne recupère que les 127 permiers charactères
                            data = "";
                            do
                            {
                                data += Marshal.PtrToStringAnsi(BTM_ReceiveDataFast(device.nameDevice));
                            } while(data.Length % 127 == 0 && data.Length < 1270);

                            temp.receivedData = data;
                            temp.device       = device;
                            e.Progress++;
                            Thread.Sleep(50);
                            Marshal.PtrToStringAnsi(BTM_DisconnectFromDevice());
                        }
                    }
                    catch (Exception error) {
                        e.HasError     = true;
                        e.ErrorMessage = error.Message;
                        Debug.Log(error.Message);
                    }
                }
            }
            hm.MonitorOut();
        }