Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Larry Griffin

Pages: [1]
1
Open Discussion / Re: What would you like to see in the next major release?
« on: November 09, 2018, 01:25:22 PM »
Since you already have some "Run as a Service" solution, would you care to share it with members of this forum as well?

To provide a basis to build on, I'll first refer to the following MS tutorial on creating a windows service:
https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer

Once you've got a Service created, add an AHMI Com component such as ethernetIPforCLXCom, from the toolbox, to the design sheet.  You can now read from or write to the PLC just as you do within a normal Windows Forms App.

I wasn't able to get the DataSubscriber to work within a Service, possibly due to my own incompetence, although it had worked within a Windows Forms App.  But it's pretty easy to achieve the same thing.  I set up a 500ms timer to read a tag and compare it to the previous value.  If it has changed, then I call a function to deal with it.  That's essentially what the DataSubscriber does behind the scenes.

In my case, the data I wanted to collect was a 128-byte string that the PLC updates every 15 to 45 seconds.  In order to avoid having to read that entire string every 500ms, I setup a Boolean tag that the PLC toggles after every update of the 128-byte string.  So I can monitor the Boolean value every 500ms, but I only need to read the long string if the Boolean value has changed.  Note: The Boolean value is returned by ethernetIPforCLXCom.Read() as a string, i.e. "True" or "False", even though the PLC sends it as a bit, 1 or 0.

LG

2
Open Discussion / Re: What would you like to see in the next major release?
« on: November 07, 2018, 04:16:19 PM »
Run as a Service!  :)

Actually, I've got a C# app running as a service now, except that DataSubscriber wouldn't work so I had to manually implement it.

This works great for data logging!

Disclaimer: Yes, I'm compliantly including the source environment along with the Service app files.

LG

3
Tips & Tricks / Re: EthernetIPforCLXCom - Reading Complete UDT
« on: September 24, 2017, 12:03:47 PM »
This works very well, indeed!  C# example follows:

Code: [Select]
        // C# example

        var workOrder = new WO();

        // Read one complete WorkOrder from the PLC
        workOrder = ReadWO("WorkOrderTag")

Code: [Select]
    // Work Order Structure
    public class WO
    {
        public int Sequence;
        public string Description;
        public string ProductID;
        public string CustWO;
        publice string ThisWO;
        public float CasingLen;
        public float TubingLen;
        public int Qty;
        public int Priority;
     }

Code: [Select]
        // Method to read Work Order from PLC
        private WO ReadWO(string tag)
        {
            Byte[] bytes = ethernetIPforCLXCom1.ReadRaw(tag);
            WO wO = new WO
            {
                Sequence = BitConverter.ToInt32(bytes, 0),
                Description = System.Text.Encoding.Default.GetString(bytes, 8, BitConverter.ToInt32(bytes, 4)),
                ProductID = System.Text.Encoding.Default.GetString(bytes, 96, BitConverter.ToInt32(bytes, 92)),
                CustWO = System.Text.Encoding.Default.GetString(bytes, 116, BitConverter.ToInt32(bytes, 112)),
                ThisWO = System.Text.Encoding.Default.GetString(bytes, 136, BitConverter.ToInt32(bytes, 132)),
                CasingLen = BitConverter.ToSingle(bytes, 152),
                TubingLen = BitConverter.ToSingle(bytes, 156),
                Qty = BitConverter.ToInt32(bytes, 160),
                Priority = BitConverter.ToInt32(bytes, 164)
            };
            return wO;
        }


4
Support Questions / Re: Read string in UDT
« on: September 20, 2017, 03:19:54 PM »
It worked perfect, first time.  I also added an override for ToString() so I can easily read values back out of it.

Code: [Select]
    public class String20
    {
        public int Length;
        public System.SByte[] Characters;

        public String20()
        {
            Characters = new System.SByte[20];
        }

        public String20(string value) : this()
        {
            Length = Math.Min(20, value.Length);
            if (value.Length > 20)
            {
                value = value.Substring(0, 20);
            }
            byte[] TmpArray = new byte[20];
            System.Text.ASCIIEncoding.ASCII.GetBytes(value).CopyTo(TmpArray, 0);
            Characters = (sbyte[])(Array)TmpArray;
        }

        public override string ToString()
        {
            return System.Text.Encoding.ASCII.GetString(Array.ConvertAll(Characters, a => (byte)a));
        }
    }

Thank you so much for the help.  Would be nice if custom strings could be automatically handled by .WriteUDT, but this is workable for now.
Looking forward to .ReadUDT too.  Soon?

LarGriff

5
Support Questions / Re: Read string in UDT
« on: September 19, 2017, 05:50:26 PM »
Not VB.  C#.

Code: [Select]
    // Work Order Structure
    public class WO
    {
        public int Sequence { get; set; }
        public string Description { get; set; } = "";  // STRING82
        public string ProductID { get; set; } = "";  // STRING20
        public string CustWO { get; set; } = "";  // STRING20
        public string ThisWO { get; set; } = "";  // STRING20
        public float CasingLen { get; set; }
        public float TubingLen { get; set; }
        public int Qty { get; set; }
        public int Priority { get; set; }
    }

6
Support Questions / Re: Read string in UDT
« on: September 19, 2017, 12:17:12 PM »
This works okay for reading.
Is there a fix for writing?

That is, I can't do a complete .WriteUDT to a UDT that contains multiple custom strings shorter than 82.  The first custom string gets written, but subsequent strings are empty.
And if I try to .WriteUDT to one custom string member of the UDT I get a "Not Enough Data" error.

LarGriff

7
Open Discussion / Re: Complete noob here
« on: April 07, 2017, 05:25:14 PM »
Terrific!  ...Liking this more and more...

LarGriff

8
Open Discussion / Re: Complete noob here
« on: April 07, 2017, 04:44:07 PM »
Thanks for the quick response, Archie!

After a little experimentation, what I ended up doing was to keep everything on one form, but use Containers Panels to contain the controls I want on each "screen".  Then I use a row of buttons to select the Visibility properties.

private void panel1Button_Click()
{
   panel1.Visible = true;
   panel2.Visible = false;
   panel3.Visible = false;
}

private void panel2Button_Click()
{
   panel1.Visible = false;
   panel2.Visible = true;
   panel3.Visible = false;
}

private void panel3Button_Click()
{
   panel1.Visible = false;
   panel2.Visible = false;
   panel3.Visible = true;
}

Not sure what I'll do if I need to turn off PLC data on the invisible panels...

LarGriff


9
Open Discussion / Re: Complete noob here
« on: April 07, 2017, 12:21:34 PM »
1.  Whats the easiest method to create a "screen change" menu and how do I go about linking those screens?
Using the FormChangeButton and the FormToOpen property

That's fine for Visual Basic... how would you do it in C#?  Those properties don't exist?

LarGriff

10
Tips & Tricks / Re: Using C#
« on: April 06, 2017, 03:17:29 PM »
To make things easier for those that prefer C#, version 3.99s now comes with a pre-configured C# projects.

Thumbs Up for that!

LG

Pages: [1]