.NET VB form hangs during execution process

Azra Begum 1 Reputation point
2020-11-04T14:27:24.277+00:00

Hi,
I have a .NET VB application running on a windows server. My VB is connected to a PLC, and my VB service suppose to read data from PLC. During the execution of the VB code, my application hangs if the PLC is disconnected and remain in hung state even though the PLC is connected back.
I have used a catch statement, but seems like its not catching any threads.

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
947 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
329 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Azra Begum 1 Reputation point
    2020-11-05T15:40:02.007+00:00

    I think the Problem is that MicroLogix is not connected directly to the SQL server but its connected through a network interface module.
    My service stops responding once it goes to the Step PLC_Read() and its not even going to next step as my PLC is powered off, but when the PLC is back UP and running again, still the service is not responding.

    Please see My code

     Imports System.Data.SqlClient
       Imports ABLink
       Public Class Form1
       Public PLC_Compactor As New Controller
    
        Public MyTag As New Tag
        '**********************************
        '* initialize Threading Timer
        Private oTimer As Threading.Timer
    
        '**********************************
        '* Define Registers
        Dim length, breakpoint As Integer
        Dim DayValueHold As Integer = 1
        Dim DateStored, TimeStored, DateTimeCurrent, DateOfDumpFormatted, TimeOfDumpFormatted As String
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' Add code here to start your service. This method should set things
            ' in motion so your service can do its work.
            '**********************************
            '* CONNECT TO PLC
            PLC_Compactor.CPUType = Controller.CPU.SLC
            PLC_Compactor.DriverType = Controller.Driver.NETENI
    
            PLC_Compactor.IPAddress = "192.168.4.190"
            ' PLC_Compactor.Path = "0.0.0.0"
            PLC_Compactor.Timeout = 3000
            PLC_Compactor.Connect()
        End Sub
    
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Try
                If (PLC_Compactor.Connect() = ResultCode.E_SUCCESS) Then
                    PLC_Read()
                    If PLC_Trigger <> 0 Then
                    WriteToPLC_UpdateTime()
                        ConvertToDateFormat(DateOfDump, DateOfDumpFormatted)
                        ConvertToTimeFormat(TimeOfDump, TimeOfDumpFormatted)
                        WriteToSQL()
                        WriteToPLC_ZeroTrigger()
                    End If
                End If
            Catch ex As Exception
                ErrorMessageAdd("PLC Connect Fail, " & ex.Message)
            End Try
        End Sub
    

    Thank you

    0 comments No comments

  2. Xingyu Zhao-MSFT 5,356 Reputation points
    2020-11-06T05:55:38.653+00:00

    I noticed that you made a connection in the Form.load event,

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
            ...  
            PLC_Compactor.Connect()  
        End Sub  
    

    But this event is loaded only once before the form is first displayed. If you need to establish a connection again, you can consider putting it into Timer.Tick methods.

    For example.

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick  
            If Not ( "something like PLC_Compactor isConnected?") Then  
                PLC_Compactor.Connect()  
            End If  
            Try  
                ...      
        End Sub  
    

    Hope it could be helpful.
    Note: Due to the lack of understanding of ‘ABLink’, the above code has not been tested.

    Best Regards,
    Xingyu Zhao

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments