VCP Scripter feature 1
BACKGROUND
Modern VAG ECUs are quite complicated to code / adapt, sometimes many changes are needed to activate a
single feature. In order to simplify the process and give a better opportunity to share the available codings ,
VCP features now the Scripter, a simple Pascal-Like script interpreter.
BASIC STRUCTURES AND SYNTAX
Scripts are based on Pascal, so the syntax is like in Pascal. The script has to be wrapped between begin / end
statements. You can find many Pascal tutorials on the internet - Example:
http://www.tutorialspoint.com/pascal
EXAMPLE SCRIPT
BEGIN
CONNECTTOECUTP20('17') ;
IF ISCONNECTEDTOECU THEN
BEGIN
WRITELN('CONNECTED') ;
WRITELN(GETECUNO) ;
WRITELN(GETECUDESCRIPTION) ;
WRITELN(DOREADAPK(3)) ;
IF DOWRITEAPK(3,'100') THEN WRITELN('APK OK') ELSE WRITELN('APK NOK') ;
WRITELN(DOREADAPK(3)) ;
END
ELSE
BEGIN
WRITELN('NOT CONNECTED') ;
END ;
CLOSECOMMUNICATION ;
END.
Explanations:
CONNECTTOECUTP20(‘17’) – connect to ECU with adressword 17 using TP20 protocol
ISCONNECTEDTOECU – this built-in variable will be set to TRUE when connection was established and to FALSE
when not.
WRITELN – just put some text on the “messages” box
GETECUNO – this function will return partnumber of the connected ECU as a string (=text)
GETECUDESCRIPTION – this function will return the description of the connected ECU (for example “Gateway
MQB”)
DOWRITEAPK(3,’100’) – writes value ‘100’ to adaptation channel number 3
VCP by www.vag-tech.eu | Background 1
VCP Scripter feature 2
DOREADAPK(3) – reads the value stored in adaptation channel 3
CLOSECOMMUNICATION – closes communication.
FUNCTION REFERENCE
FUNCTION NAME DESCRIPTION
procedure Writeln(s: string); Writes a string ‘s’ to messages box
function AskUserForInput(const Prompt: string) : string ; Displays a input window with configurable prompt.
Returns user input as a string
function IsConnectedToEcu : boolean ; Returns TRUE if connection to ECU was established,
FALSE when there’s no connection
procedure CloseCommunication ; Closes communication with ECU
function ConnectToEcuTP20(aw : string) : boolean ; Connects to ECU with adressword ‘aw’ using TP20
protocol
function ConnectToEcuUDS(aw : string) : boolean ; Connects to ECU with adressword ‘aw’ using UDS
protocol
function ConnectToEcuTP16(aw : string) : boolean ; Connects to ECU with adressword ‘aw’ using TP16
protocol
function ConnectToEcuKLine(aw : string) : boolean ; Connects to ECU with adressword ‘aw’ using
KWP2000/KWP1281 protocol
function DoLogin(login : integer) : boolean ; Performs a login procedure using login code
“login”. Returns TRUE if login was accepted, FALSE
if not.
function DoReadAPK(channel : integer) :string ; Reads contents of the adaptation channel
“channel” as string. If return value is empty –
reading error occurred
function DoWriteAPK(channel : integer ; value : string) : Writes “value” to adaptation channel “channel”.
boolean ; Returns TRUE when write was successful, FALSE
when not.
function ChangeDiagSession(session : integer) : boolean Changes current diagsession to standard
; (session=0), engineer (session=1) or EndOfLine
(session=2). Returns TRUE when change was
successful, FALSE when not
function ReadDataByID(ID : integer) : string ; Returns contents of the record (=adaptation ID in
UDS) pointed by ID. If return value is empty –
reading error occurred
function WriteDataByID(ID : integer ; DataToWrite : Writes to record pointed by ID hexstring
string) : Boolean “Datatowrite”. Returns TRUE when write was
successful, FALSE when not
function ReadLongCoding : string Returns long coding of the connected ECU. If return
value is empty – reading error occurred
function WriteLongCoding(codestring : string) : Boolean Writes Long coding “codestring” to connected ECU.
Returns TRUE when write was successful, FALSE
when not
function WriteShortCoding(coding : integer) : Boolean Writes short coding “coding” to connected ECU.
Returns TRUE when write was successful, FALSE
when not
VCP by www.vag-tech.eu | Function reference 2
VCP Scripter feature 3
procedure ClearDTC Clears all fault codes from connected ECU
function ReadMemory(addr,amount_to_read : integer ; Reads “amount_to_read” bytes of memory area
alfid : integer) : string starting at address “addr” using alfid
“alfid”.Hexadecimal addresses should start with ‘$’
(example $C01). Maximum add_to_read is 8, if you
want to read more bytes – you have to call this
function multiple times (2 for 16 bytes, 3 for 24
bytes etc) , changing read address . Alfid is a UDS
protocol element, standard value is ‘44’. Contact
support if you need more information about ALFID.
function WriteMemory(addr: integer ; DataToWrite : Writes “DataToWrite” Hexstring to memory under
string ; alfid : integer) : Boolean address “addr” Maximum length of DataToWrite is
16 characters (8 bytes). Alfid is a UDS protocol
element, standard value is ‘44’. Contact support if
you need more information about ALFID. Returns
TRUE when write was successful, FALSE when not
function GetECUShortCoding : string Returns short coding of the connected ECU
function GetECUODXVersion : string Returns required ODX container version of the
connected ECU
function GetECUODXId : string Returns required ODX container ID of the
connected ECU
function GetECUSWVersionHEX : string Returns Software version of the connected ECU
function GetECUDescription : string Returns description of the connected ECU
function GetECUNo : string Returns partnumber of the connected ECU
function SetBitInHexString(HexString : string ; Sets Bit BitNo in Hexstring’s Byte on position
ByteNo,BitNo : integer) : string; ByteNo. Return modified HexString. Bytes are
counted from left-to-right starting from 1. Bits are
counted 0-7. Example:
SetBitInHexString(‘000000’,1,0) returns 010000
function ClearBitInHexString(HexString : string ; Clears Bit BitNo in Hexstring’s Byte on position
ByteNo,BitNo : integer) : string; ByteNo. Return modified HexString. Bytes are
counted from left-to-right starting from 1. Bits are
counted 0-7. Example:
ClearBitInHexString(‘030000’,1,0) returns 020000
function TestBitInHexString(HexString : string ; Tests Bit BitNo in Hexstring’s Byte on position
ByteNo,BitNo : integer) : boolean ; ByteNo. Return true when bit is set and false when
not . Bytes are counted from left-to-right starting
from 1. Bits are counted 0-7
ChangeBytesInHexString(HexString,NewBytes : string ; Replaces bytes at position ByteNo of Hexstring with
ByteNo : integer) : string; NewBytes. Bytes are counted from left-to-right
starting from 1. Example:
ChangeBytesInHexString(‘000000’,’FF’,2) returns
00FF00
function GetApplicationPath : string ; Returns current VCP Installation path (eg. ‘c:\vcp\’)
function GetCurrentScriptPath : string ; Returns current script location path (eg.
‘c:\vcp\scripts\’. )
function ReadVIN : string ; Reads VIN from car. Note: VIN is readed from
Engine control unit.
procedure SaveStringToFile(stringtosave,filename : Saves String “stringtosave” to text file. Filename
string) ; should contain full path to file (eg.
‘d:\testfiles\test.txt’)
procedure DelayMiliseconds(amount : integer); Stops script execution for “amount” miliseconds.
procedure ECUReset; Performs ECU “terminal 15” reset. Note: works in
VCP by www.vag-tech.eu | Function reference 3
VCP Scripter feature 4
UDS control units only
UploadZDC(filename,DataSetNameToUpload : string ; Performs upload dataset “DateSetName” from ZDC
EraseFullMem : boolean) : string ; File “Filename”. Returns ‘OK’ when upload was
successful or error string when not.
Note: .zdc file must reside together with a script in
the same directory.
.ZDC files are bounded to key, you can not
download .zdc using key A and then distribute it to
system with key ‘B’. In this case, user with key ‘B’
has to download needed zdc file separately and put
it together with a script.
CRYPTED SCRIPTS
If you want to hide contents of the script, just save it as “Crypted script” (.CVCPSCRIPT). After opening such file,
its contents will be hidden, without loosing any functionality.
Note: crypted scripts can be only opened. They can not be edited or saved
VCP by www.vag-tech.eu | Crypted scripts 4
VCP Scripter feature 5
EXAMPLES
LOGIN EXAMPLE
begin
ConnectToEcuTP20('19') ;
if IsConnectedToEcu then
begin
writeln('connected') ;
writeln(GetECUNo) ;
writeln(GetECUDescription) ;
if dologin(20103) then writeln ('login OK') else writeln ('login nok') ;
end
else
begin
writeln('Not connected') ;
end ;
closecommunication ;
end.
GETTING USER RESPONSE
var
userresponse : string ;
begin
userresponse:=AskUserForInput('Please give answer ...') ;
writeln(userresponse) ;
end.
CHANGING DIAGNOSE SESSION
begin
ConnectToEcuTP20('17') ;
if IsConnectedToEcu then
begin
writeln('connected') ;
writeln(GetECUNo) ;
writeln(GetECUDescription) ;
writeln(GetECUShortCoding) ;
// diagsession 0 - standard, 1 - engineer, 2 - eol
if ChangeDiagSession(1) then writeln ('change diagsession OK') else writeln ('change diagsession nok') ;
end
else
begin
writeln('Not connected') ;
end ;
closecommunication ;
end.
VCP by www.vag-tech.eu | EXAMPLES 5
VCP Scripter feature 6
CHANGING ADAPTATION CHANNEL
begin
ConnectToEcuTP20('17') ;
if IsConnectedToEcu then
begin
writeln('connected') ;
writeln(GetECUNo) ;
writeln(GetECUDescription) ;
writeln(DoReadAPK(3)) ;
if dowriteapk(3,'100') then writeln('apk ok') else writeln('apk nok') ;
writeln(DoReadAPK(3)) ;
end
else
begin
writeln('Not connected') ;
end ;
closecommunication ;
end.
CHANGING SHORT CODING
begin
ConnectToEcuTP20('17') ;
if IsConnectedToEcu then
begin
writeln('connected') ;
writeln(GetECUNo) ;
writeln(GetECUDescription) ;
writeln(GetECUShortCoding) ;
if WriteShortCoding(262141) then writeln ('coding OK') else writeln ('coding nok') ;
writeln(GetECUShortCoding) ;
end
else
begin
writeln('Not connected') ;
end ;
closecommunication ;
end.
VCP by www.vag-tech.eu | EXAMPLES 6
VCP Scripter feature 7
READING / WRITING MEMORY
var
readedmem : string ;
begin
ConnectToEcuTP20('09') ;
if IsConnectedToEcu then
begin
writeln('connected') ;
writeln(GetECUNo) ;
writeln(GetECUDescription) ;
if dologin(42013) then writeln ('login OK') else writeln ('login nok') ;
if ChangeDiagSession(1) then writeln ('change diagsession OK') else writeln ('change diagsession nok') ;
readedmem:=ReadMemory($C01,4,0) ;
writeln(readedmem) ;
if writememory($C01,'40C16233',0) then writeln ('writemem OK') else writeln ('writemem nok') ;
readedmem:=ReadMemory($C01,4,0) ;
writeln(readedmem) ;
end
else
begin
writeln('Not connected') ;
end ;
closecommunication ;
end.
CHANGING LONG CODING
begin
ConnectToEcuUDS('19') ;
if IsConnectedToEcu then
begin
writeln('connected') ;
writeln(GetECUNo) ;
writeln(GetECUDescription) ;
writeln(ReadLongCoding) ;
if writelongcoding('000000340B087300CF00025A1C0F00010001000000000000000000000001') then writeln
('Coding OK') else writeln ('Coding nok') ;
writeln(ReadLongCoding) ;
if changediagsession('02') then writeln ('change diagsession OK') else writeln ('change diagsession nok') ;
end
else
begin
writeln('Not connected') ;
end ;
closecommunication ;
end.
VCP by www.vag-tech.eu | EXAMPLES 7
VCP Scripter feature 8
SETTING AND CLEARING BITS IN HEXSTRING
var
teststring : string ;
begin
teststring:='01020408' ;
if TestBitInHexString(teststring,4,3) then writeln('ok') ; // returns true when bit 3 in hexstring's byte 4 is set.
teststring:=SetBitInHexString(teststring,1,2) ; // sets bit 2 in hexstring's byte 1
writeln(teststring) ;
teststring:=ClearBitInHexString(teststring,1,2) ; // clears bit 2 in hexstring's byte 1
writeln(teststring) ;
end.
UPLOADING THE ZDC FILE
begin
if ConnectToEcuUDS('55') then
begin
// uploads file 'passatcc_5m0_xenon.zdc', dataset name 'PASSAT_CC_5M0907357F_AFS_DATA'
// with eraseFullMemory on
// prints ‘OK’ if upload was successful
writeln(uploadzdc('passatcc_5m0_xenon.zdc','PASSAT_CC_5M0907357F_AFS_DATA',true));
closecommunication ;
end ;
end.
Have FUN !
VCP by www.vag-tech.eu | EXAMPLES 8