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 - rbelknap

Pages: [1] 2 3 ... 5
1
Support Questions / Re: Changing a sub property
« on: January 14, 2019, 12:59:20 PM »
Archie,

This worked out well.  I had to add some code to get by the headers, to eliminate the quotes in the files, and also not to process any lines without Modbus addresses.

Code: [Select]
                        If Not TagAliasFileRead Then
                            If (System.IO.File.Exists(".\PLC Tags_basic.csv")) Then
                                TagAlias = New Dictionary(Of String, String)
                                Using sr As New System.IO.StreamReader(".\PLC Tags_basic.csv")
                                    Dim Line As String
                                    Dim Items() As String
                                    While Not sr.EndOfStream
                                        Line = sr.ReadLine()
                                        Items = Line.Split(","c)
                                        If Items(0).Substring(1, 1) <> "#" AndAlso Items(4) <> "" Then
                                            If Items.Count > 1 Then
                                                '* Item(0)=Alias, Item(1)=PLC Address
                                                Dim MbAddress As String = Items(4)
                                                Dim MOD_Prefix As String = ""
                                                Dim myType As String = Items(0)
                                                myType = myType.Substring(0, myType.IndexOf("-"))

                                                Select Case myType
                                                    Case "F32"
                                                        MOD_Prefix = "F"
                                                    Case "S32"
                                                        MOD_Prefix = "L"
                                                    Case Else
                                                        MOD_Prefix = ""
                                                End Select

                                                'put all of the tagnames in the Dictionary object in Upper case to prevent mismatch due to case
                                                'add leading 0s to contacts adressed 1,2... etc
                                                'Dim ModAddress As String = (myRow("MODBUS Start Address"))
                                                Dim x As Byte = 0
                                                If MbAddress.Length < 5 Then
                                                    For x = 1 To 4
                                                        If MbAddress.Length < 5 Then
                                                            MbAddress = "0" & MbAddress
                                                        End If
                                                    Next

                                                End If
                                                MbAddress = MOD_Prefix & MbAddress
                                                TagAlias.Add(Items(1).Substring(1, Items(1).Length - 2), MbAddress) ' Items(4))
                                            End If
                                        End If
                                    End While
                                End Using
                            End If
                            TagAliasFileRead = True
                        End If

Thanks for all of the help.

2
Support Questions / Re: Changing a sub property
« on: January 11, 2019, 11:52:38 AM »
See the attached for the file.

See below for the routine we use to query it.

Code: [Select]
Public Sub LoadFromSpreadsheet()
        Try
            'Create the Tags required by this object
            Dim dbPLCTags As clsDataBase = New clsDataBase()
            dbPLCTags.OpenDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""D:\Visual Studio Projects\CTO Tester\Data\"";Extended Properties=""text;HDR=Yes;FMT=Delimited""")
            'dbPLCTags.OpenDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Users\paxel\Documents\CTO PLc\"";Extended Properties=""text;HDR=Yes;FMT=Delimited""")

            Dim sql As String = "SELECT * FROM [PLC Tags_basic.csv]"
            sql += " Where [MODBUS Start Address] is not null"
            Dim dsTags As DataSet = dbPLCTags.ByQuery(sql, "Tags")
            Dim myRow As DataRow
            ModbusAddressLookup = New Dictionary(Of String, String)
            'Iterate through the list of tags and add an item for each

            For Each myRow In dsTags.Tables(0).Rows
                Try
                    Dim MOD_Prefix As String = ""
                    Dim myType As String = myRow("## System ID")
                    myType = myType.Substring(0, myType.IndexOf("-"))

                    Select Case myType
                        Case "F32"
                            MOD_Prefix = "F"
                        Case "S32"
                            MOD_Prefix = "L"
                        Case Else
                            MOD_Prefix = ""
                    End Select

                    'put all of the tagnames in the Dictionary object in Upper case to prevent mismatch due to case
                    'add leading 0s to contacts adressed 1,2... etc
                    Dim ModAddress As String = (myRow("MODBUS Start Address"))
                    Dim x As Byte = 0
                    If ModAddress.Length < 5 Then
                        For x = 1 To 4
                            If ModAddress.Length < 5 Then
                                ModAddress = "0" & ModAddress
                            End If
                        Next

                    End If
                    ModbusAddressLookup.Add(myRow("Tag Name").ToString.ToUpper, MOD_Prefix & ModAddress)
                    TagNameLookup.Add(MOD_Prefix & ModAddress, myRow("Tag Name").ToString.ToUpper)

                    'myPLCconn.Subscribe(MOD_Prefix & ModAddress, 1, 500, AddressOf TagProcessor)

                Catch ex As Exception
                    Logger.WriteToLog(ex.Message, True, True, ex.StackTrace, Me.ToString & " LoadFromSpreadsheet Row Processing")
                End Try
            Next
            dbPLCTags.CloseDatabase()
        Catch ex As Exception
            Logger.WriteToLog(ex.Message, True, True, ex.StackTrace, Me.ToString & " LoadFromSpreadsheet Row Processing")
        End Try
    End Sub

