Quick question… if I parse through the data in the dataAvailable event in a serial port, is it safe to assume the ‘self.bytesAvailable’ will not change for that instance of the event (even though more data is coming in)? For instance, let’s say it fires w/ 100 bytes in the buffer. I process those bytes, using a loop, and while that is happening… 50 mores bytes are received. Will those bytes reflect ‘self.bytesAvailable’ during that event… or will the dataAvailable event fire again after the main thread gets back to it w/ the new data and updated count?
Hope I made it clear of the question in which I’m asking… thanks!
[quote=201741:@Norman Palardy]unless you poll you should not get overlapped events
if you DO poll you can get one event happening when processing one already[/quote]
Awesome… appreciate it. One more question, I’m trying to tackle (and it’s somewhat related to the serial port; however, a xojo.core.mutableMemoryBlock in general). I’m trying to take the information out of the serial and inject it into this mutableMemoryBlock. In the other memoryBlock, you can simply refer the string to it like:
myMemoryBlock = self.readAll
However, in order to insert string/text into the new memoryBlock components… you are required to specify a textEncoding (unless I’m mistaken) and use ‘convertTextToData’. No encoding that I have found will work for raw data bytes coming in. Is there a simple way to do what I need using the new framework? If not currently, is there any future plans to perhaps implement a ‘raw’ encoding or something similar for this?
I have this same question. I’m struggling with how to convert bytes to text/strings and back again. Is there a RAW encoding that will just allow me to stuff bytes of text or string into the new memory block? How should I approach this? Setting an encoding so that I can use the convertTextToData function results in nothing showing up in my memory block because the text starts with a 0 byte.
However, in order to insert string/text into the new memoryBlock components… you are required to specify a textEncoding (unless I’m mistaken) and use ‘convertTextToData’. No encoding that I have found will work for raw data bytes coming in. Is there a simple way to do what I need using the new framework? If not currently, is there any future plans to perhaps implement a ‘raw’ encoding or something similar for this?[/quote]
But you’re inserting BYTES - not strings or text
Mutable memory blocks have an insert method
I couldn’t figure out how to get the new memoryblock to work with text. I had some data from a socket and used split to divide up the server’s response. I needed to MD5 the results of some manipulation of the response. The resulting string had a 0 byte in it. I couldn’t find an encoding that would allow the bytes after the 0 to survive.
I ended up using the old memory block instead so I could use string instead of text. It works fine.
How would I go about using Text and the new memoryblock for this code.
[code]dim challengeString as string = DecodeHex(challenge) //challenge is a text representation of hexadecimal bytes
dim zero as string = chr(0) //defined as first part of response in spec
dim responseString as string = zero+password+challengeString
dim m as MemoryBlock = responseString
dim md5block as MemoryBlock = Crypto.MD5(m)
I don’t have to, I was just trying to use the new framework. If I ever ported this tool to iOS, which I have thought about briefly, I think I would have to use text wouldn’t I?
I’m just wondering if there is something I am missing in the new framework, or if this type of byte/string manipulation is just not fully fleshed out in the new framework.
I’m not really sure how I should phrase the problem statement. All I know is that it felt like going down a rabbit hole trying to make that bit of code above work with text and the new framework’s memoryblock. I kept having to add new bits to the code to try and get things into and out of memory blocks. The encoding issue was what ultimately beat me.
Hopefully it’s just my unfamiliarity with the new framework.
Is there a split and join for the new memoryblock? I don’t think I could get by without those. Most of the protocols I deal with in socket code are human readable (text or bytes whatever you prefer to call it). There is always some parsing needed, and split, join and instr are what I just the most.
I see there is an IndexOf which looks like it would take the place of InStr. It looks like I would need to create my own split and join though.