Ankündigung

Einklappen
Keine Ankündigung bisher.

Modbus TCP für Beckhoff/Wago/Siemens Kommunikation

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    [Featurewunsch] Modbus TCP für Beckhoff/Wago/Siemens Kommunikation

    Wäre es möglich das MODBUS TCP von (http://mblogic.sourceforge.net/mblib...lient.html)als Plugin zu importieren, dann könnte man Hardware z.B. beckhoff BC/BX oder Wago Busklemmencontroller oder ganze Siemens SPS mit Ethernet-Anbindung als i/o ansprechen.

    Diese unterstützen nämlich das industrielle Modbus TCP Protokoll.

    Ich versuche damit und nem kleinen Script meine Beckhoff anzusprechen, funktioniert teilweise auch, stehe aber vor dem problem, das diese Classen für Python 2 geschrieben sind .. und ichb weder 2 noch 3 kann

    #2
    Hi Manuel,

    ja, möglich ist viel. Es fehlt halt nur die Zeit und Motivation. Ohne HW ist das z.B. ziemlich schwer.

    Bis bald

    Marcus

    Kommentar


      #3
      falls es jemand interssiert, die Verbindung läuft, irgendwie haperts aber mit den Adresszuweisungen/Bereichen beim lesen
      ich sende ne Anfrage mit:
      Ich sollte also von der BC die ersten 10Ausgangsbytes zurückerhalten, ich bekomme auch 10 Datenbytes zurück(getrennt durch \x01), jedoch sind diese irgendwie nicht gleich dem reelen wert?! bzw. steht immer 0 darin
      Code:
      #            Transid    |  Protokollkennzeichen  |Zahl der noch folgenden Bytes|Adresse|Funktion|Daten
      #Protokollaufbau 2 Byte |  2 Byte (immer 0x0000) |    2 Byte (n+2)            |1 Byte |1 Byte  |n Byte
      client.SendRequest(1, 1, 3, 2048, 10)
       bekomme ergebnis (1, 3, 0, 20, b'\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01', 0)

      Kommentar


        #4
        Also selbst wenn dir jemand helfen möchte... mit den sperrlichen Infos kann man es nicht. Ein wenig Quellcode etc. wäre schon praktisch
        Mit freundlichen Grüßen
        Niko Will

        Logiken und Schnittstelle zu anderen Systemen: smarthome.py - Visualisierung: smartVISU
        - Gira TS3 - iPhone & iPad - Mobotix T24 - ekey - Denon 2313 - Russound C5 (RIO over TCP Plugin) -

        Kommentar


          #5
          nicht erschrecken jetzt
          ModBusDatalib.py = Konvertierungsfunktionen
          ModBusDataStrLib.py = Konvertierungsfunktionen
          ModBusTCPLib.py = Verbindungsherstellung
          ModBusTCPMsg.py = Verbindungsherstellung
          ModBUsTCPSimpleClinet2.py = Verbindungsherstellung

          Register-Adressbereich der BC9100
          ##Outputs
          #0-255
          ##Inputs
          2048-2303
          ##Merker!
          #16384-18431


          Registerinhalt (auf Steuerung):
          0: 123
          1: 1
          ..
          2048:120
          2029:1

          der Ablauf:
          (aufruf.py)
          ->Verbindung herstellen
          ->schicke ne nachricht mit Funktionscode und Adressbereich senden
          <-Steuerung sendet Nachricht mit Funktionscode und Adressinhalt zurueck

          Das Funktioniert auch, bekomme jedoch nicht die Regsiterinformationen, sondern immer nur \x00, einmal hat es funktioniert, weiss aber nicht mehr was wie ich das hinbekommen habe :/
          Wenn ichs nich hinbekomme, das der BC was sagt, werd ich wohl mal den Beckhoff Support nerven muessen , da leider die Modbus Funktionen nicht sehr gut beschrieben sind.
          Beckhoff Information System - German

          EDIT:
          gerade nochmal geklappt:
          IP 192.168.178.24 Funktion 3 Adresse 0 ByteAnzahl 1
          Registerinhalt b'\x0b\x01'
          =>Registerinhalt auf Steuerung ist 11
          => jetzt muesste man das Ergebnis Registerinhalt nurnoch zurechtstutzen, das man es benutzen kann
          b'' entfernen... das geht mit struct.unpack?!

          -> Und zum senden wieder mit struct.pack umformene, das die Senderoutine dies versteht..
          Angehängte Dateien

          Kommentar


            #6
            Hallo,

            was soll denn das mit dem Anhang???

            zip -> cpio gz -> zip -> rar, da habe ich dann aufgehört.

            Bis bald

            Marcus

            Kommentar


              #7
              sry, das hätte ich sollen vielleicht dazusagen
              ist ne .rar Datei, welche ich wegen dem Foren System in .zip umbenannt habe

              Kommentar


                #8
                Hallo,

                hast Du die/den Autor der Library um Hilfe gefragt? Mich würde es viel Zeit kosten, durch den ganzen Code zu steigen und Dir helfen zu können.

                Bis bald

                Marcus

                Kommentar


                  #9
                  Natürlich, habe ich das getan, jedoch noch keine Anwort erhalten.
                  mir kommt es so vor, als wuerde irgendwo meine Datenstring falsch umgewandelt, sodass die PLC es nicht mehr versteht, und somit einen Error erzeugt.


                  Das Daten schreiben funktioniert noch nicht,
                  bei diesen Daten und dem Sende-String
                  Code:
                  test = client.MakeRawRequest(1, 1,5,2048,4,senden)
                  
                  sende daten b'\xff\x00\xff\x00'
                  sende string b'\x00\x01\x00\x00\x00\x06\x01\x05\x08\x00\x00\xff'
                  bekomme ich folgende Server antwort:
                  Code:
                  b'\x00\x01\x00\x00\x00\x03\x01\x85\x02'
                  Fehlercode 85 - Fehler 2

                  Kommentar


                    #10
                    Fehler 2 heisst ILLIEGAL DATA ADRESS
                    => hab mir jetzt mal den Raw Code der Sende Funktion geholt(ModBusTCPSimpleClient2.SendRequest bzw. ModBusTCPMsgLib.MBRequest s.u.)
                    das sollte gesendet werden
                    -->b'x00\x01\x00\x01\x03\x06\x00\xff\x00\xff\x00\xff '
                    TransID|UnitID|Protokollkennzeichen (immer 0)| Funktion|Adresse|Laenge|Daten
                    |1Byte|6Bytes
                    --> b'\x00\x01\x00\x00\x00\r\x01\x0f\x00\x00\x00\x03\x06\x00\xff\x00\xff\x00\xff'

                    ?? woher kommt das r?
                    Code:
                    [COLOR=#000080][B]def [/B][/COLOR]MBRequest([COLOR=#94558d]self[/COLOR], Message):
                       [COLOR=#808080][I]"""Extract the data from a Modbus/TCP request message.
                    [/I][/COLOR][COLOR=#808080][I]   Parameters: Message = This is a string containing the raw binary 
                    [/I][/COLOR][COLOR=#808080][I]            message as received.
                    [/I][/COLOR][COLOR=#808080][I]   Return values: 
                    [/I][/COLOR][COLOR=#808080][I]   TransID (integer) = Transaction ID.
                    [/I][/COLOR][COLOR=#808080][I]   UnitID (integer) = Unit ID.
                    [/I][/COLOR][COLOR=#808080][I]   Function (integer) = Function or error code.
                    [/I][/COLOR][COLOR=#808080][I]   Start (integer) = First address in request.
                    [/I][/COLOR][COLOR=#808080][I]   data = Message data. For functions 1, 2, 3, 4 this is an integer 
                    [/I][/COLOR][COLOR=#808080][I]      representing the quantity of requested inputs, coils or 
                    [/I][/COLOR][COLOR=#808080][I]      registers. For 5 or 6, this is a binary string containing
                    [/I][/COLOR][COLOR=#808080][I]      the coil or register data. For 15 or 16 this is a tuple 
                    [/I][/COLOR][COLOR=#808080][I]      containing an integer with the number of coils or registers, 
                    [/I][/COLOR][COLOR=#808080][I]      and a binary string containing the data. In the case of
                    [/I][/COLOR][COLOR=#808080][I]      exception 1 (unsupported function), this will be a binary 
                    [/I][/COLOR][COLOR=#808080][I]      string containing zeros.
                    [/I][/COLOR][COLOR=#808080][I]   exceptioncode (integer) = Modbus exception code. This is 0 if there is no error.
                    [/I][/COLOR][COLOR=#808080][I]   If a message cannot be decoded, zeros will be returned for all fields.
                    [/I][/COLOR][COLOR=#808080][I]   """
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]   # Check if the message is long enough to begin decoding.
                    [/I][/COLOR][COLOR=#808080][I]   # If it is too short, it cannot be a meaningful message.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR]([COLOR=#000080]len[/COLOR](Message) <= [COLOR=#0000ff]10[/COLOR]):
                          TransID = [COLOR=#0000ff]0
                    [/COLOR][COLOR=#0000ff]      [/COLOR]UnitID = [COLOR=#0000ff]0
                    [/COLOR][COLOR=#0000ff]      [/COLOR]Function = [COLOR=#0000ff]0
                    [/COLOR][COLOR=#0000ff]      [/COLOR]Start = [COLOR=#0000ff]0
                    [/COLOR][COLOR=#0000ff]      [/COLOR]data = [COLOR=#008080][B]'/x00/x00'
                    [/B][/COLOR][COLOR=#008080][B]      [/B][/COLOR]exceptioncode = [COLOR=#0000ff]0
                    [/COLOR][COLOR=#0000ff]      [/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, Start, data, exceptioncode
                    
                       [COLOR=#808080]MbPDU [/COLOR]= Message[[COLOR=#0000ff]10[/COLOR]:]   [COLOR=#808080][I]# Get remainder of message.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]   # Unpack the first 10 bytes of the message.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR]TransID, protocol, length, UnitID, Function, Start = struct.unpack([COLOR=#008080][B]'>HHHBBH'[/B][/COLOR], Message[[COLOR=#0000ff]0[/COLOR]:[COLOR=#0000ff]10[/COLOR]])
                    
                       [COLOR=#808080][I]# Get remainder of message.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR]MbPDU = Message[[COLOR=#0000ff]10[/COLOR]:]
                    
                       [COLOR=#808080][I]# Read coils, inputs, or registers..
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR]Function [COLOR=#000080][B]in [/B][/COLOR]([COLOR=#0000ff]1[/COLOR], [COLOR=#0000ff]2[/COLOR], [COLOR=#0000ff]3[/COLOR], [COLOR=#0000ff]4[/COLOR]):
                          
                          [COLOR=#808080][I]# Unpack the rest of the message.
                    [/I][/COLOR][COLOR=#808080][I]      # unpack always returns a tuple, so we need to get size this way.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR](qty,) = struct.unpack([COLOR=#008080][B]'>H'[/B][/COLOR], MbPDU)
                    
                          exceptioncode = [COLOR=#0000ff]0  [/COLOR][COLOR=#808080][I]# Default exception code.
                    [/I][/COLOR][COLOR=#808080][I]      
                    [/I][/COLOR][COLOR=#808080][I]      # Check for exceptions.
                    [/I][/COLOR][COLOR=#808080][I]      # Qty of inputs or outputs is out of range.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR]((qty < [COLOR=#0000ff]1[/COLOR]) [COLOR=#000080][B]or [/B][/COLOR](qty > [COLOR=#94558d]self[/COLOR]._protocollimits[Function])):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      # Check if the requested data exceeds the maximum address.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]((Start + qty - [COLOR=#0000ff]1[/COLOR]) > [COLOR=#94558d]self[/COLOR]._addrlimits[Function]):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]2     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, Start, qty, exceptioncode
                    
                    
                       [COLOR=#808080][I]# Write single coil.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]Function == [COLOR=#0000ff]5[/COLOR]:
                    
                          [COLOR=#808080][I]# Unpack the rest of the message.
                    [/I][/COLOR][COLOR=#808080][I]      # unpack always returns a tuple, so we need to get data this way.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR](data,) = struct.unpack([COLOR=#008080][B]'>2s'[/B][/COLOR], MbPDU)
                          
                          exceptioncode = [COLOR=#0000ff]0  [/COLOR][COLOR=#808080][I]# Default exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      # Check for exceptions.
                    [/I][/COLOR][COLOR=#808080][I]      # Check if the requested data exceeds the maximum address.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR](Start > [COLOR=#94558d]self[/COLOR]._addrlimits[Function]):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]2     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      # For function 5, data value must be one of two possible values.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR](data [COLOR=#000080][B]not in [/B][/COLOR]([COLOR=#008080][B]'[/B][/COLOR][COLOR=#000080][B]\x00\x00[/B][/COLOR][COLOR=#008080][B]'[/B][/COLOR], [COLOR=#008080][B]'[/B][/COLOR][COLOR=#000080][B]\xFF\x00[/B][/COLOR][COLOR=#008080][B]'[/B][/COLOR])):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, Start, data, exceptioncode
                    
                    
                       [COLOR=#808080][I]# Write single register.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]Function == [COLOR=#0000ff]6[/COLOR]:
                    
                          [COLOR=#808080][I]# Unpack the rest of the message.
                    [/I][/COLOR][COLOR=#808080][I]      # unpack always returns a tuple, so we need to get data this way.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR](data,) = struct.unpack([COLOR=#008080][B]'>2s'[/B][/COLOR], MbPDU)
                          
                          exceptioncode = [COLOR=#0000ff]0  [/COLOR][COLOR=#808080][I]# Default exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      # Check for exceptions.
                    [/I][/COLOR][COLOR=#808080][I]      # Check if the requested data exceeds the maximum address.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR](Start > [COLOR=#94558d]self[/COLOR]._addrlimits[Function]):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]2     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      # For function 6, data is unpacked into two bytes, so the value *must* 
                    [/I][/COLOR][COLOR=#808080][I]      # be within the range of 0 to 65535. Therefore, we do not need to check 
                    [/I][/COLOR][COLOR=#808080][I]      # for exception 3.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, Start, data, exceptioncode
                    
                       [COLOR=#808080][I]# Write multiple coils.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]Function == [COLOR=#0000ff]15[/COLOR]:
                    
                          [COLOR=#808080][I]# Unpack the rest of the message.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR]qty, bytecount, data = struct.unpack([COLOR=#008080][B]'>HB %ds' [/B][/COLOR]% ([COLOR=#000080]len[/COLOR](MbPDU) - [COLOR=#0000ff]3[/COLOR]), MbPDU)
                    
                          exceptioncode = [COLOR=#0000ff]0  [/COLOR][COLOR=#808080][I]# Default exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      # Check for exceptions.
                    [/I][/COLOR][COLOR=#808080][I]      # Check if the requested data exceeds the maximum address.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR]((Start + qty - [COLOR=#0000ff]1[/COLOR]) > [COLOR=#94558d]self[/COLOR]._addrlimits[Function]):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]2     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      # Qty of outputs, or registers is out of range.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]((qty < [COLOR=#0000ff]1[/COLOR]) [COLOR=#000080][B]or [/B][/COLOR](qty > [COLOR=#94558d]self[/COLOR]._protocollimits[Function])):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      # Qty for coils exceeds amount of data sent.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR](qty > ([COLOR=#000080]len[/COLOR](data) * [COLOR=#0000ff]8[/COLOR])):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      # Qty for coils less than amount of data sent.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR](qty < (([COLOR=#000080]len[/COLOR](data) - [COLOR=#0000ff]1[/COLOR]) * [COLOR=#0000ff]8[/COLOR]) + [COLOR=#0000ff]1[/COLOR]):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, Start, (qty, data), exceptioncode
                    
                       [COLOR=#808080][I]# Write multiple holding registers.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]Function == [COLOR=#0000ff]16[/COLOR]:
                    
                          [COLOR=#808080][I]# Unpack the rest of the message.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR]qty, bytecount, data = struct.unpack([COLOR=#008080][B]'>HB %ds' [/B][/COLOR]% ([COLOR=#000080]len[/COLOR](MbPDU) - [COLOR=#0000ff]3[/COLOR]), MbPDU)
                    
                          exceptioncode = [COLOR=#0000ff]0  [/COLOR][COLOR=#808080][I]# Default exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      # Check for exceptions.
                    [/I][/COLOR][COLOR=#808080][I]      # Check if the requested data exceeds the maximum address.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]if [/B][/COLOR]((Start + qty - [COLOR=#0000ff]1[/COLOR]) > [COLOR=#94558d]self[/COLOR]._addrlimits[Function]):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]2     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      # Qty of registers is out of protocol range.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]((qty < [COLOR=#0000ff]1[/COLOR]) [COLOR=#000080][B]or [/B][/COLOR](qty > [COLOR=#94558d]self[/COLOR]._protocollimits[Function])):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      # Qty for registers does not equal the size of data sent.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]elif [/B][/COLOR]((qty * [COLOR=#0000ff]2[/COLOR]) != [COLOR=#000080]len[/COLOR](data)):
                             Function = Function + [COLOR=#0000ff]128  [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]         [/I][/COLOR]exceptioncode = [COLOR=#0000ff]3     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, Start, (qty, data), exceptioncode
                    
                    
                       [COLOR=#808080][I]# Function is not supported.
                    [/I][/COLOR][COLOR=#808080][I]   [/I][/COLOR][COLOR=#000080][B]else[/B][/COLOR]:
                          [COLOR=#808080][I]# This error code needs special treatment in case of bad function
                    [/I][/COLOR][COLOR=#808080][I]      # codes that are very large.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR]Function = (Function & [COLOR=#0000ff]0xff[/COLOR]) | [COLOR=#0000ff]0x80    [/COLOR][COLOR=#808080][I]# Create error code.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR]exceptioncode = [COLOR=#0000ff]1     [/COLOR][COLOR=#808080][I]# Exception code.
                    [/I][/COLOR][COLOR=#808080][I]      [/I][/COLOR][COLOR=#000080][B]return [/B][/COLOR]TransID, UnitID, Function, [COLOR=#0000ff]0[/COLOR], [COLOR=#008080][B]'[/B][/COLOR][COLOR=#000080][B]\x00\x00[/B][/COLOR][COLOR=#008080][B]'[/B][/COLOR], exceptioncode

                    Kommentar


                      #11
                      --> b'\x00\x01\x00\x00\x00\r\x01\x0f\x00\x00\x00\x03\x06 || \x00\xff\x00\xff\x00\xff'

                      ok r = 13
                      lt. Beckhoff
                      ->
                      ModbusTCP-Protokoll
                      Byte Name Beschreibung
                      0 Transaction identifier wird vom Slave zurückgesendet
                      1 Transaction identifier wird vom Slave zurückgesendet
                      2 Protocol identifier immer 0
                      3 Protocol identifier immer 0
                      4 Length field 0 (wenn die Nachricht kleiner 256 Byte ist)
                      5 Length field Anzahl der folgenden Bytes
                      6 UNIT identtifier wird vom Slave zurückgegeben
                      7 Modbus es folgt das Modbus-Protokoll beginnend mit der Funktion

                      8 Anzahl der folgenden Bytes
                      \x00\xff\x00\xff\x00\xff' Daten

                      Kommentar


                        #12
                        so auch nach Rücksprache mit dem Beckhoff Support bin ich noch nicht weiter. Das lesen- schreiben von einzelnen Bytes funktioniert , möchte aber mehrere auf einmal schreiben; da hapert es noch.

                        return struct.pack('>HHHBBHHB%ds' %TransID, 0, count + 7, 1, FunctionCode, Addr, Qty, count + 1, MsgData) # Function code is not supported.
                        struct.error: pack expected 9 items for packing (got 8)
                        hier die Zeile mal mit eingesetzen Werten
                        Code:
                        struct.pack([COLOR=#008080][B]'>HHHBBHHB%ds' [/B][/COLOR]%count, 1, [COLOR=#0000ff]0[/COLOR], count + [COLOR=#0000ff]7[/COLOR], [COLOR=#0000ff]1[/COLOR], 16, 16384, 4, count + [COLOR=#0000ff]1[/COLOR], [COLOR=#0000ff]'127[/COLOR],[COLOR=#0000ff]255[/COLOR],[COLOR=#0000ff]67[/COLOR],[COLOR=#0000ff]255[/COLOR],[COLOR=#0000ff]67[/COLOR],[COLOR=#0000ff]255'[/COLOR])
                        Ich komme nicht dahinter was da falsch sein soll:
                        lt. Beschreibungen des Modbusprotokoll Function16 ,
                        wird 3mal ein int, 2mal ein byte, dann wieder zwei int, dann wieder ein byte gesendet, dann die nachricht als int packete

                        Ich habe noch nicht verstanden warum da ein erstes %count steht, denn normalweise wäre das lt. protokollbeschreibung nicht nötig?!

                        PS: count beschreibt die länge der Nachricht bzw der bytes die gesendet werden
                        hier ein bsp: http://infosys.beckhoff.de/index.php...ls.htm&id=3172

                        Kommentar


                          #13
                          Would be awesome to get the modbus implementation, would like to communicate with Siemens I have the hardware, and pretty good at the Plc coding, so if someone need help with that in the project - maybe someone who's good at Python

                          Kommentar


                            #14
                            @Rasmus7700 at the moment i can use the Modbus Function 3 and 6 in my Script, but i must rewrite it for smarthome.py as Logic/plugin.
                            With Function 6 /3 it is only possible to send/write 1byte to the device.
                            So we must gernate an loop that all items with modbus functionallity are read/send.

                            Kommentar


                              #15
                              das Plugin ist soweit fertig, allerdings bekomme ich
                              2015-08-15 16:56:45,270 ERROR Modbus MODBUS: Could not read an InputWord, because [Errno 104] Connection reset by peer -- __init__.py:read:355
                              2015-08-15 16:56:45,277 ERROR Modbus Reading data from 192.168.178.24 failed: release unlocked lock - reconnecting! -- __init__.py:refresh:167
                              2015-08-15 16:56:45,283 INFO Modbus MODBUS: Disconnected! -- __init__.py:disconnect:137
                              2015-08-15 16:56:45,737 DEBUG Scheduler Modbus next time: 2015-08-15 16:57:45+02:00 -- scheduler.py:_next_time:289
                              2015-08-15 16:56:46,300 INFO Modbus MODBUS: Connected to 192.168.178.24 -- __init__.py:connect:124
                              diesen release unlock lock fehler, und weiss nicht warum ?!
                              ich habe mich eigentlich an den Aufbau, anderer Plugins gehalten, was bedeutet der Fehler ?

                              Kommentar

                              Lädt...
                              X