3
Support Questions / Re: Changing a sub property
« on: January 11, 2019, 09:19:43 AM »
Archie,

This works perfectly, even with my original code commented out.

I'm glad you said this was a first go around, because I want to give you a bit more background.

We're using a PAC3000, from AutomationDirect and the Productivity Suite creates a CSV file of the tags every time you save the project, including the Modbus addresses.  In my code I'm querying this csv file to create my lookup dictionary object.

If we do have to use this separate txt file then we'll come up with a way to create is using a macro or something.

Let me know your thoughts and we appreciate all of the help you've given us and others.

4
Support Questions / Re: Changing a sub property
« on: January 09, 2019, 09:55:24 AM »
Archie,

I appreciate you looking at this for me.  My lookup is from a dictionary object, so creating the reverselookup will be simple enough.

The subscriptionHandler code looks interesting, but also a bit more involved than I'd be willing to go after on my own.  If you can provide guidance then I'm sure we can make it work.

Thanks,

Rich

5
Support Questions / Re: Changing a sub property
« on: January 09, 2019, 08:16:54 AM »
Archie,

Here is the final code and it works well to replace all of the Tag names with the Modbus addresses.

Code: [Select]
Public Sub FixPLCAddresses(ByVal ctrlParent As Control)
        'Call this from a form to translate the PLC Tags to the Modbus addresses.
        ' ie Call FixPLCAddresses(me), in the Form_Load procedure.
        Dim I As Integer, propertyIndex As Integer, SubIndex As Integer

        For I = 0 To ctrlParent.Controls.Count - 1
            Dim p() As Reflection.PropertyInfo = ctrlParent.Controls(I).GetType().GetProperties
            For propertyIndex = 0 To p.Length - 1
                If (p(propertyIndex) IsNot Nothing) AndAlso (((p(propertyIndex).PropertyType) Is GetType(String) Or (p(propertyIndex).PropertyType) Is GetType(MfgControl.AdvancedHMI.Drivers.PLCAddressItem))) Then
                    '* Does this property start with "PLCAddress"?
                    If p(propertyIndex).Name.IndexOf("PLCAddress", StringComparison.CurrentCultureIgnoreCase) = 0 AndAlso (p(propertyIndex).PropertyType) Is GetType(String) Then
                        'Dim value As String = LookupModbusAddr(Me.Controls(i).Name & "." & p(propertyIndex).Name)
                        Dim value As String = LookupModbusAddr(p(propertyIndex).GetValue(ctrlParent.Controls(I), Nothing))
                        If value <> "" Then p(propertyIndex).SetValue(ctrlParent.Controls(I), value, Nothing)

                    ElseIf (p(propertyIndex).PropertyType Is GetType(MfgControl.AdvancedHMI.Drivers.PLCAddressItem)) Then
                        '* Does the PCAddress property point to an object instance?
                        If p(propertyIndex).GetValue(ctrlParent.Controls(I), Nothing) IsNot Nothing Then
                            Dim PLCAddressObject = p(propertyIndex).GetValue(ctrlParent.Controls(I), Nothing)
                            Dim SubProperty() As Reflection.PropertyInfo = PLCAddressObject.GetType().GetProperties
                            '* Check all of the properties of the PLCAddressItem
                            For SubIndex = 0 To SubProperty.Length - 1
                                If ((SubProperty(SubIndex).PropertyType Is GetType(String) AndAlso SubProperty(SubIndex).Name.IndexOf("PLCAddress") >= 0)) Then
                                    '* Set the value of the sub proprty
                                    Dim subvalue As String = LookupModbusAddr(SubProperty(SubIndex).GetValue(PLCAddressObject, Nothing))
                                    SubProperty(SubIndex).SetValue(PLCAddressObject, subvalue, Nothing)
                                End If
                            Next
                        End If
                    End If
                End If
            Next
            'Fix anything in a container control, such as a panel or groupbox
            If ctrlParent.Controls(I).HasChildren Then
                FixPLCAddresses(ctrlParent.Controls(I))
            End If
        Next

    End Sub

All of the PLCAddress properties get updated, however when I run my program the AnalogValueDisplay still gives an error for the original tag name. 

My form has DisableSubscriptions=true on the ComComponent.  In form Load I run the FixPLCAddress routine and then turn DisableSubscritions=false in code.

