Data.Text question
vegastech
Posts: 369
Now that I have a few rs232 devices and a few IP devices running on my home system, I have a sort of educational question with regard to data.text: Since I am creating buffers for each of these devices, how does the system know what to put into which buffer, based on the initial flood of data into data.text, like at startup? I'm thinking in terms of an alarm system that is constantly (or at least frequently) sending zone status data, along with, say, a weather parsing function sending info as well. Does it ALL just go into data.text as it is sent, and then the coding figures it all out from there?
0
Comments
DATA.TEXT can easily be used e.g. to receive a keypad string from a panel or data (string, command) from a virtual and Duet device, because the data packet always is complete (imagine that the panel or virtual device is doing a SEND_STRING with the complete message native on NetLinx).
On a serial port or manually programmed IP communication, it is not quaranteed that the data the device has sent is a complete packet, containing the full working string from begin to end, espacially on IP connects. For example, you may expect 20 bytes for a full response on RS232, but after 10 bytes a "lag" in the datastream may occure, and so the datastream is not complete within time. You may now get a 1st Event where the DATA.TEXT contains the first 10 bytes, and from the lag, a second event with the next 10 bytes but the first received bytes get lost.
With the above limitation of 2048 bytes, using the DATA.TEXT you can receive "only" 2048 bytes in one event cycle, which may be too less on IP. CREATE_BUFFER automatically copies the incoming data from the port's inbuffer to the software array, and the software array can hold much more as the 2kB data.
http://amxforums.com/showthread.php?t=4406&highlight=mtu&page=6
DATA_EVENT[dev1]
{
STRING:
{
// handle data.text for dev1 here
}
}
DATA_EVENT[dev2]
{
STRING:
{
// handle data.text for dev2 here
}
}
etc.
Or you can use CREATE_BUFFER for each device and process the buffer variable in each string event as well. In that case, capture the data in each buffer as follows:
CREATE_BUFFER dev1,dev1_buffer
CREATE_BUFFER dev2,dev2_buffer
Through either approach, Netlinx will simply provide you with the incoming data from either dev1 or dev2. You don't have to worry about how it happens.
Hope this helps.
Sheldon Samuels
That's exactly what I was looking for! "each Data_Event has its own DATA.TEXT".
DEFINE_START
CREATE_BUFFER dev1,dev1_buffer
DEFINE_EVENT
DATA_EVENT[dev1]
{
STRING:
{
// process dev1_buffer here
}
}
In this way, you know that the dev1_buffer contains the incoming data for dev1 only, but you only have to worry about processing that incoming data when the DATA_EVENT is triggered.
It just depends on how you manage your devices and the incoming strings.
Hope this helps.
Sheldon Samuels
SchoolView Technologies, LLC
If the data coming in fits the size limits of data.text AND I'm not going to be doing any serious string chopping, I'll use data.text. I usually just create a stack_var buffer and dump data.text into it, chop away and leave the data_event with what I need.
If the data coming is is from a chatty device, I'll use data.text to append data to the end of a large buffer with a delimiter and setup a queue that handles the buffer elsewhere. This is how I handle all my module<->main program communication on modules I write myself.
For slower baud rate gear that is chatty but the messages are smaller I'll go with good ole' Define_Buffer. I've found that data.text can misfire on slower gear. It thinks the gear is done talking when it may or may not be.
For web page scraping, I almost always use define_buffer. It handles the larger data sizes and chunkiness of internet communications better in my opinion.