More and more users of DiagRA D and Silver Scan-Tool are taking advantage of the remote control option via the Webservices API. Via the interface, external applications on the same computer or in the local network can use almost the complete functionality of both applications. For example, flash sequences with subsequent diagnostic tests can be automated via a Python script or special diagnostic tests on HiLs or test benches can be integrated into the experiments. Of course, recurring OBD tests can also be automated very easily.
Technical background: The interface of the web services is given by a machine-processable format, typically by WSDL (Web Services Description Language). The network protocol SOAP (Simple Object Access Protocol) is used for communication. XML is used as the message format and the HTTP protocol for communication within the network. In the case of DiagRA D/Silver Scan-Tool, communication takes place between a client programme and DiagRA D/Silver Scan-Tool, with DiagRA D/Silver Scan-Tool serving as the server application. The web services are implemented as an API for SOAP, so the user does not have to worry about creating the XML messages or HTTP communication.
The example below shows how the communication is first initiated via DiagRA D using a Python script, then all values from mode $01 are read from all OBD ECUs, then the ECU supply voltage PID $42 is specifically read, and finally the MIL status from mode $03 is read. Finally, communication with the OBD system is terminated. In the example, ZEEP is used as the SOAP client. Documentation of the commands can be found directly in existing installations of DiagRA D or Silver Scan-Tool in the Samples folder.
The Webservices plugin is an optional extension of a DiagRA D or Silver Scan-Tool licence and can either be ordered with a licence or added later.
If you are interested, please contact us at info@rac.de.
Example Python script:
#!/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)