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 - Andrew.Lenzo

Pages: [1]
1
Support Questions / Re: ModbusTCPCOM Timeout Issue
« on: June 19, 2019, 11:29:10 AM »
Thanks this is very informative! I have resolved the freezing issues by running on background threads. It took a lot of googling but it turns out I just needed to use the threadpool and a lambda statements in the "signal" write methods as shown below. I still see a delay a reaction from the hardware as the background threads do their thing but the Main Form doesn't freeze which is fine for this project.
Code: [Select]
    Public Sub WriteCLR(ByVal WriteValue As Integer)
        System.Threading.ThreadPool.QueueUserWorkItem(Sub() _Connection.Write(_CLRaddress, WriteValue)) 'writes to signals color address
    End Sub

    Public Sub WritePWR(ByVal WriteValue As Integer)
        System.Threading.ThreadPool.QueueUserWorkItem(Sub() _Connection.Write(PWRaddress, WriteValue)) 'writes to signals power address
    End Sub

My next task is to add a network connection diagram to the HMI which will involve changing the color of some lines based on the connection status of the PLCs. It sounds like the ConnectionEstablished, ConnectionClosed, and ComError events may be exactly what I need to do that.

Thanks Archie!

2
Support Questions / Re: ModbusTCPCOM Timeout Issue
« on: June 19, 2019, 07:49:20 AM »
Thank you for your reply Archie. I've never done asynchronous programming before so this may be a good opportunity to learn! Seems simple enough but I'm still trying to get my head around whats happening when I am creating tasks and how to pass info to them. Also, can I create the tasks/threads in my object method or do I need to do that when the main form calls it?

I noticed that there is a function that returns a Boolean called IsSubscriptionActive(). Would it be possible to test the ModbusTCP connection before calling the write function using this? something like

Code: [Select]
if ModbusTCPCOM1.IsSubscriptionActive()
     ModbusTCPCOM1.Write(...)
else
     MSGBox("Com1 is not active")
end if



3
Support Questions / ModbusTCPCOM Timeout Issue
« on: June 18, 2019, 04:30:58 PM »
Hello,

I have a class called "Signal" setup as follows.
Code: [Select]
Public Class Signal 'class with properties of signal. Links ModbusTCP/IP driver to memory bit adresses for power and color

    Dim _Connection As AdvancedHMIDrivers.ModbusTCPCom
    Dim _PWRaddress As String 'memory bit address of power control relay
    Dim _CLRaddress As String  'memory bit address of color control relay

    Public Property Connection() As AdvancedHMIDrivers.ModbusTCPCom
        Get
            Return _Connection
        End Get
        Set(value As AdvancedHMIDrivers.ModbusTCPCom)
            _Connection = value
        End Set
    End Property

    Public Property PWRaddress As String
        Get
            Return _PWRaddress

        End Get
        Set(value As String)
            _PWRaddress = value

        End Set
    End Property
    Public Property CLRaddress As String
        Get
            Return _CLRaddress
        End Get
        Set(value As String)
            _CLRaddress = value
        End Set
    End Property

    Public Sub WriteCLR(ByVal WriteValue As Integer)
        _Connection.Write(_CLRaddress, WriteValue) 'writes to signals color address
    End Sub

    Public Sub WritePWR(ByVal WriteValue As Integer)
        _Connection.Write(PWRaddress, WriteValue) 'writes to signals power address
    End Sub
End Class

I have initialized 40 "signals" on load in the main form as "signal1", "signal2", etc. I then added these signals to various object arrays which groups them together and allows me to write to that group using a single button click by looping through all of the signals in that groups array. This works fine except when connection is lost to one of the ModbusTCP drivers. If I disconnect one of the PLCs, the program seems to freeze as it trys to connect to the PLC for every signal in the array.

I am wondering if there is a way to access the status of the Modbus connection and move on the the next object in the array if it is not active or not able to ping that PLC. Any help would be greatly appreciated.

Thanks,

Andrew


4
Thank you! This worked like a charm. Also, I was able to toggle using a single Button by setting a state variable equal to ModbusTCPComX.Read("00001"). They i used conditional statements to evaluate which value to write. (I know the additional state variables are unnecessary. This is a WIP!)


Code: [Select]
     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim state1 As Boolean
        Dim state2 As Boolean
        Dim state3 As Boolean
        Dim state4 As Boolean
        Dim state5 As Boolean
        state1 = ModbusTCPCom1.Read("00001")
        state2 = ModbusTCPCom1.Read("00003")
        state3 = ModbusTCPCom1.Read("00005")
        state4 = ModbusTCPCom1.Read("00007")
        state5 = ModbusTCPCom1.Read("00009")

        If state1 = 0 Then
            ModbusTCPCom1.Write("00001", 1)
            ModbusTCPCom1.Write("00003", 1)
            ModbusTCPCom1.Write("00005", 1)
            ModbusTCPCom1.Write("00007", 1)
            ModbusTCPCom1.Write("00009", 1)
        Else
            ModbusTCPCom1.Write("00001", 0)
            ModbusTCPCom1.Write("00003", 0)
            ModbusTCPCom1.Write("00005", 0)
            ModbusTCPCom1.Write("00007", 0)
            ModbusTCPCom1.Write("00009", 0)
        End If

    End Sub

5
Thanks for the reply! A few follow up questions:

1. I need to put this code in the private sub "Basicbutton1_Click" correct?
2. Do i need to have any additional code to allow the values to toggle between 0 and 1 or is it sufficient to select toggle as the output type in the button properties?

Thanks again in advance!

6
I have an application where I am controlling identical "banks" of LED signals over a long distance. Each "bank" has 5 LED signals controlled by a dedicated PLC. All PLCs have identical programming but a unique IP address. Currently, I have modbus TCP connections to each PLC (total of 9 PLCs) and individual basic buttons for each signal.

I am wondering if there is a way to send the same command to multiple modbus TCP connections with a single button. For example, if I would like to turn on signal 1 (memory bit 00001) on every PLC, I need to have 9 basic buttons, 1 for each modbus connection. Is there a way to toggle 00001 on multiple PLCs with one button. For example, toggle 00001 on modbus connection 1, 2, 3, 4, etc.?

Sorry for the long winded question. This is not my area of expertise. If more info or examples would be helpful, please let me know.

Pages: [1]