void BGW_DeviceConnector_Progress(object CustomData, int Progress) { DeviceConnectionHelper temp = (DeviceConnectionHelper)CustomData; txtAnswer.text += temp.status + "\n"; if (temp.status.Contains("Connected")) { if (temp.receiveHexData) { ReceiveByteData(); } else { ReceiveData(); } } }
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; } }
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()); }