Exemplo n.º 1
0
    void BGW_ReceiveByteData_Progress(object CustomData, int Progress)
    {
        Debug.Log("BGW_ReceiveByteData_Progress");
        ByteDataCommunicationHelper temp = (ByteDataCommunicationHelper)CustomData;

        txtAnswer.text += BitConverter.ToString(temp.receivedData);
        Debug.Log(BitConverter.ToString(temp.receivedData));
    }
Exemplo n.º 2
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;
        }
    }
Exemplo n.º 3
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());
    }