%%%
  VERSION: 1
  LANGUAGE: ENGLISH
%%%

MODULE PAINT (SYSMODULE, NOSTEPIN)
  
  CONST string DnsioChannel:="DNSIO2";
  CONST string strCmd:="dpr e 0x328 0x4040";

  LOCAL VAR IODEV ComPortDR;
  LOCAL VAR IODEV ComPortDW;


  PROC SysPntReset()
    ConfJ \Off;
    ConfL \Off;
  ENDPROC


  PROC SpeedSup()

    Open DnsioChannel,ComPortDW\Write;
    Open DnsioChannel,ComPortDR\Read;

    Write ComPortDW, strCmd; ! send command

    if not ResultsOk() then
      ErrWrite "Speed sup mode not set","ACCB not informed about Speed sup mode";
    endif

    Close ComPortDR;
    Close ComPortDW;
  ENDPROC

  LOCAL FUNC bool ResultsOk(
  \num nTimeout)

    ! Scope: Find result. Returns TRUE if value $0 is found, else FALSE.

    CONST string strRoutineName := "ResultsOk";
    VAR num nLocalTime := 5;
    VAR num nValue:=0;
    VAR num nResultLen:=0;
    VAR num nResultPos:=0;
    VAR num nDigitPos:=0;
    VAR num nResultMatch:=0;
    VAR bool bContinue:=TRUE;
    VAR string strResultStr:="";
    VAR string strResult:="";

    if present (nTimeout) nLocalTime := nTimeout;
    while bContinue do
      strResultStr:=ReadStr(ComPortDR\Time:=nLocalTime);
      nResultLen:=StrLen(strResultStr);
      if nResultLen>0 then
        nResultPos:=StrFind(strResultStr,1,"$");
        if nResultPos<>(nResultLen+1) then ! "$" is found. put answer in strResult.
          nDigitPos:=StrFind(strResultStr,nResultPos,STR_DIGIT);
          strResult:=StrPart(strResultStr,nDigitPos,(nDigitPos+1)-nResultLen);
          bContinue:=false;
          strResultStr:=ReadStr(ComPortDR\Time:=1); ! Read prompt out of buffer.
          if StrToVal(strResult,nValue) then
            if nValue=0 then
              return true;
            else
              test nValue
                case 1:
                  ErrWrite "Unknown command","Unknown command reported from ACA.";
                case 2:
                  ErrWrite "Parameter missing","Parameter missing reported from ACA.";
                case 3:
                  ErrWrite "Illegal parameter","Illegal parameter reported from ACA.";
                case 4:
                  ErrWrite "$4 returned.","$4 returned from ACA.";
                default:
              endtest
            endif
          endif
        endif
      endif
    endwhile
    return false;
  error
    if ERRNO=ERR_DEV_MAXTIME then
      ErrWrite "Timeout","No $ found, timeout aborted readstr";
	return false;
    endif
    return false;
  ENDFUNC
     
ENDMODULE
