Post

Replies

Boosts

Views

Activity

Reply to fatal error: Index out of range...
What is golfDBdata? I don't see it declared in the code you showed. I assume it's an array. How many elements does it have? => testDBdata is golfDBdata What is numDB? What is its value? numDB is initialized as 1. The error message is telling you that the value of numDB is greater than or equal to the number of elements in golfDBdata. Another potential problem you have is you are running the code asynchronously. You may be trying to access data before it's been fetched. => this may be right guess. so, i think, "DispatchQueue.main.async " is related with this error. => self.golfDBdata isn't initialized yet, someone advised me that i need to initialize golfDBdata at class initializer or at property intializer. => some book says that it is not recommanded that using Array item in DispatchQueue.
Oct ’23
Reply to fatal error: Index out of range...
var id = UUID() @Published var output = "Disconnected" @Published var connected = false @Published var databasePath = String() enum itemType : Int{ case angle = 1 case degree = 2 case grip1 = 3 case grip2 = 4 } struct test_Array: Identifiable { var id = UUID() var time: String var swingNum : Int var dataSeqInSwing: Int var timeStampInSeq: Double var itemType: Int var value: Double } @Published var golfDBdata = [test_Array] () ..... private var centralManager: CBCentralManager? func connectCalculator() { output = "Connecting..." centralQueue = DispatchQueue(label: "test.discovery") centralManager = CBCentralManager(delegate: self, queue: centralQueue) } .... func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { ..... if characteristic.uuid == outputCharUUID, var data = characteristic.value { ..... DispatchQueue.main.async() { for index in tupleSets { strItemSets = index.components(separatedBy: ",") ....... ....... var countItem = 0 var numDB = 1 var itemN = 1 for indexStr in strItemSets { self.golfDBdata[numDB].dataSeqInSwing = countItem. <= Error self.golfDBdata[numDB].itemType = itemN self.golfDBdata[numDB].value = Double(strItemSets[itemN]) ?? 0.0
Oct ’23
Reply to how can i make a ios bluetooth classic program? is this Mission Impossible?
#include "BluetoothSerial.h" BluetoothSerial SerialBT; bool isconnected = false; void Bt_Status (esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { if (event == ESP_SPP_SRV_OPEN_EVT) { Serial.println ("Bluetooth: Connected"); isconnected = true; } else if (event == ESP_SPP_CLOSE_EVT ) { Serial.println ("Bluetooth: Disconnected"); isconnected = false; } } void setup() { Serial.begin(115200); while (!Serial); Serial.print("\n"); Serial.println("dbg> ESP32 Test program. Start ..."); SerialBT.register_callback (Bt_Status); Serial.println("The device started, now you can pair it with bluetooth!"); if(!SerialBT.begin("ESP32")){ Serial.println("An error occurred initializing Bluetooth"); }else{ Serial.println("Bluetooth initialized. Bluetooth Started!"); Serial.println("Bluetooth device name(ESP32), Ready to pair..."); } } void loop() { if (Serial.available()){ char command = Serial.read(); Serial.print("Recived command : "); Serial.print(command); Serial.print(", "); if(command == '3'){ Serial.println("REQ#3:"); cmd_tx_result_data1(); //test1: make string & TX data: swing raw data, bluetooth } else{ Serial.println("Wrong command(3)"); Serial.println("Usage: "); Serial.println(" REQ#3: make string & TX data"); } } } void cmd_tx_result_data1() { String tx_data1 = "here is some format code"; if (isconnected) { Serial.print("dbg> tx_data1 = "); Serial.println(tx_data1); SerialBT.print(tx_data1); } else { Serial.println ("dbg> Bluetooth: Client Not Connected"); } }
Jul ’23