length_array() issue
annuello
Posts: 294
Gday all,
I've noticed some "interesting" behavior with length_array(), which had me baffled for several days. It doesn't seem to like constant strings. If it is called several times on the same constant string, the master locks up (including bringing down comms to the master). I've been too familiar with the PRD switch & power plug while trying to figure out this issue.
An example:
When using a constant string & the truncate button [dvTp,1] is more than once, the master locks up. When using a non-constant string the master runs without issue.
So I guess my question is:
Is it bad practice to use length_array() on a constant string, or is it a bug with the compiler/master firmware?
I've sinced changed the offending line to something that works, but I thought others may be interested in this issue.
I'm using:
NI-3100 v3.13.339 / v1.12.140
NLS build 2.5.0.163 (NetLinx compiler 2.3.0.0)
Yours,
Roger
I've noticed some "interesting" behavior with length_array(), which had me baffled for several days. It doesn't seem to like constant strings. If it is called several times on the same constant string, the master locks up (including bringing down comms to the master). I've been too familiar with the PRD switch & power plug while trying to figure out this issue.
An example:
PROGRAM_NAME='LengthArray test' DEFINE_DEVICE dvRelay = 5001:8:0 dvTp = 128:1:0 DEFINE_CONSTANT //char cDelimiter[] = ';' //Can lock up the master DEFINE_VARIABLE char cText[50] char cDelimiter[] = ';' //Works fine. //constant char cDelimiter[] = ';' //Can lock up the master DEFINE_START DEFINE_EVENT button_event[dvTp,1]{ push:{ if(length_array(cText) > 0){ wait 10 'test'{ //Works fine. // cText = left_string(cText, length_array(cText) - 1) //Can lock up the master if cDelimiter is a constant string. cText = left_string(cText, length_array(cText) - length_array(cDelimiter)) send_command dvTp, "'!T',1,cText" } } } } button_event[dvTp,2]{ //Restore push:{ cText = 'The quick brown fox jumps over the lazy dog.' send_command dvTp, "'!T',1,cText" } } DEFINE_PROGRAM
When using a constant string & the truncate button [dvTp,1] is more than once, the master locks up. When using a non-constant string the master runs without issue.
So I guess my question is:
Is it bad practice to use length_array() on a constant string, or is it a bug with the compiler/master firmware?
I've sinced changed the offending line to something that works, but I thought others may be interested in this issue.
I'm using:
NI-3100 v3.13.339 / v1.12.140
NLS build 2.5.0.163 (NetLinx compiler 2.3.0.0)
Yours,
Roger
0
Comments
This:
DEFINE_CONSTANT
char cDelimiter[] = ';' //Can lock up the master ? and will
To this:
DEFINE_CONSTANT
char cDelimiter[] = {';'} //Will not lock up the master
Then life will be good.
Thanks for the insight. I didn?t know Netlinx could be brought to its knees in this scenario, doesn?t seem right to me.
DEFINE_CONSTANT
//Queue constants
CHAR cQDelim[3] = '~!~' //delimiter for queues
INTEGER nQDelimLen = 3
And then I just use nQDelimLen instead of LENGTH_ARRAY(cQDelim) I don?t think your way is bad practice, I?m just lazy and don?t like to type more than I have to.
I have alway put braces around character arrays that were defined as constants. This is the way it was taught in the AMX programming classes.
I guess we now know why.
This appears to be yet another instance of the good old "not coping with single character strings" problem. Treat single character strings with enormous respect.
For the record I'm using NLS v3.0.0.315 on v3.50.430 firmware.
Roger McLean
Swinburne University