The only way it seems to work is if I set the ComComponent for the AnalogValueDisplay =None on the form, run the FixPLCAddress routine and then set the ComComponent and set DisableSubscritions=false in form load.

For a basic label it works straight away, but appears that the PLCAddressItem Type is treated differently on creation of the form.

Let me know if you have any thoughts on how I may be able to get around this.

Thanks,

Rich

6
Support Questions / Re: Changing a sub property
« on: December 19, 2018, 11:58:55 AM »
Archie,

I working with Paxel on trying to get this to work, but we're having trouble setting the sub property.  We are able to get the Property value, but the set is not working.  Also, it seems the sub properties are only available if there is a value, so I know I'll have to add some checks for that.

Was wondering if you had any helpful tips on how we can do this?

Our goal for this is to be able to use tag names in the software to make it more readable and then have them converted to Modbus addresses on the fly.  If it comes down to it we can always get the same look with a basic label and the issue would go away for now.

Thanks for any help you can provide.

Rich

7
ok, That makes sense.

My other question on this, is there a reason you wouldn't use a Select Case statement?
Something like this:
Code: [Select]

     Select Case e.PlcAddress
            Case "N20:33"
                value1 = e.Values(0)
            Case "N20:34"
                value2 = e.Values(0)
            Case "N20:35"
                value3 = e > Values(0)
            Case Else
                MsgBox " No handler for " & e.plcaddress
     End Select

8
Archie,

Is either way, subscribing individually, or using NumberOfElements, better than the other?
ie, is there a performance hit one way vs the other?

And what would the difference in the datachanged event code look like if you use NumberOfElements?

Rich

9
From the screen shot it looks like Carlos is on the properties page for the solution, not the project.

Right-Click on the Project, not the solution, and you should het a screen that look something like the attached.
Un-check the 'Make Single Instance Application.

You'll need to do this for both applications.

Also, my screen shot os from VS2015, not sure if it'll be different in 2017.

10
Support Questions / Re: Do-More and Modbus TCP Strings
« on: June 06, 2017, 09:58:03 AM »
Archie,

That works great!.

Thanks,

Rich

11
Support Questions / Do-More and Modbus TCP Strings
« on: June 05, 2017, 02:20:12 PM »
I'm looking to use a (2) Do-More processors in a build and need to be able to send ASCII strings to them from AdvancedHMI, mainly model/serial numbers.

My original plan was to use Modbus TCP, but in looking at the manuals I don't see a way to send ASCII strings.

Am I seeing this wrong?  or will it just work.

I have the hardware already, but haven't had a chance to hook anything up yet.

Is my only other option to go through the serial port?

12
Support Questions / Re: Form Dialog TopMost
« on: April 11, 2017, 08:03:30 AM »
James,

Archie may have a simpler way to do what you want, but for me I would raise and event when the new form opened, and catch it in the popup form(s).
Code: [Select]
'In the forms you want to "Look" at, declare an event
Public event frmOneShowing

'In form Load raise the event
RaiseEvent frmOneShowing

'In the Popup form
'Declare an object reference withevents to the form
private withevents myfrmOne as frmOne

'Create the routine to handle the event
Private Sub frmOne_frmOneShowing handles frmOne.frmOneShowing

'your code here to center it.

end sub



Rich

13
Support Questions / Re: Debug message
« on: March 17, 2017, 12:36:06 PM »
Archie,

I think he means within Visual Studio so he knows the error is occurring during debug.

ASF,

Which version of Visual Studio are you using?

For 2015 see this link: https://blogs.msdn.microsoft.com/visualstudioalm/2015/02/23/the-new-exception-settings-window-in-visual-studio-2015/

Rich

14
Support Questions / Re: Charge Controller Communication
« on: February 07, 2017, 12:54:50 PM »
Archie,

Thanks for the reply.

This is at my seasonal Camp, so I only get to try it on the occasions I'm there.
I will try it this weekend and see how it goes.

Thanks Again.

15
Support Questions / Charge Controller Communication
« on: February 03, 2017, 12:38:45 PM »
I'm trying to communicate with a Midnite Classic 150 Charge Controller.
I have it setup to charge batteries from a solar array.

I'm using the Modbus TCPIP driver, but think I'm messed up in how to address the registers.

For example the Modbus spec for it shows Register 4101 is the PCB version. 
It's a 16 bit register and I can't seem to make it work.

It's been a bit since I tried it, but I just had a basic label on my form with addresses like:
4101
40101
44101
etc. 

I think if I can get my head wrapped around how to form the address I can make it work.
Any help is much appreciated.

Pages: [1] 2 3 ... 5