Antenna Communication (IGC)

From Space Engineers Wiki
Jump to navigation Jump to search

Prerequisites

Inter Grid Communication

Inter Grid Communication (IGC) allows messages to be sent between Programmable Blocks.

There are two types of messages; broadcast and unicast.

Broadcast messages are available to all Programmable Blocks (that register for it)

Unicast messages are sent to a specific Programmable Block (only).

Messages

Messages contain

  • Tag. The tag is the identification used to determine the expected contents of the message. Tag should be chosen to be unique, or to match a known tag.
  • Data. The actual data of the message. The message data sent can be any immutable type. That means it’s not changeable.The simplest message is just a string
  • Source. The source of the message (who sent it). The source can be used to send unicast messages back to the sender.

Receiving Messages

Check for messages existing on a channel with .HasPendingMessages. Get the next message in the channel with .AcceptMessage

while (_myBroadcastListener.HasPendingMessage)
{
    MyIGCMessage myIGCMessage = _myBroadcastListener.AcceptMessage();
}

Each channel can have multiple messages pending. When accepted, that message is removed from the queue so it must be processed or it will be lost.

Broadcast

To receive broadcast messages, a channel must first be opened. The name of the channel must be specified as a tag. Only messages sent on this channel will be received.

Unicast

There is a predefined unicast channel. All messages sent to the Programmable Block are received on the one unicast channel. Tags should be checked by the receiver to process the messages correctly.

Sending Messages

Broadcast

Broadcast messages are sent to a named channel defined in the tag.

IGC.SendBroadcastMessage(_broadCastTag, theString);

Data sent can be any of the specified types. The easiest is string. But other complex types can be created.

Here is a list of types that can be sent/received in IGC messages.

The SendBroadcastMessage method also has an optional distance parameter. This allows messages sent to be limited in their distance traveled.

There are three main distances defined * AntennaRelay. This is the default distance. Messages will be sent to all listeners in antenna range. * CurrentConstruct. This limits the message to broadcast listeners that are on the current construct. * ConnectedConstructs. This limits the message to broadcast listeners that are connected together physically; including through connectors.

This code sends a broadcast message, but only to local constructs.

IGC.SendBroadcastMessage(_broadCastTag, theString, TransmissionDistance.CurrentConstruct);

Unicast

Unicast messages are sent to a specified Programming Block. This allows more efficient use of communications to only those scripts that are affected by the information.

IGC.SendUnicastMessage(targetID, _unicastTag, argument);

Example code

I’ve created a number of examples of using IGC. I’ve also created a world with all of the scripts loaded for easy demonstration.

  1. Simple Echo
  2. Light Toggle
  3. Echo with wicoIGC
  4. Echo and Unicast send/receive with wicoIGC

Debugging messages

  • Ensure that the grid is within antenna range. An antenna can RECEIVE messages even if it’s transmit range is lower, but any messages it sends will not make it to the destination.
  • Make sure “Enable Broadcast’ is on or messages will not be RECEIVED



We all owe a great thank you to Wicorel for taking the time to write this tutorial and all the examples. This tutorial was adapted from the original on Malware's MDK wiki, by Malware.