MessageWritten event problem
SL
✭
Hello all,
How can I figure out in the MessageWritten event handler, which controller threw the event? Below is shown briefly (in C#), how I have tried to do that.
Any help would be much appreciated!
controller1.EventLog.MessageWritten +=
new EventHandler<MessageWrittenEventArgs>(MsgWritten);
controller2.EventLog.MessageWritten +=
new EventHandler<MessageWrittenEventArgs>(MsgWritten);
...
private void MsgWritten(object sender, MessageWrittenEventArgs e)
{
// Trial 1:
EventLog evlog = (EventLog)sender;
if (controller1.EventLog == evlog) { // never goes here }
if (controller2.EventLog == evlog) { // always goes here! }
// Trial 2:
// EventLog messages are iterated and e.Message is searched from
// there using Timestamp and SequenceNumber fields.
// For simplicity, all code is not shown, but here the same occurs: // message is found always from controller2.
bool bFound1 = FindMessage(e.Message, controller1.EventLog); // never here
bool bFound2 = FindMessage(e.Message, controller2.EventLog); // always here!
}
0
Comments
-
Short assumptions and recommendations:if you are running on a FP SDK, they are the same Controller.if you are running on a PC SDK, the best alternative is to connect each Event log to a different event handler, and then make a call to another routine that handles the message for your appliaction. This is some pseudo-code as a work around:controller1.EventLog.MessageWritten += new EventHandler<MessageWrittenEventArgs>(MsgWritten_1);controller2.EventLog.MessageWritten += new EventHandler<MessageWrittenEventArgs>(MsgWritten)2);...private void MsgWritten_1(object sender, MessageWrittenEventArgs e){MsgWritten_1(controller1, e)}private void MsgWritten_2(object sender, MessageWrittenEventArgs e){MsgWritten_2(controller2, e)}private void MsgWritten(Controller controller, MessageWrittenEventArgs e){}Carlos Martinez
ABB0 -
OK, I was quessing it would be the work around. I'll try that.Thank you very much, Carlos, for your help.It would be nice to see this fixed in future RAB versions.0
-
Has this issue been fixed? How does RobotStudio do it? Does anyone have a solution?0
-
No, it is not fixed currently. The event handler get as parameter the "object sender" (which is an "EventLog"); this variable contains controller information, but this is declared as private and thus not usable in your own code.
0 -
Hello,
you can use reflection to read the controller data from the sender.
Please see following code:private void EventLog_MessageWritten(object sender, ABB.Robotics.Controllers.EventLogDomain.MessageWrittenEventArgs e) { ABB.Robotics.Controllers.EventLogDomain.EventLog log = (ABB.Robotics.Controllers.EventLogDomain.EventLog)sender;<pre class="CodeBlock"><code>
PropertyInfo piCtrlInfo = log.GetType().GetProperty("Controller", BindingFlags.NonPublic| BindingFlags.Instance);
Controller ctrl = (Controller)piCtrlInfo.GetValue(log);
string s = string.Format("{0} | {1} - {2}", ctrl.SystemName, e.Message.CategoryId * 10000 + e.Message.Number, e.Message.Title);
}
Best regards
Micky0 -
That is OK, but reflection is slow - by its very nature and if connected to 100's of controllers it is not great. Would be better if ABB made the controller available
0 -
Have you tried with a lambda expression .. (pseudo code)
controller1.EventLog.MessageWritten += (o, e) =>
{
// Here you can call your method, and provide the instance of the controller (since you have access to it at this point). You can also pass the EvengLog (o) if you need it
MyEventLog_MessageWritten(controller1, e);
};
private void My MyEventLog_MessageWritten(Controller theController, ABB.Robotics.Controllers.EventLogDomain.MessageWrittenEventArgs e)
{
}Carlos Martinez
ABB0
Categories
- All Categories
- 5.5K RobotStudio
- 395 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings