Announcement

Collapse
No announcement yet.

Cannot an call with main program in PBDOS

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

  • Cannot an call with main program in PBDOS

    Hey all,

    I will called the routines in the selfcreating but it gives errors
    it said not found, what not found?
    What do I wrong, I don't find the error !!!!

    'Unit
    '==========================================================================='
    'Read and Write the PC Ports in DOS '
    '==========================================================================='
    $COMPILE UNIT "PORTS16.PBU"

    'Return an byte from the specific port
    DECLARE FUNCTION InportB(BYVAL PortAddress AS WORD) AS BYTE

    'Return an word from the specific port
    DECLARE FUNCTION InportW(BYVAL PortAddress AS WORD) AS WORD

    'Write an byte to the specific port
    DECLARE SUB OutportB(BYVAL PortAddress AS WORD, BYVAL Value AS BYTE)

    'Write an word to the specific port
    DECLARE SUB OutportW(BYVAL PortAddress AS WORD, BYVAL Value AS WORD)

    SUB OutportB(BYVAL PortAddress AS WORD, BYVAL value AS BYTE)
    ASM mov AX, value
    ASM mov DX, PortAddress
    ASM out DX, AL
    END SUB

    FUNCTION InportB(BYVAL PortAddress AS WORD) AS BYTE
    ASM mov DX, PortAddress
    ASM IN AL, DX
    ASM mov FUNCTION[0], AL
    END FUNCTION

    SUB OutportW(BYVAL PortAddress AS WORD, BYVAL value AS WORD) PUBLIC
    ASM mov AX, value
    ASM mov DX, PortAddress
    ASM out DX, AX
    END SUB

    FUNCTION InportW(BYVAL PortAddress AS WORD) AS WORD
    ASM mov DX, PortAddress
    ASM IN AX, DX
    ASM mov FUNCTION[0], AX
    END FUNCTION

    'End Unit


    'My Application program
    ========================

    '==========================================================================="
    ' Programma : Servobesturing "
    ' Copyright : Brainsoft Programmers 2001 "
    '==========================================================================="

    '======================================="
    ' Hoofdprogramma "
    '======================================="

    $COMPILE UNIT "E:\PB35\PB-PBU\PORTS16.PBU"
    DECLARE SUB Test()

    %BA = &H3F8
    DIM Schleifenzeit AS SHARED SINGLE
    DIM Ch AS STRING * 1

    'Begin
    CALL Test
    DO
    CALL Steuerung
    LOOP UNTIL INSTAT
    END

    '======================================="
    ' procedure test "
    '======================================="
    SUB Test

    DIM High AS BYTE
    DIM Low AS BYTE
    DIM m AS WORD
    DIM FmtStr AS STRING

    $INLINE &HFA 'CLI, interrupt blokkeren
    OutportB &H43, &H34 'Timer 0, Mode 2
    OutportB &H40, &H00 'Timer 0, low reset
    OutportB &H40, &H00 'Timer 0, high reset
    FOR m = 1 TO 1000 : NEXT m 'tijdmeting
    OutportB &H43, &H04 'Timer 0, bevriezen
    Low = InportB(&H40) 'Timer 0, uitlezen
    High = InportB(&H40)
    $INLINE &HFB 'STI, interrupt vrijgeven
    Schleifenzeit = -(Low + 256 * High) / 1000
    FmtStr = UNSING$("#####.###",Schleifenzeit)
    PRINT "Cyclusduur = " + FmtStr + "æs";
    PRINT
    END SUB

    SUB Impulsgenerator(BYVAL Laenge AS INTEGER)
    DIM Anzeit AS WORD
    DIM Auszeit AS WORD
    DIM Anzahl AS WORD
    DIM m AS WORD

    Anzeit = ROUND(Laenge / Schleifenzeit)
    Auszeit = ROUND(10000 / Schleifenzeit)
    $INLINE &HFA
    FOR Anzahl = 1 TO 50
    OutPortB %BA + 4, 1 'DTR Aan
    FOR m = 1 TO Anzeit : NEXT m 'Impulstijd
    OutportB %BA + 4, 0 'DTR uit
    FOR m = 1 TO Auszeit : NEXT m 'Pauze
    NEXT Anzahl
    $INLINE &HFB
    END SUB

    SUB Steuerung
    DIM n AS INTEGER

    FOR n = 1 TO 10
    CALL Impulsgenerator(1000 + n * 100)
    NEXT
    END SUB

    Greetz
    Stephane



    ------------------
    ICQ: 123632482

  • #2
    Greetings Stephane!

    I've changed your code slightly to compile. Take a gander at the code and then read below to see the changes:

    Code:
    'Unit 
    '==========================================================================='
    'Read and Write the PC Ports in DOS                                         '
    '==========================================================================='
    $ERROR ALL ON
    $COMPILE UNIT "PORTS16.PBU"
        
    'Return an byte from the specific port
    DECLARE FUNCTION InportB(BYVAL PortAddress AS WORD) AS BYTE
        
    'Return an word from the specific port
    DECLARE FUNCTION InportW(BYVAL PortAddress AS WORD) AS WORD
        
    'Write an byte to the specific port
    DECLARE SUB OutportB(BYVAL PortAddress AS WORD, BYVAL Value AS BYTE)
        
    'Write an word to the specific port
    DECLARE SUB OutportW(BYVAL PortAddress AS WORD, BYVAL Value AS WORD)
        
    SUB OutportB(BYVAL PortAddress AS WORD, BYVAL value AS BYTE) PUBLIC
      ASM mov AX, value
      ASM mov DX, PortAddress
      ASM out DX, AL
    END SUB
        
    FUNCTION InportB(BYVAL PortAddress AS WORD) PUBLIC AS BYTE
      ASM mov DX, PortAddress
      ASM IN AL, DX
      ASM mov FUNCTION[0], AL
    END FUNCTION
        
    SUB OutportW(BYVAL PortAddress AS WORD, BYVAL value AS WORD) PUBLIC
      ASM mov AX, value
      ASM mov DX, PortAddress
      ASM out DX, AX
    END SUB
        
    FUNCTION InportW(BYVAL PortAddress AS WORD) PUBLIC AS WORD
      ASM mov DX, PortAddress
      ASM IN AX, DX
      ASM mov FUNCTION[0], AX
    END FUNCTION
        
    'End Unit
    In the library I made sure to make each FUNCTION accessible to the main executable by dictating PUBLIC on each routine. I also make sure I run with "$ERROR ALL ON" to point out any mistakes.

    Code:
    'My Application program
    '========================
        
    '==========================================================================="
    ' Programma : Servobesturing                                                "
    ' Copyright : Brainsoft Programmers 2001                                    "
    '==========================================================================="
        
    '======================================="
    '           Hoofdprogramma              "
    '======================================="
        
    $LINK "PORTS16.PBU"
    DECLARE SUB Test()
        
    %BA = &H3F8
    DIM Schleifenzeit AS SHARED SINGLE
    DIM Ch AS STRING * 1
        
    'Begin
      CALL Test
      DO
         CALL Steuerung
      LOOP UNTIL INSTAT
    END
        
    '======================================="
    ' procedure test                        "
    '======================================="
    SUB Test
        
      DIM High    AS BYTE
       DIM Low     AS BYTE
       DIM m       AS WORD
       DIM FmtStr  AS STRING
        
       $INLINE &HFA                   'CLI, interrupt blokkeren
       OutportB &H43, &H34            'Timer 0, Mode 2
       OutportB &H40, &H00            'Timer 0, low reset
       OutportB &H40, &H00                'Timer 0, high reset
       FOR m = 1 TO 1000 : NEXT m         'tijdmeting
       OutportB &H43, &H04            'Timer 0, bevriezen
       Low  = InportB(&H40)             'Timer 0, uitlezen
       High = InportB(&H40)
       $INLINE &HFB                 'STI, interrupt vrijgeven
       Schleifenzeit = -(Low + 256 * High) / 1000
       FmtStr = USING$("#####.###",Schleifenzeit)
       PRINT "Cyclusduur = " + FmtStr + "æs";
       PRINT
    END SUB
        
    SUB Impulsgenerator(BYVAL Laenge AS INTEGER)
        DIM Anzeit  AS WORD
        DIM Auszeit AS WORD
        DIM Anzahl  AS WORD
        DIM m       AS WORD
        
        Anzeit  = ROUND(Laenge / Schleifenzeit,0)
        Auszeit = ROUND(10000  / Schleifenzeit,0)
        $INLINE &HFA
        FOR Anzahl = 1 TO 50
            OutPortB %BA + 4, 1             'DTR Aan
            FOR m = 1 TO Anzeit : NEXT m    'Impulstijd
            OutportB %BA + 4, 0             'DTR uit
            FOR m = 1 TO Auszeit : NEXT m   'Pauze
        NEXT Anzahl
        $INLINE &HFB
    END SUB
        
    SUB Steuerung
        DIM n AS INTEGER
    
        FOR n = 1 TO 10
            CALL Impulsgenerator(1000 + n * 100)
        NEXT
    END SUB
    This code had a few problems. One, you needed to LINK to the library not try to recreate it. In the line:

    Code:
    FmtStr = USING$("#####.###",Schleifenzeit)
    ...you mispelled USING$. And in the lines:

    Code:
        Anzeit  = ROUND(Laenge / Schleifenzeit,0)
        Auszeit = ROUND(10000  / Schleifenzeit,0)
    ...you didn't tell PB how many digits to round. When compiled as I edited it. I received output from the program:

    Cyclusduur = -64.747æs
    Cyclusduur = -63.754æs
    Cyclusduur = -63.815æs
    Cyclusduur = -63.061æs
    Cyclusduur = -62.660æs

    ...I don't know what it all means but I hope I was able to help in some small way.

    ------------------
    Don Ewald
    mailto:[email protected][email protected]</A>
    Donnie Ewald
    [email protected]

    Comment


    • #3
      Hey Don,

      Thanks for your help
      This program is an drive for servomotors.

      Can you programming an formatted input and output for PowerBasic?
      I give you then the details

      Greetz
      Stephane


      ------------------
      ICQ: 123632482

      Comment


      • #4
        Hey Don,

        I corrected my code but I can’t compile it to my main program. The error 462 declarations of so.
        What do I fault, can you send my the corrected Ports16.bas + Servo.bas and the EXE-cute file to email then can I study what I do wrong.
        Is that possible an include file?

        ‘==========================================================================='
        ' Unit Read and Write the PC Ports in DOS '
        '==========================================================================='
        $ERROR ALL ON
        $COMPILE UNIT "PORTS16.PBU"

        'Return an byte from the specific port
        DECLARE FUNCTION InportB(BYVAL PortAddress AS WORD) AS BYTE

        'Return an word from the specific port
        DECLARE FUNCTION InportW(BYVAL PortAddress AS WORD) AS WORD

        'Write an byte to the specific port
        DECLARE SUB OutportB(BYVAL PortAddress AS WORD, BYVAL Value AS BYTE)

        'Write an word to the specific port
        DECLARE SUB OutportW(BYVAL PortAddress AS WORD, BYVAL Value AS WORD)

        SUB OutportB(BYVAL PortAddress AS WORD, BYVAL value AS BYTE) PUBLIC
        ASM mov AX, value
        ASM mov DX, PortAddress
        ASM out DX, AL
        END SUB

        FUNCTION InportB(BYVAL PortAddress AS WORD) PUBLIC AS BYTE
        ASM mov DX, PortAddress
        ASM IN AL, DX
        ASM mov FUNCTION[0], AL
        END FUNCTION

        SUB OutportW(BYVAL PortAddress AS WORD, BYVAL value AS WORD) PUBLIC
        ASM mov AX, value
        ASM mov DX, PortAddress
        ASM out DX, AX
        END SUB

        FUNCTION InportW(BYVAL PortAddress AS WORD) PUBLIC AS WORD
        ASM mov DX, PortAddress
        ASM IN AX, DX
        ASM mov FUNCTION[0], AX
        END FUNCTION

        ‘ =============================================================================================’
        ‘ Include file from the Unit : Ports16.INC ‘
        ‘==============================================================================================’

        'Return an byte from the specific port
        DECLARE FUNCTION InportB(BYVAL PortAddress AS WORD) AS BYTE

        'Return an word from the specific port
        DECLARE FUNCTION InportW(BYVAL PortAddress AS WORD) AS WORD

        'Write an byte to the specific port
        DECLARE SUB OutportB(BYVAL PortAddress AS WORD, BYVAL Value AS BYTE)

        'Write an word to the specific port
        DECLARE SUB OutportW(BYVAL PortAddress AS WORD, BYVAL Value AS WORD)

        '==========================================================================="
        ' Programma : Servobesturing "
        ' Copyright : Brainsoft Programmers 2001 "
        '==========================================================================="

        '======================================="
        ' Hoofdprogramma "
        '======================================="

        $COMPILE UNIT "E:\PB35\PB-PBU\PORTS16.PBU"
        DECLARE SUB Test( )
        DECLARE SUB Impulsgenerator(BYVAL Laenge AS INTEGER)
        DECLARE SUB Steuerung( )

        %BA = &H3F8

        DIM Schleifenzeit AS SHARED SINGLE
        DIM Ch AS STRING * 1

        'Begin
        CALL Test
        DO
        CALL Steuerung
        LOOP UNTIL INSTAT
        END

        '======================================="
        ' procedure test "
        '======================================="
        SUB Test

        DIM High AS BYTE
        DIM Low AS BYTE
        DIM m AS WORD
        DIM FmtStr AS STRING

        $INLINE &HFA 'CLI, interrupt blokkeren
        OutportB &H43, &H34 'Timer 0, Mode 2
        OutportB &H40, &H00 'Timer 0, low reset
        OutportB &H40, &H00 'Timer 0, high reset
        FOR m = 1 TO 1000 : NEXT m 'tijdmeting
        OutportB &H43, &H04 'Timer 0, bevriezen
        Low = InportB(&H40) 'Timer 0, uitlezen
        High = InportB(&H40)
        $INLINE &HFB 'STI, interrupt vrijgeven
        Schleifenzeit = -(Low + 256 * High) / 1000
        FmtStr = USING$("#####.###",Schleifenzeit)
        PRINT "Cyclusduur = " + FmtStr + "æs";
        PRINT
        END SUB

        SUB Impulsgenerator(BYVAL Laenge AS INTEGER)
        DIM Anzeit AS WORD
        DIM Auszeit AS WORD
        DIM Anzahl AS WORD
        DIM m AS WORD

        Anzeit = ROUND(Laenge / Schleifenzeit,3)
        Auszeit = ROUND(10000 / Schleifenzeit,3)
        $INLINE &HFA
        FOR Anzahl = 1 TO 50
        OutPortB %BA + 4, 1 'DTR Aan
        FOR m = 1 TO Anzeit : NEXT m 'Impulstijd
        OutportB %BA + 4, 0 'DTR uit
        FOR m = 1 TO Auszeit : NEXT m 'Pauze
        NEXT Anzahl
        $INLINE &HFB
        END SUB

        SUB Steuerung
        DIM n AS INTEGER

        FOR n = 1 TO 10
        CALL Impulsgenerator(1000 + n * 100)
        NEXT
        END SUB

        Greetz
        Stephane


        ------------------
        ICQ: 123632482

        Comment


        • #5
          Sure, I'll email it to you shortly.

          ------------------
          Don Ewald
          mailto:[email protected][email protected]</A>
          Donnie Ewald
          [email protected]

          Comment


          • #6
            Don,

            Thank you in advance !

            Ps: In what langeage programming you?
            Wich compilers from PowerBasic have you experince?



            ------------------
            ICQ: 123632482

            Comment


            • #7
              Greetings Stephane!

              I've decent experience in QuickBasic 4.5 and PDS 7.1. I've then ported most of that code to PowerBASIC 3.5 for DOS. I've recently purchased PowerBASIC CC and I've no experience with it yet.


              ------------------
              Don Ewald
              mailto:[email protected][email protected]</A>
              Donnie Ewald
              [email protected]

              Comment


              • #8
                Hey Don,

                In PBDOS is that okay !
                You have earlier an project PBE is that true?

                Kind regards
                STEPHANE


                ------------------
                ICQ: 123632482

                Comment

                Working...
                X