CREATE_MULTI_BUFFER
jjames
Posts: 2,908
Has anybody used this with much success? It seems like it'd be neat to use. Just haven't actually tested it out.
Bueller? Bueller?
Bueller? Bueller?
0
Comments
I did a quick test with a couple of virtual devices and it works as advertised.
The code:
And the output after button 1 and button 2 is pushed:
I can’t think of a reason why I would use this command yet but I’ll have to keep it in mind as it may come in handy some day.
First - thanks for playing around.
The thing that made me stumble across this is that we often install several of the same type of equipment on a job. I.e. multiple Oppo bluray players, multiple Integra DTRs, etc. so of course I use one DATA_EVENT for each kind of equipment. I then use get_last and pull from the data.text and put it into its respective container to parse. I noticed on the last job that in rare occasions when the devices were firing info off at the same time, I either wasn't pulling out the data properly or get_last wasn't synced right when pulling it out. Or maybe . . . I'm not getting the full concept of data.text; is it a single buffer per DATA_EVENT, even when using an array? Or is it a single buffer per device in the DATA_EVENT?
Either way, this seems like a handy way to handle multiple devices in a single DATA_EVENT. This way there is a concrete indication of each device's received data.
I've wondered about the multi buffer function for a long time and recently thought about using it and then said screw it since I'm not using buffers much lately anyway unless I need to hold over 15999 bytes. I'd rather just use data.text and append to local vars in an array to achieve the same thing for multiple devices.
If you want to use created buffers you can just create an array of buffers that match an array of devices and in define start run a for loop to associate each buffer buffer to its device.
An in the strinfg event do something like this: I guess if a complete parse ready string is always received in one chuck the multi buffer might make sense but it's easy enought to do just using arrays that you control and fully understand.
I didn't show the def start in the code but I did elude to it in the text line above the code block. Normally I would just use a regular array and append data.text to it. In this example I'm receiving data well over 20kbytes so I went the CREATED BUFFER route.
My bad - sorry. I missed that part.
I don't really see how that would be possible. A data_event is run when the string comes in from the port. You may not get the complete string depending on timings, but data.text shouldn't have text from two different ports in one string event. The only scenario I can see where this might not work is if you have waits or some other delay in the data_event and data.text is getting overwritten before you have emptied it.
Paul
You will need an array per device to store your data.text if you want to keep it separate. Otherwise you are mingling them together by using local_var and appending the new data to the old.
Paul
I should also add s_buffer[i_index] = "s_buffer[i_index],data.text" after the WHILE loop as well; this parsing routine was shown to me by someone when I first start programming and eventually saw that it was actually taken from TN 616.
I should also note, that it seems that CREATE_MULTI_BUFFER skips over the need of creating multi-dimensional character arrays, which looks tempting to be honest.
If the data did arrive in segments spanning more than one event you would still need to handle it in a var array of your own creation and concantenate your data for each device in it's own container until ready for processing.
This seems to be the case and it makes sense. The multi buffer has delimiters separating the strings between devices.
"Each command string placed in the multi-buffer has a three-byte header associated with it. The first header byte, $FF, marks the start of a new command string, the second header byte is the number of the device (not the Port number) that received the string, and the third byte is the length of the string, as shown below:
$FF, device number or DEV[ ] index, length, <string>"
Personally I prefer to roll my own, as I have found hard to trace bugs when using these types of built in stuctures. YMMV.
Paul
I'm not sure what to make of it now. I wonder what the capacity of the entire string is and does it concantenate into each delimited section or does it just add to the end of the string with its ID delimeters.
If it adds to the existing section of the string that's sort of neat but makes finding strings a little more laborious since you have the potential of essentially having to look through several buffers while looking for a particular string before getting to the string section begining with the correct ID to then start your search. Of course if you trigger off of data.text on the incoming and then pull from the buffered string that's not so laborious. I usually prefer to do that anyway when web scraping or dealing with other large strings that come in chunks less than the D.T limit. Of course I could always just keep updating my find_string pointer.
If the incoming strings just get added to the end that complicate the code cuz you either have to pull out strings as they come in and concantenate into your own array which makes using the multi buffer pointless or you wait for a specific ending tag to trigger your parsing and then collect the various sections with matching IDs.
Maybe there's a reason it's stayed in the shadows all these year.