Announcement

Collapse
No announcement yet.

Errors in the DECLARE part?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Errors in the DECLARE part?

    Dear support

    I have written an console program for drive servo motors but it doesn"t work, I don't know why it doesn't work.

    This is my application code:
    =====================

    Code:
    #COMPILE EXE
    #DIM ALL
    DECLARE SUB      STDCALL Out32 LIB "inpout32.dll" ALIAS "OUT32" (BYVAL portID AS INTEGER, BYVAL nByte AS INTEGER)
    DECLARE FUNCTION STDCALL Inp32 LIB "inpout32.dll" ALIAS "INP32" (BYVAL portID AS INTEGER) AS INTEGER
    DECLARE FUNCTION sscanf(STRING buf, STRING format,...),INT
    DECLARE FUNCTION sprintf(POINTER p, POINTER p, ...), INT
    MACRO BA = &h2F8
    
    '=========================================================================================================='
    '                                   Rechstreekse digitale output                                           '
    '                                                                                                          '
    '- De RTS en CTS lijnen kunnen rechtstreeks worden aangestuurd omdat we slechts 1 commando nodig is        '
    '- Deze uitgangen kunnen zeer snel en nauwkeurig getimed worden als we deze koppelen aan de interne klok   '
    '  van de computer                                                                                         '
    '- De klok van de PC bestaat uit een 16-bit teller die met een frequentie van 1.193182 MHz aftelt          '
    '- Na elke 65536 klokpulsen, dus na : fclock / 2^16 = 18.206 Hz loopt de teller over (overflow) waardoor   '
    '  een interrupt wordt opgewekt                                                                            '
    '  Deze interrupt routine wordt gebruikt voor de software teller voor het instellen van de datum en de tijd'
    '  Toepassing : processen op de seconde nauwkeurig                                                         '
    '- De interrupts beïnvloeden de verwerkingssnelheid van de CPU                                             '
    '                                                                                                          '
    '                                   Schakelklok                                                            '
    '                                                                                                          '
    '- Gebruik : OUT32 ((BA + 0x04), data_byte))                                                               '
    '  databyte = 0 ==> DTR = 0                                                                                '
    '  databyte = 1 ==> DTR = 1                                                                                '
    '  databyte = 2 ==> RTS = 1                                                                                '
    '  IF TIME$ >= "17:00:00" THEN OUT32 ((BA + 0x04), data_byte))                                             '
    '  Programma maken die op de achtergrond draait en de verbruikers schakelt terwijl de PC voor andere doel  '
    '  einden kunnen gebruiken                                                                                 '                                                                                                                   '
    '=========================================================================================================='
    FUNCTION PBMAIN () AS LONG
        'Servosturing
        'Hoofdprogramma
        DIM setup_tijd  AS DOUBLE
        DIM ch          AS STRING
        
        CALL Test()
        DO
            Sturing()
        LOOP UNTIL INSTAT
    
    END FUNCTION
    
    SUB Test()
        LOCAL high, low AS BYTE
        LOCAL m AS WORD
        
        ! cli
        
        OUT32 (&h43, &h34)                          ' TIMER 0, Mode 2
        OUT32 (&h40, &h00)                          ' TIMER 0, low RESET
        OUT32 (&h40, &h00)                          ' TIMER 0, high RESET
    
        FOR m = 1 TO 1000 : NEXT m                  ' tijdsmeting
    
        OUT32 (&h43, &h04)                          ' TIMER 0, bevriezen
        low  = INP32(&h40)                          ' TIMER 0, uitlezen
        high = INP32(&h40)
    
        ! sti
        
        setup_tijd = -(low + 256 * high) / 1000
        PRINT USING("Cyclusduur: #####.###", setup_tijd)
        PRINT
    END SUB
    
    SUB Impulsgenerator(BYVAL impuls_width AS LONG)
        LOCAL on_time  AS WORD
        LOCAL off_time AS WORD
        LOCAL getal    AS WORD
        LOCAL teller   AS WORD
    
        on_time =  ROUND(impuls_width / setup_tijd)
        off_time = ROUND(10000 / setup_tijd)
        
        ! cli
        
        FOR getal = 1 TO 50
            OUT32 ((BA + &h04), &h01                'DTR = 1
            FOR m = 1 TO on_time : NEXT m           'impulstijd
            OUT32 ((BA + &h04), &h00                'DTR = 0
            FOR m = 1 TO off_time : NEXT m          'pausetijd
        NEXT getal
        
        ! sti
    END SUB
    
    SUB Sturing()
        LOCAL n AS INTEGER
        FOR n = 1 TO 10
            CALL ImpulsGenerator(1000 + n * 100)
        NEXT n
    END SUB
    This is the Error report :
    ==================

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\SpinDisk\SPINDISK.BAS {91 total lines}
    Target compilation: SPINDISK.exe
    Compile time: 0.1 seconds, at 109200 lines/minute

    1820 bytes compiled code, 15317 bytes RTLibrary,
    100 bytes string literals, and 2124 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 23552 bytes Memory image: 17541 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\SpinDisk\SPINDISK.BAS
    ==============================
    Compile succeeded at 15:13:53 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\FrmPrint.bas {106 total lines}
    Target compilation: FrmPrint.exe
    Compile time: 0.1 seconds, at 127200 lines/minute

    1596 bytes compiled code, 23449 bytes RTLibrary,
    208 bytes string literals, and 2124 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 31232 bytes Memory image: 25781 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\FrmPrint.bas
    ==============================
    Compile succeeded at 15:14:05 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas {16 total lines}
    Target compilation: WaitKey_InStat_Ex_1.exe
    Compile time: 0.1 seconds, at 19200 lines/minute

    540 bytes compiled code, 4798 bytes RTLibrary,
    16 bytes string literals, and 1892 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6706 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas
    ==============================
    Compile succeeded at 15:33:38 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas {16 total lines}
    Target compilation: WaitKey_InStat_Ex_1.exe
    Compile time: 0.1 seconds, at 19200 lines/minute

    540 bytes compiled code, 4798 bytes RTLibrary,
    16 bytes string literals, and 1892 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6706 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas
    ==============================
    Compile succeeded at 15:33:40 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas {16 total lines}
    Target compilation: WaitKey_InStat_Ex_1.exe
    Compile time: 0.1 seconds, at 19200 lines/minute

    540 bytes compiled code, 4798 bytes RTLibrary,
    16 bytes string literals, and 1892 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6706 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas
    ==============================
    Compile succeeded at 15:34:03 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_2.bas {24 total lines}
    Target compilation: WaitKey_InStat_Ex_2.exe
    Compile time: 0.1 seconds, at 28800 lines/minute

    572 bytes compiled code, 5150 bytes RTLibrary,
    8 bytes string literals, and 1884 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9728 bytes Memory image: 7042 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_2.bas
    ==============================
    Compile succeeded at 15:35:18 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_2.bas {26 total lines}
    Target compilation: WaitKey_InStat_Ex_2.exe
    Compile time: 0.1 seconds, at 31200 lines/minute

    524 bytes compiled code, 5005 bytes RTLibrary,
    8 bytes string literals, and 1884 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6897 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_2.bas
    ==============================
    Compile succeeded at 15:36:19 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_2.bas {26 total lines}
    Target compilation: WaitKey_InStat_Ex_2.exe
    Compile time: 0.1 seconds, at 31200 lines/minute

    524 bytes compiled code, 5005 bytes RTLibrary,
    8 bytes string literals, and 1884 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6897 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_2.bas
    ==============================
    Compile succeeded at 15:36:44 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\COM\Say\Say.bas {52768 total lines}
    Target compilation: Say.exe
    Compile time: 0.7 seconds, at 4522971 lines/minute

    8769 bytes compiled code, 16888 bytes RTLibrary,
    104 bytes string literals, and 4384 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 33280 bytes Memory image: 21376 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\COM\Say\Say.bas
    E:\PROGRA~1\PBCC50\WINAPI\WIN32API.INC
    E:\PROGRAM FILES\PBCC50\SAMPLES\COM\SAY\SAY.INC
    ==============================
    Compile succeeded at 15:37:48 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas {16 total lines}
    Target compilation: WaitKey_InStat_Ex_1.exe
    Compile time: 0.1 seconds, at 19200 lines/minute

    540 bytes compiled code, 4798 bytes RTLibrary,
    16 bytes string literals, and 1892 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6706 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas
    ==============================
    Compile succeeded at 15:41:27 on 23/09/2008

    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas {16 total lines}
    Target compilation: WaitKey_InStat_Ex_1.exe
    Compile time: 0.1 seconds, at 19200 lines/minute

    540 bytes compiled code, 4798 bytes RTLibrary,
    16 bytes string literals, and 1892 bytes dgroup.
    Executable stack size: 1048576 bytes.
    Disk image: 9216 bytes Memory image: 6706 bytes.

    Component Files:
    ----------------
    E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\WaitKey_InStat_Ex_1.bas
    ==============================
    Compile succeeded at 15:41:39 on 23/09/2008

    File(s) not saved. Compile canceled.
    PowerBASIC Console Compiler
    PB/CC Version 5.00
    Copyright (c) 1998-2008 PowerBasic Inc.
    Venice, Florida USA
    All Rights Reserved

    Error 426 in E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\Auto_Servo_Drive.bas(3:018): Variable expected
    Line 3: DECLARE SUB STDCALL Out32 LIB "inpout32.dll" ALIAS "OUT32" (BYVAL portID AS INTEGER, BYVAL nByte AS INTEGER)
    ==============================
    Compile failed at 19:42:04 on 23/09/2008

    Can someone help me what wrong here

    Kind regards
    Stephane

  • #2
    STDCALL goes after the subroutine name. And then you will find other problems. Most can be resolved by reading the manual.

    For instance the 3rd and 4th declares in your post will fail as well ... tthey are obviously not legitimate PB BASIC parameter specifications.
    Rick Angell

    Comment


    • #3
      Richard Angell

      This is my corrected code.
      This code compile find, but run fails why?

      Code:
      #COMPILE EXE
      #DIM ALL
      DECLARE SUB      Out32 STDCALL LIB "inpout32.dll" ALIAS "Out32" (BYVAL portID AS INTEGER, BYVAL nByte AS INTEGER)
      DECLARE FUNCTION Inp32 STDCALL LIB "inpout32.dll" ALIAS "Inp32" (BYVAL portID AS INTEGER) AS INTEGER
      
      MACRO BA = &h2F8      
      
      GLOBAL setup_tijd AS DOUBLE
      
      FUNCTION PBMAIN () AS LONG
          'Servosturing
          'Hoofdprogramma
          DIM ch          AS STRING
          
          CALL Test()
          DO
              Sturing()
          LOOP UNTIL INSTAT
      
      END FUNCTION
      
      SUB Test()
          LOCAL high, low AS BYTE
          LOCAL m AS WORD
          
          ! cli
          
          OUT32 (&h43, &h34)                          ' TIMER 0, Mode 2
          OUT32 (&h40, &h00)                          ' TIMER 0, low RESET
          OUT32 (&h40, &h00)                          ' TIMER 0, high RESET
      
          FOR m = 1 TO 1000 : NEXT m                  ' tijdsmeting
      
          OUT32 (&h43, &h04)                          ' TIMER 0, bevriezen
          low  = INP32(&h40)                          ' TIMER 0, uitlezen
          high = INP32(&h40)
      
          ! sti
          
          setup_tijd = -(low + 256 * high) / 1000
          LOCAL a AS STRING
          a = USING$("######.###", setup_tijd)
          STDOUT "Cyclusduur: " & a
          PRINT
      END SUB
      
      SUB Impulsgenerator(BYVAL impuls_width AS LONG)
          LOCAL on_time  AS WORD
          LOCAL off_time AS WORD
          LOCAL getal    AS WORD
          LOCAL m        AS WORD
      
          on_time =  ROUND(impuls_width / setup_tijd, 2)
          off_time = ROUND(10000 / setup_tijd, 2)
          
          ! cli
          
          FOR getal = 1 TO 50
              OUT32 ((BA + &h04), &h01)               'DTR = 1
              FOR m = 1 TO on_time : NEXT m           'impulstijd
              OUT32 ((BA + &h04), &h00)               'DTR = 0
              FOR m = 1 TO off_time : NEXT m          'pausetijd
          NEXT getal
          
          ! sti
      END SUB
      
      SUB Sturing()
          LOCAL n AS INTEGER
          FOR n = 1 TO 10
              CALL ImpulsGenerator(1000 + n * 100)
          NEXT n
      END SUB
      Error report:
      =========

      PowerBASIC Console Compiler
      PB/CC Version 5.00
      Copyright (c) 1998-2008 PowerBasic Inc.
      Venice, Florida USA
      All Rights Reserved

      Primary source: E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\Auto_Servo_Drive.bas {98 total lines}
      Target compilation: Auto_Servo_Drive.exe
      Compile time: 0.1 seconds, at 117600 lines/minute

      1116 bytes compiled code, 9043 bytes RTLibrary,
      36 bytes string literals, and 1972 bytes dgroup.
      Executable stack size: 1048576 bytes.
      Disk image: 13824 bytes Memory image: 11051 bytes.

      Component Files:
      ----------------
      E:\PROGRA~1\PBCC50\Samples\Graphic\FrmPrint\Auto_Servo_Drive.bas
      ==============================
      Compile succeeded at 21:20:30 on 23/09/2008

      In attachtment the WinXP error message

      I have A questions of this declares is corrected?

      DECLARE FUNCTION sscanf CDECL ALIAS "int _sscanf ( const char * str, const char * format, ...)"
      Attached Files
      Last edited by Stephane Fonteyne; 23 Sep 2008, 02:44 PM.

      Comment


      • #4
        what do you expect to happen here?

        Code:
        FOR m = 1 TO on_time : NEXT m

        Comment


        • #5
          Ms

          It's SF's timing loop, a delay probably for external events, another timer, to have time to transpire. He might be better to simply use Sleep ### here.
          Last edited by Richard Angell; 23 Sep 2008, 07:30 PM.
          Rick Angell

          Comment


          • #6
            Originally posted by Helpfile:
            ALIAS
            A string literal that identifies the name and capitalization of the procedure in the external DLL.
            But you are using all capitalized calls in the program, whereas the DECLARE uses all mixed case.
            Last edited by Richard Angell; 24 Sep 2008, 08:53 AM.
            Rick Angell

            Comment


            • #7
              Bu[t] you are using all capitalized calls in the program, whereas the DECLARE uses all mixed case.
              Symbols such as procedure names and variable names are case-insensitive; external references in the ALIAS clause are case-sensitive.

              Maybe this will help:
              Code:
              DECLARE FUNCTION [i]symbol-name[/i] LIB "library-name" ALIAS "[i]external-reference-name[/i]" .......
              ...
              ...   CALL [i]symbol-name[/i]   .......

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X