Program Prog1;
var code: string;
procedure ReadCode;
begin
  if not ReadDevice then begin
    MsgBox( 'Read Error', 'Error', MB_OK );
  end
  else begin
    Code := chr(GetByteHexEdit( $31 ))+
              chr(GetByteHexEdit($32))+
              chr(GetByteHexEdit( $33 ))+
              chr(GetByteHexEdit( $34 ));
    MsgBox( Code, 'Code', MB_OK or MB_ICONINFORMATION );
    code := 'ewqwe';
  end;
end;

procedure WriteCode;
var n: integer;
begin
  SetProgramModifiedOnly( true );
  if InBox( 'Enter', 'Code', code ) then begin
    if  length( code ) < 4 then begin
      MsgBox( 'Enter 4 numbers', 'Error', MB_OK );    
      exit;
    end;
    n := StrToInt( code );
    SetByteHexEdit( $31, ord(code[1]) );
    SetByteHexEdit( $32, ord(code[2]) );
    SetByteHexEdit( $33, ord(code[3]) );
    SetByteHexEdit( $34, ord(code[4]) );
    RefreshHexEdit;
    if MsgBox( 'Program?', 'Confirm', MB_YESNO ) = IDYES then begin    
      ProgramDevice;
      VerifyDevice;	
    end; 
  end;
end;

begin
  AddDeviceGroup( 'Samples', 'Select a Device' );  
  AddDevice( 'Opel Immo', '68HC05B8 - 0F10V', 'Samples', 'MC68HC05B8'); 
  AddAction( 'Read Code', 'ReadCode', 'Opel Immo' ); 
  AddAction( 'Write Code', 'WriteCode', 'Opel Immo' ); 
  AddOpenFileAction( 'Board Top Side', 'Opel Immo', 'opel_imo2.jpg' );
  AddOpenFileAction( 'Board Bottom Side', 'Opel Immo', 'opel_imo3.jpg' );
  AddOpenFileAction( 'Connections', 'Opel Immo', 'mc68hc05b8_uusp.png' );
  AddOpenFileAction( 'Connections Specifics', 'Opel Immo', 'mc68hc05b8_uusp.txt' );
  AddOpenFileAction( 'Edit sample1.uds', 'Opel Immo', 'sample1.uds' );
  AddMsg('Sample Device Script (sample1.uds) Installed '#169' 2005 ELRASOFT');
  SetProductInfo( 'Sample1', 'Device Script Example'#$D'Copyright'#169' 2006 ELRASOFT Ltd.' );
end.
