Problem when serial port already active
Posted: Thu Apr 30, 2015 3:00 am
I have a situation where data is continuously generated by a serial port connected to anAirConsole 2, and the app I’m developing must be able to start up at any time, even if data is already being generated. My app reads and analyses the data stream using bluetooth. The app works perfectly if the app is started (and a connection is established) before any data is generated. However, things go wrong if the serial port is already generating data before the app is started.
If the app is started before data is generated by the port, events occur in the expected order:
1. I instantiate an airconsoleMgr object, disable WiFi, assign a delegate and call scanForDevices.
2. deviceAdded is invoked, where I instantiate an airconsoleSession object, assign a delegate, setLineParameters, setFlowControl and call the connect method.
3. sessionDidConnect is invoked, where I call stopScanning.
Note: The call to stopScanning, as I notice is mentioned in another post here, surprisingly causes deviceRemoved to be invoked, but this seems to have no bad effect.
4. sessionBytesAvailable is repeatedly invoked, where I read the incoming data.
However if data is already being generated before the app starts, the order is different:
After DeviceAdded runs, there is a call to sessionBytesAvailable, then a call to sessionDidConnect, followed by repeated calls to sessionBytesAvailable. (Surely this is not what is supposed to happen?) Also, the data received in all calls to sessionBytesAvailable is completely garbled — regardless of which flow control method is chosen at both ends.
The workarounds I tried had no effect:
1. Calling the flush method just before connecting.
2. Dismissing calls to sessionBytesAvailable until sessionDidConnect has completed (but flushing).
My app also needs to automatically re-connect when the device briefly goes out of range and then returns within range. I can’t do this because of the same problem: when I re-connect, data generation is already in progress, so only garbled data is received from then on.
Is this a known problem, is there a workaround or when could a fix be expected? It’s a real showstopper for my app.
Fwiw here is my test setup: An AirConsole 2 is connected to a Digitech Serial to USB adaptor which is connected to a USB hub which connects to a USB port on my Mac. Data is generated by the CoolTerm app, sending the contents of a large text file to the port. My app runs under iOS8.2 on a (physical) iPhone5. 4800 baud, 8 bits, no parity, 1 stop bit, XON, DTR or no flow control.
Help appreciated.
Bill
If the app is started before data is generated by the port, events occur in the expected order:
1. I instantiate an airconsoleMgr object, disable WiFi, assign a delegate and call scanForDevices.
2. deviceAdded is invoked, where I instantiate an airconsoleSession object, assign a delegate, setLineParameters, setFlowControl and call the connect method.
3. sessionDidConnect is invoked, where I call stopScanning.
Note: The call to stopScanning, as I notice is mentioned in another post here, surprisingly causes deviceRemoved to be invoked, but this seems to have no bad effect.
4. sessionBytesAvailable is repeatedly invoked, where I read the incoming data.
However if data is already being generated before the app starts, the order is different:
After DeviceAdded runs, there is a call to sessionBytesAvailable, then a call to sessionDidConnect, followed by repeated calls to sessionBytesAvailable. (Surely this is not what is supposed to happen?) Also, the data received in all calls to sessionBytesAvailable is completely garbled — regardless of which flow control method is chosen at both ends.
The workarounds I tried had no effect:
1. Calling the flush method just before connecting.
2. Dismissing calls to sessionBytesAvailable until sessionDidConnect has completed (but flushing).
My app also needs to automatically re-connect when the device briefly goes out of range and then returns within range. I can’t do this because of the same problem: when I re-connect, data generation is already in progress, so only garbled data is received from then on.
Is this a known problem, is there a workaround or when could a fix be expected? It’s a real showstopper for my app.
Fwiw here is my test setup: An AirConsole 2 is connected to a Digitech Serial to USB adaptor which is connected to a USB hub which connects to a USB port on my Mac. Data is generated by the CoolTerm app, sending the contents of a large text file to the port. My app runs under iOS8.2 on a (physical) iPhone5. 4800 baud, 8 bits, no parity, 1 stop bit, XON, DTR or no flow control.
Help appreciated.

Bill