Hi Folks, I am working on an iOS project where I am receiving data over a TCPSocket in response to commands being sent. There are two types of data being received in response to a specific command. The first command returns typical ASCII text in which I successfully handle using the following:
[b]dim mBuffer As xojo.Core.MemoryBlock
dim buffer As Text
The second command returns a string of ASCII data that I need to convert to integers and store in an array. The bytes are weighted and summed with every 4 bytes added to an UInt32 array. In a desktop app, I successfully do something similar to the following for each set of 4 bytes:
I am struggling with the second part in terms of converting the data in the iOS space. Any assistance with what that code may look like would be greatly appreciated.
@Sean Pons You are struggling but what happens in detail? You don’t get the right values? (maybe an endianness problem) or do you get an error/crash?
and for the moment, I have buffer to dump into a textarea just so I can see what is coming over. I get a list of Chinese characters.
UTF16 doesnt fail but that encoding cannot be right. Using ASCII or UTF8 in the place of UTF16 causes: Runtime Exception: The data could not be converted to text with this encoding. No other encoding seems to work.
What I need is to read each byte as decimal ASCII and ultimately store in an integer array.
@Sean Pons Well, you are working with raw bytes in the second part so you absolutely don’t want to make any conversion and the TextEncoding should be nil (BTW, a string with a nil encoding will not be converted by Xojo). However, I am curious to have a hex-dump of the raw data.
On iOS memory block and string (text) are different.
On desktop you can switch from one to the other.
so keep your mBuffer as xojo.core.memoryblock and read directly the Uint32Value.
On serial you have a buffer (string/memory) and with read(1) you advance one byte for each read so you build you UInt32 byte by byte.
But if you do a read(4) and then from the string/memory you can get the UInt32Value in one step.