Type: BCS.Sym3.IDeviceMessage

Represents a Message object

        	// add the message if it doesn't exist
        msg = Project.Messages.Get("ConveyorInput");
        if (!msg) {
        	msg = Project.Messages.New("ConveyorInput");
        	msg.DeviceMessageID = 101;
        	msg.MessageType = Project.DataTypes.Get("ConveyorMessageBody");
        	msg.HandlerFunction = "";
        	msg.Input = true;
        }

Properties


DeviceMessageID

  • Description: The ID of the Message
  • Type: Int32
  • Access: Read and Write

HandlerFunction

  • Description: The Script Handler function (for input message only)
  • Type: String
  • Access: Read and Write

Input

  • Description: True for Input messages, False for Output messages
  • Type: Boolean
  • Access: Read and Write

MessageType

  • Description: The Data Type defining the message body structure
  • Type: IUserDefinedType
  • Access: Read and Write

Examples:

//******************************************************************************
// HOW TO : Device Messages
//******************************************************************************


//------------------------------------------------------------------------------
// How to create
//------------------------------------------------------------------------------

// create a new entity
var newEntity = Project.Messages.New()
print("A new entity has been created with default name: " + newEntity.Name)

// create a new entity with a specific name
var newEntity2 = Project.Messages.New("MyMessage")
print("A new entity has been created: " + newEntity2.Name)



//------------------------------------------------------------------------------
// How to access entity
//------------------------------------------------------------------------------

// get by name using method 'Get'
var entity1 = Project.Messages.Get("MyMessage")
print("Get entity by name: " + entity1.Name)

// get by name using operator []
var entity2 = Project.Messages["MyMessage"]
print("Get entity by name: " + entity2.Name)

// get by index:
var entity3 = Project.Messages[0]
print("Get entity by index: " + entity3.Name)


//------------------------------------------------------------------------------
// How to loop
//------------------------------------------------------------------------------


var entities = Project.Messages.Objects;
for (var i = 0; i < Project.Messages.Count; i++) {
    
    print(entities[i].Name);
}


//------------------------------------------------------------------------------
// How to delete
//------------------------------------------------------------------------------

// remove entity
Project.Messages.Remove(newEntity)


//------------------------------------------------------------------------------
// How to edit
//------------------------------------------------------------------------------

var myMessage = Project.Messages.New("MyMessage")

// change properties:
myMessage.Name = "MyMessage2";

// The ID of the Message
myMessage.DeviceMessageID = 100;

// The Data Type defining the message body structure
myMessage.MessageType = Project.DataTypes.Get("ConveyorMessageBody")

// The Script Handler function (for input message only)
myMessage.HandlerFunction = "OnMyHandler";

// set the message to be an output message
myMessage.Input = false;