Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

CR3000 SDM command, address as variable?


Nico Mar 9, 2015 12:43 PM

Just tried to implement some menue in the CR3000 that would allow me to change the SDM address of devices connected via SDM.
But compiling for example a scan that contains the CSAT command with an variable instead of an integer at the position of the SDM address ID throws an error..
Any workaround?

this works:
CSAT3 (CSAT(1),1,3,98,CSAT_ExecParam)

this doesn't:
Var1 pickable from 0-14
CSAT3 (CSAT(1),1,Var1,98,CSAT_ExecParam)

>> Variable illegal in Parameter: Var1


Dana Mar 10, 2015 03:24 PM

Can you use a Constant Table? e.g.,

Public Dest(5)

ConstTable (SetAddr)
Const Addr = 0
EndConstTable

BeginProg
Scan (1,Sec,3,0)
CSAT3 (Dest(),1,Addr,91,10)

NextScan

EndProg

Refer to the CRBasic Help for additional information on the Constant Table.

Dana


Nico Mar 11, 2015 03:26 AM

Hi Dana,

Thanks, that worked reasonable well, but now I got some 'cosmetic' problem that is related.

I got the menu setup alright and while I was at it and implementing the behavior of keeping changeable SDM addresses during a recompile/restart/power-cycle I tried to get the same behavior for some flags I use all over the program (switch stuff on and off).

The flags are currently defined with the same ConstTable call and use the False/True Boolean type (converted to YES/NO per some constant defines).
To get the manipulated flag to stay over a recompile/power-cycle the MenuPick list needs to contain the constant as well which causes the menu to show '-1' for True/YES and '0' for False/NO.
If I leave the constant out of the MenuPick list the variable is being shown as YES/NO but doesn't survive a recompile/power-cycle.

example:
Const YES = -1 '(= True)
Const NO = 0 '(= False)

ConstTable
Const SDMadr_CSAT = 3
Const FLAG_Maintenance = NO
EndConstTable
Public Recompile = NO

DisplayMenu ("Custom",0)
MenuItem ("Maintenance",FLAG_Maintenance)
MenuPick (YES,NO)
SubMenu ("SDM address change?")
MenuItem ("SDM adr CSAT",SDMadr_CSAT)
MenuPick (SDMadr_CSAT,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
MenuRecompile ("Restart Now?", Recompile)
MenuPick (YES, NO)
EndSubMenu
EndMenu

in the CR3000 display the menu entry for 'Maintenance' then has got a 'NO' to the right of it, which is desirable but it doesn't keep the setting during a power cycle.
If I add 'FLAG_Maintenance' to the MenuPick list like this:

MenuPick (FLAG_Maintenance,YES,NO)

the choice taken will survive a power-cycle/recompile but the display menu to the right of 'Maintenance' then shows a '0' instead of a 'NO' which is not so cool..

Any workaround for that?

* Last updated by: Nico on 3/10/2015 @ 9:28 PM *


Dana Mar 11, 2015 03:37 PM

I'm not sure I completely understand. What OS are you using? When I load your code above, the pick list for RestartNow displays Yes, No (not -1, 0).

Dana


Dana Mar 11, 2015 03:54 PM

I think I may understand after looking a little further...

I'm not certain there is a way around this, since No is defined as 0 previously, so 0 is what gets used in the Constant Table.

I will, however, check with engineering and see if anything can be done in a future OS.

Dana


Nico Mar 12, 2015 05:13 AM

Hi Dana,

Thanks for looking into this further. The Logger is running OS.28 as of now, CRBasic is waiting for it's update of LoggerNET to the latest version.. 4.3 I think.

The 'problem' is not a big deal really, just not intuitive:

A)
if one uses the MenuPick list without the constant at the first position the 'YES'/'NO' shows up but it won't modify the constants value (re-compile will reset choices)

B)
if one uses the MenuPick list with the constant at the first position the 'YES'/'NO' doesn't show up (but '0'/'-1' instead) but it will modify the constants (re-compile will keep settings)

The following pic shows case A and B.
'Maintenance' MenuPick list doesn't contain the Constant that is set to 'NO', but for example 'Log LiveView's MenuPick list contains it (set to 'YES', which shows up as '-1')
http://imageshack.com/a/img538/3900/TNJEtm.jpg

Important bits of the code used for above pic:
...
Const YES = -1 'Yes is defined as True or -1.
Const NO = 0 'No is defined as False or 0.

{...}

ConstTable (CONSTANTs_Flags,0)
Const FLAG_Maintenance = NO
Const FLAG_LiveView = YES
EndConstTable

{...}

MenuItem ("Maintenance",FLAG_Maintenance)
MenuPick (YES,NO)
MenuItem ("Log LiveView",FLAG_LiveView)
MenuPick (FLAG_LiveView,YES,NO)
...

From my point it can just be a matter of the 'routine' that does the variable/constant display on the logger screen which behaves differently for these cases.
I naturally understand that constant names are merely placeholders for the value they represent up until compiling the code - from this point of view it's surprising to me that 'YES'/'NO' shows up at all (case A).


Nico Mar 12, 2015 05:29 AM

One more note.. if I put the constant's name LAST in the MenuPick list, like so:
...
MenuItem ("Log LiveView",FLAG_LiveView)
MenuPick (YES,NO,FLAG_LiveView)
...

then the menu will display 'NO'/'YES' again, but as with case B doesn't keep settings over a recompile (via MenuRecompile).


Dana Mar 16, 2015 04:06 PM

As was pointed out to me when I spoke with our developers about your question, Constants are basically a "one-way" reference. They provide a way that a name can be used to represent a value, but the reverse does not occur (e.g., everywhere in the program a -1 occurs, the datalogger does not look through all constants and return the name rather than the value).

Dana


Dana Mar 16, 2015 04:07 PM

Here is a reply from one of our other AEs in-house:

Here is an alternative way of solving it, though when working with FLAG_Maintenance, you give up the convenience of working with and storing boolean comparison and values. It requires doing string based comparisons (matching "YES" and "NO") and storing or transmitting an entire string byte array. It also requires typing in a "NO" or "YES" if interacting directly with the consttable. Noticed that I also changed the MenuPick for FLAG_Maintenance.

Const YES = TRUE
Const NO = FALSE

ConstTable
Const SDMadr_CSAT = 3
Const FLAG_Maintenance = "NO"
EndConstTable

Public Recompile
DisplayMenu ("Custom",0)
MenuItem ("Maintenance",FLAG_Maintenance)
MenuPick (FLAG_Maintenance,YES,NO)
SubMenu ("SDM address change?")
MenuItem ("SDM adr CSAT",SDMadr_CSAT)
MenuPick (SDMadr_CSAT,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
MenuRecompile ("Restart Now?", Recompile)
MenuPick (YES, NO)
EndSubMenu
EndMenu


Nico Mar 19, 2015 12:35 PM

Hi Dana.

Thanks for all the work.

I think I will be able to live with the '0' and '-1' in the menu.. I put some description in one of the lines so won't scratch my head what to do if needed.

Cheers,
Nico

Log in or register to post/reply in the forum.