Completing Message Configuration and Posting Messages

Use PAscript to complete message configuration and post messages.

Before you begin, create or open a new PAscript in the Messages folder you created in Adding Messages to a Message Table. To create a PAscript, click New..., then click Programming » PAscript.
Complete the following steps to complete message configuration in PAscript:
  1. Define Base as the namespace.

    The global class Message is part of the namespace Base.

  2. Instantiate an object of the message class by passing the following parameters to the constructor function.
    • int32: The variable of the message ID as a reference.
    • text: The variable or constant that specifies the origin of the message. For example, the text variable might specify PAscript as the origin of the message.
    • variant: The value table Message_PAscript.WTB. Define the variant Message_PAscript.WTB in section globals. The value table is part of the BaseModule Message. Do not pass a different value table to the constructor function.
  3. Register the message table on the message system using the :Init() class function.

    To register the message table, use one of the following options.

    Note A call to the :Init() function can only occur once, not cyclically. If a PAbasic program or PAscript program registered the message table, do not call the :Init() function again.
    Table 34. Options to Register the Message Table
    Option Description Parameters to pass to the :Init() function
    Register the message table without using the module logbook. Messages are not recorded in any logbook on the PXI controller.
    • Message table.
    • Message visibility.
      • <message object>:show_in config: The message table is visible in the configuration tab of the message userbox.
      • <message object>:hide_from_config: The message table is invisible in the configuration tab of the userbox.
    Register the message table using an existing module logbook.

    Send messages to an existing logbook when the following conditions are met:

    • Another PAbasic or PAscript program opened the module logbook.
    • The log descriptor has been assigned.
    • Message table.
    • Message visibility.
      • <message object>:show_in config: The message table is visible in the configuration tab of the message userbox.
      • <message object>:hide_from_config: The message table is invisible in the configuration tab of the userbox.
    • int32: The variable of the module file descriptor as a reference.
    Register the message table and create a module logbook. Create a logbook for the messages.
    • Message table.
    • Message visibility.
      • <message object>:show_in config: The message table is visible in the configuration tab of the message userbox.
      • <message object>:hide_from_config: The message table is invisible in the configuration tab of the userbox.
    • int32: The variable of the module file descriptor as a reference.
    • text: The variable or constant that specifies the name of the logbook that you are creating.
  4. Optional: Use the following class functions to add logic code to set and reset messages.
    • :Set()
    • :Reset()

    If you add logic for a message, do not configure the message according to Configuring a Monitorings Group to Show Messages. Using the set function and the reset function allows you to provide more complex logic than you can specify in the Monitorings group.

    Using the set and reset functions, enter the number of the message that you want to set or reset. Enter the number in the message table.

Example: Instantiate and Register the Message Table

using BASE
 
program  
    section globals
        variant[] myMessages_MSG.WTB    // message subtable name
        variant[] Message_PAscript.WTB
        int32 myMessages_MSG.ID         // message id name that was added to the variables group
        int32 myMessages_LogDesc
    endsection
 
    text myPabasic(20) = "myPAbasic"
    text myLogName(20) = "myLog" 
 
    // set a unique message id value in myMessages_MSG.ID
    Message Msg(ref myMessages_MSG.ID, myPAbasic, Message_PAscript.WTB)    // first argument is the message ID name that was added to the variables group
 
    section initialization
        // initialize the myMessages_MSG.WTB table
        Msg:Init(myMessages_MSG.WTB, myMessage:show_in_config, ref myMessages_LogDesc,  myLogName) // first argument is the subtable name
    endsection
 
endprogram

Example: Set and Reset a Message

if Temperatur_01.AV > 300 then
  myMarker = 1
  myMessage:Set(1)    //Set Warning
endif
 
if Temperatur_01.AV <= 300 and myMarker == 1 then
  myMarker = 0
  myMessage:Reset(1)  //Reset Warning
endif
Refer to PAscript in the PAtools User Manual for more information about PAscript.