Author Topic: DF1Com1 in C# - Simple issue. I think  (Read 3789 times)

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
DF1Com1 in C# - Simple issue. I think
« 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

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #2 on: April 21, 2018, 11:05:27 AM »
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.






Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: DF1Com1 in C# - Simple issue. I think
« Reply #3 on: April 21, 2018, 11:24:08 AM »
Is O:2/4 used in the ladder logic of the PLC?

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #4 on: April 21, 2018, 11:27:56 AM »
Nope..

I have an older application that does not include the C#


It works perfectly.

I have check that the com port is all good.

Thanks


authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #5 on: April 21, 2018, 11:28:38 AM »
I have nothing in the PLC.. I.e. no code.. just 1 empty ladder

« Last Edit: April 21, 2018, 11:30:25 AM by authorleon »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: DF1Com1 in C# - Simple issue. I think
« Reply #6 on: April 21, 2018, 11:38:51 AM »
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?

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #7 on: April 21, 2018, 11:47:09 AM »
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. ?

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #8 on: April 21, 2018, 11:48:25 AM »
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.
« Last Edit: April 21, 2018, 11:50:51 AM by Godra »

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #9 on: April 21, 2018, 11:53:33 AM »
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:



I am trying what you suggested now.


Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #10 on: April 21, 2018, 12:06:28 PM »
Can you post a picture of your RSLinx, just like the attached one?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: DF1Com1 in C# - Simple issue. I think
« Reply #11 on: April 21, 2018, 12:15:06 PM »
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.

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #12 on: April 21, 2018, 12:22:18 PM »
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:

Code: [Select]
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.


Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #13 on: April 21, 2018, 12:45:35 PM »
The code would be pretty much the same and for Toggle it could be like this:

Code: [Select]
    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:

Code: [Select]
    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
« Last Edit: April 21, 2018, 01:41:12 PM by Godra »

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #14 on: April 21, 2018, 06:43:33 PM »
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.

   
Code: [Select]
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.

Code: [Select]
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)
        {
         
        }
    }
}