How to read IOs with C#.
EugeneB
✭
Hi, everyone.
I'm wondering - How can I read IO from IRC5 controller with C#? Example - when di1 is changed I would like to make some actions. This is my pseudo code:
"
// Cn = new Controller;
Cn.?? += SignalChangedEven;
Thank you.
I'm wondering - How can I read IO from IRC5 controller with C#? Example - when di1 is changed I would like to make some actions. This is my pseudo code:
"
// Cn = new Controller;
Cn.?? += SignalChangedEven;
private void SignalChangedEven(Object sender, SignalChangedEventArgs e)
{
if (cn.? == true)
{
}
if (true)
{
do something;
}
}
"Thank you.
Tagged:
0
Best Answer
-
Hello,
you can find some info on the following web site:
http://developercenter.robotstudio.com/blobproxy/devcenter/RobotCommunication/html/455b4712-8d1d-499b-90ef-72a2e4209563.htm
below you will find an example for the FlexPendant SDK but it will also work for the PC-SDK.
In this example are 4 signals in an array is connected to the event.
But you can also use a single declaration for a signal and is it also possible to connect several signal to the same event routine.//create the signal _sigActPosRet = new DigitalSignal[4]; for (int i = 0; i < 4; i++) _sigActPosRet[i] = (DigitalSignal) _ctrl.GetSignal(string.Format("doAct{0}_{1}_PosRet", _iActuatorNo.ToString("00"), i + 1)); private DigitalSignal[] _sigActPosAdv;
The event is activated in the Activate method of the form:</code>public void Activate() { try { for (int i = 0; i < 4; i++) { if (_sigActPosRet != null && _sigActPosRet[i] != null) _sigActPosRet[i].Changed += sigActPosRet_Changed; if (_sigActPosAdv != null && _sigActPosAdv[i] != null) _sigActPosAdv[i].Changed += _sigActPosAdv_Changed; } } catch (Exception ex) { ExceptionHandler.HandleException(this, "Activate", ex); } } </pre><div><br></div><br>In the event routine, it will be check if an invoke is required. If yes, the same routine is called again with the Invoke method.<br>If you want to know, which signal has triggered the event routine, you can cast the sender object to the uses signal type. Afterwards, you can use the signal name to compare which action should be executed.<br><br>In case you create for each signal a separate event routine, the sender object is not required because the current value of the signal is provided by the parameter "e.NewSignalState"<br><pre class="CodeBlock"><code>void sigActPosRet_Changed(object sender, SignalChangedEventArgs e) { try { // check if invoke is required if (InvokeRequired) { Invoke(new SignalChangedEventHandler(sigActPosRet_Changed), sender, e); return; } var signal = (DigitalSignal)sender; if (signal == null) return; Debug.WriteLine("Signal: " + signal.Name + " Value:" + e.NewSignalState.Value); if (_sigActPosRet[0] != null && signal.Name == _sigActPosRet[0].Name) _picLedActPosRet[0].Image = _imlLeds.Images[(int)e.NewSignalState.Value]; else if (_sigActPosRet[1] != null && signal.Name == _sigActPosRet[1].Name) _picLedActPosRet[1].Image = _imlLeds.Images[(int)e.NewSignalState.Value]; else if (_sigActPosRet[2] != null && signal.Name == _sigActPosRet[2].Name) _picLedActPosRet[2].Image = _imlLeds.Images[(int)e.NewSignalState.Value]; else if (_sigActPosRet[3] != null && signal.Name == _sigActPosRet[3].Name) _picLedActPosRet[3].Image = _imlLeds.Images[(int)e.NewSignalState.Value]; } catch (Exception ex) { ExceptionHandler.HandleException(this, "sigActPosRet_Changed", ex); } }
I hope this will help you.
Best regards
Micky5
Answers
-
Thank you Micky.
All this information really help me.0
Categories
- All Categories
- 5.5K RobotStudio
- 394 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 309 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