Fernsteuerung von DiagRA D und Silver Scan-Tool über die optionale Webservices-API

Immer mehr Nutzer von DiagRA D und Silver Scan-Tool nutzen die Fernsteuermöglichkeit über die Webservices API. Über die Schnittstelle können externe Anwendungen auf demselben Rechner oder im lokalen Netzwerk nahezu die komplette Funktionalität der beiden Anwendungen nutzen. So lassen sich beispielsweise über ein Python-Skript Flash-Abläufe mit anschließenden Diagnosetests automatisieren oder ganz gezielt spezielle Diagnosetests an HiLs oder Prüfständen in die Experimente integrieren. Natürlich können auch immer wiederkehrende OBD-Tests sehr einfach automatisiert werden.
Technischer Hintergrund: Das Interface der Web Services wird dabei durch ein maschinell verarbeitbares Format gegeben, typischerweise durch WSDL (Web Services Description Language). Dabei wird das Netzwerkprotokoll SOAP (Simple Object Access Protocol) zur Kommunikation verwendet. Hierbei wird XML als Nachrichtenformat und das HTTP-Protokoll zur Kommunikation innerhalb des Netzwerks verwendet. Im Fall von DiagRA D/Silver Scan-Tool findet die Kommunikation zwischen einem Client-Programm und DiagRA D/Silver Scan-Tool statt, wobei DiagRA D/Silver Scan-Tool als Server-Anwendung dient. Die Webservices sind als API für SOAP implementiert, sodass der Nutzer sich weder um die Erstellung der XML-Nachrichten noch die HTTP-Kommunikation kümmern muss.
Das untenstehende Beispiel zeigt, wie mittels Python-Skript über DiagRA D erst die Kommunikation eingeleitet, dann von allen OBD-Steuergeräten alle Werte vom Mode $01, dann gezielt die Steuergeräteversorgungsspannung PID $42 und im Anschluss noch der MIL Status aus dem Mode $03 ausgelesen wird. Zum Abschluss wird die Kommunikation mit dem OBD-System wieder beendet. Als SOAP Client kommt im Beispiel ZEEP zum Einsatz. Eine Dokumentation der Kommandos findet sich direkt in bestehenden Installationen von DiagRA D oder Silver Scan-Tool im Ordner Samples.
Das Webservices-Plugin ist eine optionale Erweiterung einer DiagRA D oder Silver Scan-Tool Lizenz und kann entweder mit einer Lizenz mitbestellt oder nachträglich hinzugefügt werden.
Bei Interesse kontaktieren Sie uns bitte über info@rac.de.

Beispiel Python-Skript:

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
import time
# PLEASE NOTE:
#   This script uses the third party package Zeep ("A fast and modern Python SOAP client").
#   Find Zeep in the Python package index: https://pypi.org/project/zeep/
#   Find its documentation here: https://docs.python-zeep.org/en/master/
#   Should you be interested in logging, this might help you: https://docs.python-zeep.org/en/master/plugins.html
#   Zeep project and sources on GitHub: https://github.com/mvantellingen/python-zeep
from zeep import Client, Transport, __version__ as zeep_version

# Configure web service connection.
# PLEASE NOTE:
#   If web service is not running on local machine (localhost/127.0.0.1),
#   you will have to call the login method at first, before being able to use any other method.
IP_ADDRESS = "localhost"
PORT = 1024
# Set 'INTRANET_ONLY', if an internet connection is not available.
# PLEASE NOTE:
#   This requires the 'soapencoding.xsd' to reside in './resources' subfolder.
#   It can be downloaded, here: http://schemas.xmlsoap.org/soap/encoding/
INTRANET_ONLY = False


# Web service constants
RETURN_CODE_SUCCESS = 0
COMMUNICATION_STARTED = 0
COMMUNICATION_STOPPED = 1
COMMUNICATION_ESTABLISHED = 2


class TransportIntranetOnly(Transport):

    def load(self, url):
        # See https://stackoverflow.com/a/40280341

        if (url == "http://schemas.xmlsoap.org/soap/encoding/"):
            url = "resources/soapencoding.xsd"

        # print(url)
        return super(TransportIntranetOnly, self).load(url)

def wait_for_communication(get_status):
    result = False
    while True:
        communication_status = get_status()
        print(f"Communication status: {communication_status}")

        if (communication_status == COMMUNICATION_ESTABLISHED):
            result = True
            break
        # Also leave loop if communcation has unexpectedly been stopped.
        if (communication_status == COMMUNICATION_STOPPED):
            print("Communication has been stopped.")
            break

        time.sleep(1)  # Wait before next poll.

    return result


def main(intranetonly):
    print("Web service OBD sample | RA Consulting GmbH 2021 | www.rac.de")
    print("")

    # PLEASE NOTE:
    #   DiagRA D or Silver Scan-Tool needs to be running and web service needs to be activated.

    wsdl = f"http://{IP_ADDRESS}:{PORT}/wsdl/IDiagRAWebservice"

    if intranetonly:
        client = Client(wsdl, transport=TransportIntranetOnly())
    else:
        client = Client(wsdl)

    webservice = client.service
    # factory = client.type_factory("ns0")  # Needed to handle non-primitive argument and return types.

    # Perform login.
    # PLEASE NOTE:
    #   This is required if web service is not running on local machine (localhost/127.0.0.1).
    # webservice.Login("Example python script")
    try:
        # Temporarily increase log level of the web service. Possible values are 1 to 7.
        # The log file is very helpful if things don't work out as expected. It contains all the called methods, the given arguments, the results and the return codes.
        # It is written to '%LocalAppData%\RA Consulting\DiagRA D\Log' or '%LocalAppData%\RA Consulting\Silver Scan-Tool\Log', respectively,
        # and is called 'DiagRA_RemoteControl_*.log'.
        # You can also set a permanent log level in the Windows registry. Have a look into DiagRA D's/Silver Scan-Tool's help file to find out how this is done.
        webservice.Configure("LOGLEVEL", "5")

        # Print versions.
        webservice_version = webservice.GetVersion("")
        print("Versions:")
        print(f"- Python {sys.version}")
        print(f"- Zeep {zeep_version}")
        print(f"- Web service {webservice_version}")
        print()

        # Set addressword for OBD and obtain its index.
        # PLEASE NOTE:
        #   If you like to communicate with a distinct ECU/addressword instead, you need to use 'GetECUIndex'
        #   and the web service's non-OBD methods (the ones not containing 'OBD' in their names).
        #   For a list of all available methods, see web service reference PDF that resides in
        #   subfolder '.\Samples\WebServices\Doc' of the installation directory.
        obd_index = webservice.GetOBDIndex("33", "")
        print(f"OBD index: {obd_index}")
        if (obd_index < RETURN_CODE_SUCCESS):
            print(webservice.GetLastErrorText())
        else:
            # OBD addressword has been successfully set.
            # Now set protocol.
            webservice.Configure("PROTOCOL", "ISO 15765-4 (CAN)")

            # Try to start communication.
            return_code = webservice.StartOBDCommunication(obd_index)
            print(f"Start communication: {return_code}")
            if (return_code == RETURN_CODE_SUCCESS):
                # Communication could be started.
                try:
                    # Wait until communication has fully been established, before requesting data.
                    communication_established = wait_for_communication(lambda: webservice.GetOBDCommunicationStatus(obd_index))

                    if communication_established:
                        # Read current data.
                        result = webservice.GetOBDAllCurrentData(obd_index)
                        print("Current Data: ")
                        for item in result:
                            print(item)

                        # Read module voltage.
                        result = webservice.GetOBDSingleCurrentData(obd_index, "42")
                        print("Control Module Voltage: ")
                        for item in result:
                            print(item)

                        # Get MIL status.
                        result = webservice.GetOBDMILStatus(obd_index)
                        print("Mode 3: ")
                        for item in result:
                            print(item)
                finally:
                    # Stop communication.
                    return_code = webservice.StopOBDCommunication(obd_index)
                    print(f"Stop communication: {return_code}")

    finally:
        # Perform logout.
        # webservice.Logout()
        pass


if (__name__ == "__main__"):
    main(INTRANET_ONLY)

Neues zu DiagRA D und Silver Scan-Tool

Aktuelle Versionen Stand 9. Dezember 2020: 7.45.40

  • neues Aufzeichnungsformat MDF4 mit wählbarer MDF Version 4.2.0, 4.1.1, 4.1.0 oder 4.0.0
  • Wir haben den DiagRA X Viewer auf unserem Download-Server hinzugefügt. Es handelt sich dabei um ein Zusatztool, das die mit der Aufzeichnungsfunktion von DiagRA D erstellten MDF4-Dateien öffnen kann. Wir haben es für die Nutzung mit DiagRA D aus unserem Applikationstool DiagRA X ausgekoppelt. Für den Viewer benötigen Sie keine zusätzliche Lizenz (genauso wie bei XML-Convert und XML-to-Excel).
  • Das Hilfstool XML-to-PDF wurde durch das Tool „XML-Convert“ ersetzt. Die XML-zu-PDF-Konvertierungsfunktion ist wieder in diesem neuen Tool implementiert und zusätzlich gibt es eine Funktion XML-zu-HTML. Der Grund dafür ist, dass es immer mehr Probleme gibt, wenn Browser XML-Dateien unter Verwendung eines Stylesheets öffnen sollen. Installieren Sie das Tool einfach. Es entfernt das XML-zu-PDF-Tool und bietet die gleiche Funktionalität plus die HTML-Konvertierungsfunktion.
  • Mit XML-to-Excel lassen sich die OBD-Daten aus XML-Ausgaben der DiagRA D Messabläufe nach Excel konvertieren. Man kann mehrere XML-Dateien in ein Excel-File konvertieren, gleichzeitig oder auch nacheinander, um diese zu vergleichen.
  • Anpassungsarbeiten für die neue SAE J1979-2 sind gestartet. Wir erwarten eine erste Version in der Mitte des 1. Quartals 2021 bereitstellen zu können.
  • Umfangreiche Erweiterungen für NOx Binning und Green House Gas in SAE J1939 und in SAE J1979 Mode $09

 

Nur DiagRA D

  • Unterstützung für CAN FD. Es werden bereits viele Interfacetypen unterstützt. Die Kommunikation mit Steuergeräten, die CAN FD unterstützen ist um einiges schneller – vor allem die Flashprogrammierung über das DiagRA D Flash Plugin.
  • Autosar XML für die Parametrierung der FlexRay-Kommunikation
© RA Consulting GmbH, 2024    USt.-Ident.-Nr.: DE143081464    HRB: 231127 ASAMAETAElektromobilität Süde-West
RA Consulting GmbH