AdvancedHMI Software
General Category => Support Questions => Topic started by: authorleon on April 19, 2018, 02:39:30 PM
-
Hello all,
I need to use C# because I need to use global hotkeys.
I am just setting up a basic program with one button, using an SLC 500.
Unfortunately I'm getting some errors and I don't know why.
I have had a look around but I don't know how to approach the problem.
Please have a look at the attached images.
Effectively I am just trying to get one button to work so it turns on output on the SLC 500.
I can get this working if I use .NET. But fortunately I stated before I need to get it working in C#...
I hope I have explained it clearly. These have a look at the attached images
-
See this:
https://www.advancedhmi.com/forum/index.php?topic=2013.msg11296#msg11296
-
Hello,
Fantastic... Right, I have done that. Also, I have VS 2017.
I have created a button, I am using DF1Com1 (AKA SerialDF1For5Com1). I assume that is the correct one. I run the program. the form comes up with the button. However, when I press the button, my AB SLC 500 does nothing. The relay does not toggle at all.
I am very close, thank you very much.
(https://i.imgur.com/wt78VRf.png)
(https://i.imgur.com/l0Z3aFA.png)
-
Is O:2/4 used in the ladder logic of the PLC?
-
Nope..
I have an older application that does not include the C#
(https://i.imgur.com/nkbbLfO.png)
It works perfectly.
I have check that the com port is all good.
Thanks
-
I have nothing in the PLC.. I.e. no code.. just 1 empty ladder
(https://i.imgur.com/DmzsJbe.png)
-
Try it on an internal bit such as B3/0. Also do you have RSLinx completely shutdown so the driver can get access to the com port?
-
Hello, I gave it a go.. Still the same...
Yes, of course. I have closed down RSlinx 100%.
Would TeamV be an option... as I really would love to get this sorted. ?
-
The correct driver should be SerialDF1forSLCMicroCom.
You should also know all your COM1 settings and include them in the driver properties:
- BaudRate, change from AUTO to exact baud rate for your PLC
- TargetNode, is usually 1 but use RSLinx / RSLogix to confirm
- Parity
- ChecksumType
As Archie suggested, you should have 1 rung with contact set to B3:0/0 and coil set to O:2/4.
Then change the PLCAddressClick to B3:0/0 and maybe select Toggle as OutputType.
-
The correct driver should be SerialDF1forSLCMicroCom.
You should also know all your COM1 settings and include them in the driver properties:
- BaudRate, change from AUTO to exact baud rate for your PLC
- TargetNode, is usually 1 but use RSLinx / RSLogix to confirm
- Parity
- ChecksumType
As Archie suggested, you should have 1 rung with contact set to B3:0/0 and coil set to O:2/4.
Then change the PLCAddressClick to B3:0/0 and maybe select Toggle as OutputType.
Hello,
I have all the config working:
(https://i.imgur.com/ZAY5IWl.png)
I am trying what you suggested now.
-
Can you post a picture of your RSLinx, just like the attached one?
-
You are not using the correct driver. The one you selected is for the PLC5, but I see you are using RSLogix500 which means you should be using the SLCMicro driver.
-
Thank you both very much, it is now working so I just want to confirm a few things.
With the new version: X399 you cannot use a button with a direct output. e.g. O:1/1 etc. You have to use B3:0/0 (Make a ladder B3:0/0 > O:1/1 )
The second part is that I utterly have a piece of code which allows for the board shortcuts:
If (e.KeyCode And Not Keys.Modifiers) = Keys.T AndAlso e.Modifiers = Keys.Control Then
DF1Com1.Write("O:1/0", "0") ' (O:9/0) (R)
End If
Could I have a little bit of help modifying this code so it would activate B3:0/0.
Once this has been achieved.
I will then focus on making global keyboard shortcuts. Thank you gents very much.
-
The code would be pretty much the same and for Toggle it could be like this:
Private switch As Boolean
Private Sub MainForm_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
If (e.KeyCode And Not Keys.Modifiers) = Keys.T AndAlso e.Modifiers = Keys.Control Then
If switch Then
Me.SerialDF1forSLCMicroCom1.Write("B3:0/0", "0")
switch = False
Else
Me.SerialDF1forSLCMicroCom1.Write("B3:0/0", "1")
switch = True
End If
End If
End Sub
or possibly this, which would be more accurate:
Private Sub MainForm_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
If (e.KeyCode And Not Keys.Modifiers) = Keys.T AndAlso e.Modifiers = Keys.Control Then
'Read current B3:0/0 value
Dim switch As Boolean = Me.SerialDF1forSLCMicroCom1.Read("B3:0/0")
If switch Then
Me.SerialDF1forSLCMicroCom1.Write("B3:0/0", "0")
Else
Me.SerialDF1forSLCMicroCom1.Write("B3:0/0", "1")
End If
End If
End Sub
-
Thank you very much... However I have realized that the code is in C#.
Here is the program had in the old application which worked. Of course I understand now that I have to use a B reference.
Private Sub MainForm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If (e.KeyCode And Not Keys.Modifiers) = Keys.T AndAlso e.Modifiers = Keys.Control Then
DF1Com1.Write("O:1/0", "1")
End If
End Sub
Private Sub MainForm_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If (e.KeyCode And Not Keys.Modifiers) = Keys.T AndAlso e.Modifiers = Keys.Control Then
DF1Com1.Write("O:1/0", "0")
End If
End Sub
Of course, I have now realized that the code is in C#.
Does anyone have the equivalent code in C# please. I have had to look online and consulted the Microsoft website but I tried that code and he did not work...
Much appreciated all.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AdvancedHMICS
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void basicButton1_Click(object sender, EventArgs e)
{
}
}
}
-
You seem to be learning how to do programming in C#.
Maybe you should look up some tutorials online.
Currently you have a form with a driver and a BasicButton control on it.
Adding any more controls in the future will not make it any simpler for you.
There are some online code conversion tools which convert VB to C#, like this one:
https://www.carlosag.net/tools/codetranslator/
You could also use SharpDevelop 4.4 program which has code converter built-in.
As for C# in AdvancedHMI, you need to be using the MainForm inside the AdvancedHMIcs project.
You also need to get familiar with Properties window, like the attached picture shows.
Lightning Bolt icon will show all events associated with selected object, whether it's a form or a control.
Double-clicking any of the events will create a code for you and take you to the code window.
If you manually add a code that you find somewhere online then you still need to associate that code with the event by selecting it in the properties window.
-
Fantastic !!!!!!!!!!!!!!! THANK YOU VERY MUCH!!!!!!!!!!
I love to learn and you have saved a lot of time!!!!!!!
Thank you again... A beer for you.
-
Hello,
Right, I have some progress now. I have global hotkeys working which is fantastic....
I just need a little bit of help tweaking the code please.
public void hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F12)
{
Me.SerialDF1forSLCMicroCom1.Write("B3:0/0", "0")
switch = False
}
else if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F11)
{
MessageBox.Show("Combinacion F11");
}
// show the keys pressed in a label.
}
Please note, I do not want a toggle function. I would like you that when the button is pressed ("B3:0/0", "1"). And when the button is released ("B3:0/0", "0"). In other words the action only continues when the button is pressed and held down. Once released the bit is put back to zero.
Thank you very much...
-
Right. I have the code working for toggle now....
For anyone, it if like this:
public void hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F12)
{
serialDF1forSLCMicroCom1.Write ("B3:0/0", "1");
}
else if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F11)
{
serialDF1forSLCMicroCom1.Write("B3:0/0", "0");
}
// show the keys pressed in a label.
}
I jsut need help with keep up and release...
Thank you all very much
-
You seem to be looking to assign those functions to global hotkeys (which you mentioned in your other topic https://www.advancedhmi.com/forum/index.php?topic=2036.0).
There still doesn't seem to be any solution for that.