Program Prog1;
var 
Code,Code_1,Code_2,Code_3,Code_4: string;
Code_On,Time_Blocked: Integer;

Procedure ReadCode;
begin     
  SetProgramModifiedOnly( false );
  if not ReadDevice then 
   begin
    MsgBox( 'Read Error', 'Error', MB_OK );
   end
  else
   begin
    Code_1:=inttohex(GetByteHexEdit($7B),2);
    Code_2:=inttohex(GetByteHexEdit($7A),2);
    
    Code:=Code_1+Code_2
    
    AddMsg('');
    AddMsg('Code is: '+ Code);
    Time_Blocked:=GetByteHexEdit($7C);
     if Time_Blocked=$03 then
    AddMsg ('Time Blocked is aktive');    
    AddMsg('');
   end;
end;

Procedure ResetTime;
begin 
    SetProgramModifiedOnly( false );
    SetProgramModifiedOnly( true );
    SetByteHexEdit( $7C, $00);
    RefreshHexEdit;
    ProgramDevice;  
    SetProgramModifiedOnly( false );
    ReadCode;
end;

Procedure NewCode;

begin   
  SetProgramModifiedOnly( false );
  SetProgramModifiedOnly( true );
  if InBox( 'Enter', 'Code', code ) then begin
    if  length( code ) < 4 then begin
      MsgBox( 'Enter 4 numbers', 'Error', MB_OK );    
      exit;
    end;
    if  StrToInt( code )> 9999 then begin
      MsgBox( 'Enter 0001-9999 Code', 'Error', MB_OK );    
      exit;
    end;

    SetByteHexEdit( $7B, StrToInt('$'+ code[1]+code[2]));
    SetByteHexEdit( $7A, StrToInt('$'+ code[3]+code[4]));

    RefreshHexEdit;
    ProgramDevice; 
    SetProgramModifiedOnly( false );
    VerifyDevice;
    ReadCode;    
  end;                             
end;

begin
  AddDeviceGroup( 'RADIO', 'Select a Device' );  
  AddDevice( 'Volvo HU-405/HU-605', '93C46 ROTATED', 'RADIO', '93C46 x16' ); 
  AddAction( 'Read Code', 'ReadCode', 'Volvo HU-405/HU-605' ); 
  AddAction( 'New Code', 'NewCode', 'Volvo HU-405/HU-605' );           
  AddAction( 'Reset Time Blocked', 'ResetTime', 'Volvo HU-405/HU-605' );  
  AddOpenFileAction( 'Powering up', 'Volvo HU-405/HU-605', 'volvo_hu-605.jpg' );
  AddMsg('Sample Device Script (volvo_hu-405_hu-605.uds) Installed  J.M.Serwis ');
  SetProductInfo( 'Volvo HU-405/HU-605', 'Device Script Example'#$D'Copyright J.M.Serwis' );
end.

