Menu

Libnodave connection error after 40minutes

Help
2011-05-23
2013-05-09
  • Carllos Alberto Rogenski

    Hi, i developed my application in Visual Basic 6, and use a timer(1second) to receive a value from a PLC.
    That works fine.
    But after aproximadately 40minutes, he only receive a value 0, if i close and reopen my software, he back to receive a value normaly, but after aproximadately 40 minutes, receive only value 0 again.
    I'm using a conection with a CLP Siemens S7 315, and a ethernet TCP/IP connection.
    Any idea to resolve my problem?
    Thanks!

     
  • Carllos Alberto Rogenski

    My code actually:
    Configuration of the module LIBNODAVE:

    Private Function initialize(ByRef ph As Long, ByRef di As Long, ByRef dc As Long)
    ph = 0
    di = 0
    dc = 0
    Rem uncomment the daveSetDebug... line, save your sheet
    Rem run excel from dos box with: excel yoursheet >debugout.txt
    Rem send me the file debugout.txt if you have trouble.
    Rem Call daveSetDebug(daveDebugAll)
    initialize = -1
    res = -1
    peer$ = Form1.IP_PLC
    ph = openSocket(102, peer$)    ' for ISO over TCP
    If (ph > 0) Then
            di = daveNewInterface(ph, ph, "IF1", 0, daveProtoISOTCP, daveSpeed187k)
            res = daveInitAdapter(di)
            If res = 0 Then
                MpiPpi = 2
                Rack = 0
                Slot = 2
                dc = daveNewConnection(di, MpiPpi, Rack, Slot)
                res = daveConnectPLC(dc)
            If res = 0 Then
                initialize = 0
            End If
        End If
    End If
    End Function
    

    Then i added a new function, to easily my configuration in form:

    Function SIEMENS_READ(ByVal AREA As String, DB As Integer, ENDERECO As Integer, QTDE As Integer, TIPO As String)
        If QTDE > 222 Then
           MsgBox ("Quantidade de bytes excedida !!")
           SIEMENS_READ = -1
           Exit Function
        Else
    
        Dim ph As Long, di As Long, dc As Long
        Dim buffer() As Variant
        ReDim buffer(QTDE)
                    
        res = initialize(ph, di, dc)
                         
        If res = 0 Then
            pdu = daveNewPDU
            Call davePrepareReadRequest(dc, pdu)
            
         
            ' VERIFICA PARAMETRO AREA
            If AREA = "DB" Then Call daveAddVarToReadRequest(pdu, daveDB, DB, ENDERECO, QTDE)
            If AREA = "M" Then Call daveAddVarToReadRequest(pdu, daveFlags, "0", ENDERECO, QTDE)
            If AREA = "I" Then Call daveAddVarToReadRequest(pdu, daveInputs, "0", ENDERECO, QTDE)
            If AREA = "Q" Then Call daveAddVarToReadRequest(pdu, daveOutputs, "0", ENDERECO, QTDE)
            If AREA = "C" Then Call daveAddVarToReadRequest(pdu, daveCounter, "0", ENDERECO, QTDE)
            If AREA = "T" Then Call daveAddVarToReadRequest(pdu, daveTimer, "0", ENDERECO, QTDE)
            If AREA = "DI" Then Call daveAddVarToReadRequest(pdu, daveDI, DB, ENDERECO, QTDE)
                                       
            resultSet = daveNewResultSet
            res2 = daveExecReadRequest(dc, pdu, resultSet)
            
            ' VERIFICA PARAMETRO TIPO
            If TIPO = "BYTE" Then
                For i = 0 To QTDE - 1
                    res3 = daveUseResult(dc, resultSet, i)
                    buffer(i) = daveGetS8(dc)
                Next
            End If
                            
            If TIPO = "WORD" Then
                For i = 0 To (QTDE / 2) - 1
                    res3 = daveUseResult(dc, resultSet, i)
                    buffer(i) = daveGetU16(dc)
                Next
            End If
            
            If TIPO = "INT" Then
                For i = 0 To (QTDE / 2) - 1
                    res3 = daveUseResult(dc, resultSet, i)
                    buffer(i) = daveGetS16(dc)
                Next
            End If
            
            If TIPO = "DWORD" Then
                For i = 0 To (QTDE / 4) - 1
                    res3 = daveUseResult(dc, resultSet, i)
                    buffer(i) = daveGetS32(dc)
                Next
            End If
            
            If TIPO = "REAL" Then
                For i = 0 To (QTDE / 4) - 1
                    res3 = daveUseResult(dc, resultSet, i)
                    buffer(i) = daveGetFloat(dc)
                Next
            End If
                  
            daveFree (resultSet)
            daveFree (pdu)
        End If
           
        SIEMENS_READ = buffer()
        
        Call cleanUp(ph, di, dc)
     End If
    End Function
    

    And a code used in timer from a form to receive the value from PLC:

    Private Sub Timer1_Timer()                                                                               'Timer 1s
        Entradas = SIEMENS_READ("M", "0", "100", "2", "BYTE")                                                  'Faz a leitura da entrada, e envia a um array
        For i = 0 To 1
            For ii = 0 To 7
                Entrada = Entrada & SIEMENS_GETBIT(Entradas(i), ii)                                          'Desmonta o array, convertendo a uma variavel
            Next ii
        Next i
    End Sub
    

    I see more detailed informations at today, and this is here:
    _A time for stop receive informations of PLC is: exactly 1hour, 21minutes and 44 seconds.
    _A number of times the timer run, is exactly 3174 times.

    Before this, the program receive a Speed of the machine, which is at a MW100.
    After this, the program only receive a 0 speed. And this is resolved when i close my program, and start again(ONLY THE PROGRAM USING THE LIBNODAVE).

    Any friend can help me?
    I really need help, for apply his library to my work.

     
  • Simon

    Simon - 2011-05-24

    You could try running a 2 seconds to see if it runs longer.
    Do you keep the connection open?  - I believe there is a Keep Alive feature?
    Presumably no other application is accessing the PLC - e.g. an HMI?
    No other traffic on the Ethernet (Try running it isolated, PC and Ethernet only)

    I wrote something in C on a Linux box but it polls PLC once every minute.
    Hope this helps,
    Simon

     
  • Carllos Alberto Rogenski

    Sorry man,

    I resolved it, after a very time, i see my error in program.
    The problem is i open a connection(socket), and without read a instruction of Clean UP, i added with a close connection(port)
    The problem is resolved when i change in Clean UP, sloseport to closesocket.
    Now, the program is working fine!

    NOTE: The PLC is under a network, working with PROFIBUS(traffic with other 6 PLCs) and a ethernet network too, comunicating with software iFix.

    The libnodave in ethernet runs fine with other communication of PLC running at the same time ;)

     

Anonymous
Anonymous

Add attachments
Cancel