Strategy name in PAC Control


#1

I am looking for a way to automatically “retrieve” the strategy filename in PAC Control and then write that to a scratch pad string index. I know there are ways to view the strategy filename using PAC Control in Debug mode and going to Control Engine-> Inspect and also using PAC Terminal. Is there a way to get this piece of information using an action block or Optoscript block?

I have in the meantime created a variable and manually entered the strategy filename. Using an action block I have written that variable to a scratch pad string index (see attached images).

Any help would be appreciated,

Thanks,

Russ Stacy


Greatest Hits - and mini-lessons
#2

Hi Russ,

Welcome to the forums! Excellent question. I’d argue that there [I]should [/I]be a command, perhaps called [B]GetStrategyName[/B]. I’ve put in a request to our development team.

In the meantime, I’ve created one for you (a little subroutine that I believe does what you need). As someone might notice in a sniff, when PAC Control’s debug mode or PAC Terminal get the strategy’s name from your controller, they’re sending a “FILENAME” command to tcp port 22001 (assuming the default control engine port number). The command is followed by a CR (ASCII 13). The strategy name returned is preceded by 2 bytes of error code (both 0’s if all is okay).

So, the code you’ll find in the attached strategy/subroutine, looks something like this:

// This as assumes we want to talk to the host port, on 22001
sHandleValue = "tcp:127.0.0.1:22001";
SetCommunicationHandleValue(sHandleValue, chController);

// Open connection to port
nCHStatus = OpenOutgoingCommunication( chController );

if (IsCommunicationOpen( chController )) then // we opened the connection

  // Here's where we send the command to the local or remote controller
  sFORTHCommand = "FILENAME" + chr(13);
  nCHStatus = TransmitString( sFORTHCommand, chController );

  if (nCHStatus == 0) then // the transmit worked okay

    // receive the reply from the controller (should be 2 bytes of 0 if all went okay) 
    nCHStatus = ReceiveNChars( sResponse, 2, chController );

    // check for the 0x00 0x00 in the first 2 bytes
    if((nCHStatus == 0) and (sResponse[0] == 0) and (sResponse[1] == 0)) then 
      // no error back from the remote controller, see how many characters are waiting
      nNumChars = GetNumCharsWaiting( chController );

      if ( nNumChars > 0 ) then // we have a non-zero length strategy name waiting for us, let's read those chars
        //ReceiveNChars(Put in, Number of Characters, Communication Handle)
        nCHStatus = ReceiveNChars( sStrategyName, nNumChars, chController );
      endif
    endif
  endif

  CloseCommunication( chController );
endif

I’ve attached a little sample strategy as well as just the subroutine, both built in 8.0 (in case anyone out there is still using older PAC Control). You should be able to open these in PAC Control 8.0 Basic or higher.

Hope that helps! Thanks for the excellent question.

-OptoMary


#3

Mary,

This works great. Thank you so much for the quick response.

Russ


#4

Hi Russ,

Just a heads up, if you change your strategy name, you will lose all your persistent variables… (Page 222 of doc 1700)
Depending on how you have things set up (ie, you are not using persistent variables at all or you have an iron clad way of backing them up before each and every download), this may not be a big deal, but I wanted to point this out…

In other words, for 99.999% of people, 99.999% of the time, its a really bad idea to be using the strategy name as part of your version tracking system.

Ben.


#5

Ben,

Thanks for the heads up. I am not a programmer by nature, so I have to do a little reading to wrap my head around persistent variables. I am curious, do you have any suggestions for a better way to track versions of PAC Control strategies?

Thank you,

Russ


#6

Russ,

Tick the ‘create archive’ option in Pac Control, That will ensure that a date / time stamped zip file is made for you every single time you download.
Done.

This is usually enough. To top it off what I do is in the power up chart I throw in a date time comment that has a summery of what I changed/added.
You could also use a software versioning system (SVN for example) to manage the zip archives. I never did, I just backed them up nightly and relied on the comments in the power up chart.

Ben.


#7

GetStrategyInfo.zip (1.77 KB)
Here’s an sub that returns a little bit more info (the “Up Time” and “Active” timestamp, and datestamp like you’d see when you inspect a controller).

Also might want to check out [B]this thread[/B] for an elapsed time sample.


#8

Maybe I’m a bit a of a purist, but instead of inventing yet another PAC Control command, surely it would be better to map these things directly to the Memory Map, where they can be accessed by the PAC Control programmer, as required. Leave blank for non control engine based brains.

Way back in 1974, a certain Mr Engman needed only a total of 22 stock items in order to cover the entire worlds’ needs for SSR’s, while some four years later Kernighan & Ritchie needed only 32 keywords/command in order to define the entire C programming language.

Today we have 450+ commands in PAC Control and it still does not appear to be sufficient. :smiley:


#9

Wow, I haven’t thought about the K&R in a long time.

I do think having the strategy name in the mem map would be handy too. I added a request in our system for that as well. Good idea. Keep ‘em comin’!