Beispiel #1
0
    void BGW_ReceiveData_Progress(object CustomData, int Progress)
    {
        Debug.Log("BGW_ReceiveData_Progress");
        DataCommunicationHelper temp = (DataCommunicationHelper)CustomData;

        txtAnswer.text += temp.receivedData;
    }
Beispiel #2
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;
        }
    }
Beispiel #3
0
    void BGW_SendAndReceiveData_Progress(object CustomData, int Progress)
    {
        Debug.Log("BGW_SendData_Progress");
        DataCommunicationHelper temp = (DataCommunicationHelper)CustomData;

        Debug.Log("Sent: " + temp.dataToSend + " Received: " + temp.receivedData);

        txtAnswer.text += temp.receivedData;
    }
Beispiel #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;
     }
 }
Beispiel #5
0
        /**
         * Supprime si l'appareil n'est pas connecté et sauvegarde les actions des joueurs.
         * @param    CustomData  information lié au Bluetooth
         * @param    e           indique au thread qu'il y a eu une modification
         */
        void CheckDeviceProgress(object CustomData, int Progress)
        {
            DataCommunicationHelper temp = (DataCommunicationHelper)CustomData;

            if (!temp.receivedData.Contains("I am connected with " + FinderDevicesBLS.NAME_GAME))
            {
                fdb.RemoveDevice(temp.device);
            }
            if (temp.receivedData.Contains("MOVE"))
            {
                isNeedMove = true;
            }
            if (temp.receivedData.Contains("PRESS"))
            {
                isSelect = true;
            }
        }
Beispiel #6
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();
        }
Beispiel #7
0
    void Start()
    {
        deviceFinderHelper = new DeviceFinderHelper()
        {
            performFastFind = true, performLoopFind = false
        };
        deviceConnectionHelper      = new DeviceConnectionHelper();
        dataSenderAndReceiverHelper = new DataCommunicationHelper();
        dataReceiverHelper          = new DataCommunicationHelper();
        byteDataSenderHelper        = new ByteDataCommunicationHelper();
        byteDataReceiverHelper      = new ByteDataCommunicationHelper()
        {
            dataToSend = new byte[maxByteLength], receivedData = new byte[maxByteLength], maxLength = maxByteLength
        };

        ubwDeviceFinder          = new UnityBackgroundWorker(this, BGW_DeviceFinder, BGW_DeviceFinder_Progress, BGW_DeviceFinder_Done, deviceFinderHelper);
        ubwDeviceConnector       = new UnityBackgroundWorker(this, BGW_DeviceConnector, BGW_DeviceConnector_Progress, BGW_DeviceConnector_Done, deviceConnectionHelper);
        ubwDataSenderAndReceiver = new UnityBackgroundWorker(this, BGW_SendAndReceiveData, BGW_SendAndReceiveData_Progress, BGW_SendAndReceiveData_Done, dataSenderAndReceiverHelper);
        ubwDataReceiver          = new UnityBackgroundWorker(this, BGW_ReceiveData, BGW_ReceiveData_Progress, BGW_ReceiveData_Done, dataReceiverHelper);
        ubwByteDataReceiver      = new UnityBackgroundWorker(this, BGW_ReceiveByteData, BGW_ReceiveByteData_Progress, BGW_ReceiveByteData_Done, byteDataReceiverHelper);

        FindDevices(true);
        StartCoroutine(StatusCoroutine());
    }
Beispiel #8
0
 /**
  * Constructeur privé
  */
 private CheckDeviceBLSConnected()
 {
     dataReceiverHelper = new DataCommunicationHelper();
 }