Access Input / Output signals of robot out of C#

Does anyone have a little example how to access input and output signals of a robot with c#? I am able to read and write I/Os of the interface IBooleanSignal. (Like the StartStop of an conveyor) But the robots I/Os are IBooleanSignalMap. How can I access the value of an IBooleanSignalMap?

Thank you!

To get the IBooleanSignal defined in a port of a IBooleanSignalMap you can do something like this:

//example: robotSignalMap is your IBooleanSignalMap

int testPort = 101; // the port you want to check the signal value
var portIndex = robotSignalMap.GetPortIndex(testPort);
if(portIndex != -1) // make sure port has a signal in it
{
var internalSignal = robotSignalMap.GetSignal(portIndex) as IBooleanSignalMap;
var value = internalSignal.Value;
}

Thank you for your replay. I tested it like this:

var sensorSignal = e.Component.Behaviors.Where(b => b.Type == BehaviorType.BooleanSignalMap);

foreach (IBooleanSignalMap ibs in sensorSignal)
{
if (ibs.Name == “Inputs”)
{
int testPort = 1; // the port you want to check the signal value
var portIndex = ibs.GetPortIndex(testPort);
if (portIndex != -1) // make sure port has a signal in it
{
var internalSignal = ibs.GetSignal(portIndex) as IBooleanSignal;
var value = internalSignal.Value;
}
}
}

The problem is: portIndex is everytime -1. Am I right: the testPort is the number of the signal? For example Input 1 = testPort = 1? Also IBooleanSignalMap doesn’t have a Value member. (internalSignal) Is it right to use here a IBooleanSignal?

Hello,

The IBooleanSignalMap is composed by ports. Ports will have signals only if you connect them to other signals OR if you manually assign a signal to them.

If you look at the following image. You will see that the robot has 2 signal maps (input/ouputs) with 4079 ports each. However, because they are not connected to any thing there are not signals on them.

In the next image, one of the ports is connected to another signal in other component. When you do a connection, the port (10) creates a signal (number 0) and connect that signal to the other end.

If you want to get the signal and its value for that port you will have to do this:

var portIndex = robotSignalMap.GetPortIndex(10); // this will return you 0, unless you have other connections
var internalSignal = robotSignalMap.GetSignal(portIndex) as IBooleanSignalMap;
var value = internalSignal.Value;

By the way, I made a mistake in my first example (as you noticed):

var internalSignal = robotSignalMap.GetSignal(portIndex) as IBooleanSignalMap;

should be:

var internalSignal = robotSignalMap.GetSignal(portIndex) as IBooleanSignal;

If you want to get the value of ALL signals in the map you can do this;

for (int i = 0; i < robotSignalMap.PortCount; i++)
{
var portIndex = robotSignalMap.GetPortIndex(i);
if (portIndex != -1) // make sure port has a signal in it
{
var internalSignal = robotSignalMap.GetSignal(portIndex) as IBooleanSignal;
var value = internalSignal.Value;
}
}

Yeah, that’s true, only when I connect a signal is (portIndex != -1) = true. But “var internalSignal = robotSignalMap.GetSignal(portIndex) as IBooleanSignal;” throws anyway a NullReferenceException.

Am I doing anything else wrong?

ISimComponent comp = IoC.Get<ISelectionManager>().GetSelected<ISimComponent>();
if (comp != null && comp != cashedComp)
{

var sensorSignal = comp.Behaviors.Where(b => b.Type == BehaviorType.BooleanSignalMap);

foreach (IBooleanSignalMap ibs in sensorSignal)
{
if (ibs.Name == “Outputs”)
{
for (int i = 0; i < ibs.PortCount; i++)
{
var portIndex = ibs.GetPortIndex(i);
if (portIndex != -1) // make sure port has a signal in it
{
var internalSignal = ibs.GetSignal(portIndex) as IBooleanSignal;
var value = internalSignal.Value;
}
}
}
}
}

portIndex is evertime 0, also, when I connect Output 10.

I am also wondering why it’s not enough to define the action of a signal like this:

Because when i program a robot in VC I can also use this output and I think they use the same methode, don’t they?

 

Hello,

I verified the issue. For some reason you cannot cast to IBooleanSignal, but you can just leave it as ISignal

ISignal internalSignal = ibs.GetSignal(portIndex);

and later cast the value

bool value = (bool)internalSignal.Value;

 

When you use the “Action Configuration”, you are just mapping the ouputs to action defined in the ActionScript. If your robot triggers an output and there was no signal in that output port, the map will trigger a generic signal from that port which will be caught by the Action script, otherwise it will use the signal in that port to trigger the event.