Determine the byte/buffer length iOS app

Questions, FAQ, Feature Requests and Troubleshooting for Airconsole

Moderator: sergey

Wilbe
Posts: 1
Joined: Sat May 14, 2016 12:24 am

Determine the byte/buffer length iOS app

Postby Wilbe » Sat May 14, 2016 12:32 am

I have used the airconsole SDK to write an app but I cannot figure out how to determine the correct byte count or buffer count. The code provided in the idk works but with a buffer length of 1024 some of the strings in "NSString s" are joined as if there is a null value between the strings. How die session class work and how can I determine the buffer or byte length before populating it into a string. Alternatively everything can be read and then added to a string.

daniel
Posts: 127
Joined: Wed Jul 27, 2011 9:33 am

Re: Determine the byte/buffer length iOS app

Postby daniel » Mon May 16, 2016 4:39 am

Hello,

The SDK example assumes that the byte stream sent by the serial device is pure text data with no nulls, strange codes, etc. It's not a bullet-proof example as the comments in the code indicate; it's more for demonstration purposes.

To answer your questions:
- when bytes are received on the serial port you get a callback "readBytesAvailable" with a count parameter. The count parameter indicates how many bytes are currently available to be read from the serial port at this instant.
- your code calls [AirconsoleSession read] and passes in a buffer of your choosing - the return code indicates how many bytes were transferred into your buffer. You choose the size of this buffer according to your needs; the SDK will fill it up as much as possible. The SDK example uses a fixed 1024 byte buffer, but this of course could be dynamically allocated to match the "count" parameter passed to readBytesAvailable.
- you now have a buffer of bytes you can use, if you want to convert this to a string, then you'll need to know what format your strings are in - e.g. what character encoding, and what line termination (if any). This shouldn't be a mystery as you know the type of serial device you have connected the Airconsole to. The SDK example assumes, a.) UTF-8 character encoding, and b.) no line termination - data is a stream of characters.

You may want to look at some articles such as http://stackoverflow.com/questions/2793 ... ted-string for help converting bytes into NSString objects.

Hope that helps


Return to “Airconsole”

Who is online

Users browsing this forum: No registered users and 29 guests