Module command handler buffer problem?
maxifox
Posts: 209
I have a module that process' strings inside command (not string!) handler.
When I send a command (via send_command) the command handler is fired but there is nothing inside the buffer to parse and array length is zero.
Looks like buffers created with "create_buffer" keeps only strings sent with send_string (?):
I issued send_command dev, "com" and got
Then I issued send_string dev, "str" and got
finally send_command dev, "com2"
Is that behavior normal that I cannot use buffers with create_buffer for command handler? I would like to use the technic described in TN616 for command handlers as well...
Here is the master code:
and module code
I am running NI-4000 v3.00.316, Netlinx Studio build 2.4.0.123.
Thanks in advance.
When I send a command (via send_command) the command handler is fired but there is nothing inside the buffer to parse and array length is zero.
Looks like buffers created with "create_buffer" keeps only strings sent with send_string (?):
I issued send_command dev, "com" and got
Line 1 :: GOT COMMAND: - 11:16:01
Then I issued send_string dev, "str" and got
Line 2 :: GOT STRING: str - 11:16:11
finally send_command dev, "com2"
Line 3 :: GOT COMMAND: str - 11:16:20
Is that behavior normal that I cannot use buffers with create_buffer for command handler? I would like to use the technic described in TN616 for command handlers as well...
Here is the master code:
PROGRAM_NAME='master_test' DEFINE_DEVICE vdv = 33001:1:0; DEFINE_START DEFINE_MODULE 'mtest' mdl_test(vdv); DEFINE_PROGRAM
and module code
MODULE_NAME='mtest'(dev ddd) DEFINE_VARIABLE char buf[128]; DEFINE_EVENT DATA_EVENT[ddd] { COMMAND : { SEND_STRING 0, "'GOT COMMAND: ', buf"; } STRING : { SEND_STRING 0, "'GOT STRING: ', buf"; } } DEFINE_START CREATE_BUFFER ddd, buf; DEFINE_PROGRAM
I am running NI-4000 v3.00.316, Netlinx Studio build 2.4.0.123.
Thanks in advance.
0
Comments
Hello maxifox,
I never use create buffer but alway's date.text. See sample below:
DATA_EVENT[dev]
{
COMMAND:
{
IF(FIND_STRING(DATA.TEXT,'com',1))
{
SEND_STRING 0,"DATA.TEXT"
}
}
}
Works well for me.
Hopes it is usefull for you
The Data on Command Level can only be received by DATA.TEXT.
This works as designed. A COMMAND is always a complete instruction and is received in the DATA_EVENT handler at one step. This works because a COMMAND level instruction is an NetLinx internal handling and these type of data is always a full instruction.
But with strings (like from serial port or ethernet) , you MAY have received a complete instruction, but this is not sure. So if working with serial ports or - much more critical - with data via TCP (where almost every character triggers a data event), you should use a CREATE_BUFFER to receive and store the user data. and then work with the buffer array. The DATA_EVENTs STRING handler in this case is more or less only a trigger to launch the buffer parsing.
I hope this helps.
Regards,
I agree the question is more theoretical than practical but what is going with the buffers for command handlers? Does it work?
EDITED: Thank you, Marc. This is what I suspected - it is by design...
By design, a Send_Command payload has a maximum number of characters that should always fit into the DATA.TEXT default array size. And there is the advantage that it can be completely parsed in a single data event. I believe the maximum size of a Send_Command is approximately 2000 characters. Perhaps someone here knows the exact number.
Keep in mind all you are doing is shuffling data between one memory location to another. No data enters or leaves the box as with a physical com port.
However, I've found that it's not necessary to buffer SEND_COMMANDs, at least not in any application where I've used them. As Marc said, the whole thing is going to be there, just by the nature of how they work in the first place.
Not sure if this is certain though.
DATA.TEXT has a size of 2048 Characters.
See definition in the NetLinx.AXI
The largest hardware buffers in NetLinx have 2048 bytes (NXI and NXC-COM2).
On Ethernet, afaik the master has a larger hardware buffer, but still can only pick up 2048 bytes in one block to software. So like I recommended earlier in this thread, depending on the data awaited i.e. HTML or XML, I'll create a (HUGE (why not 30000 bytes) ) software buffer with CREATE_BUFFER for Ethernet handling.