Menu

AVR Mega 328P Problem using: Val32( ) and StringToLong( )

Andye
2024-09-01
2024-09-02
  • Andye

    Andye - 2024-09-01

    Hi,
    Please help with this code. It does not compile and throws this Error:
    Pointer mismatch: Cannot handle variable construct. Please check syntax...

    '''GCBASIC Program.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''Description:  [todo]
    '''
    '''@author     [todo]
    '''@licence    GPL
    '''@version    [todo]
    '''@date       [todo]
    '''********************************************************************************
    
    #chip mega328p , 16
    
    '''----- Includes
    '''----- Configuration
    '''----- Define Hardware settings
     'USART settings for USART1
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    
    '''----- Variables
    Dim ML AS Long
    DIM Pulse as Long
    DIM LongVar as Long
    Dim Text as String
    
    '''----- Interrupts
    
    '''----- Main body of program
    Do
        HSerGetString Text    ' Get Number from usart 1
        HserPrint Text        ' Send out TEXT TO usart 1
        HSerSend(13)          ' Send New Line TO usart 1
    
        LongVar = Val32(Text) 'Error: Pointer mismatch:  Cannot handle variable construct.
    
        LongVar = StringToLong( Text ) 'Error: Pointer mismatch:  Cannot handle variable construct.
    
        HserPrint LongVar         ' send out usart 1
        HSerSend(13)
        wait 100 ms
    loop
    
    '''----- Subroutines
        Function Pulses_To_Ml (Pulses as Long)
            ML = (Pulses * 1000) / 45454
        end function
    
    '''----- Lookup Tables
    

    I don't know why it does not work.

    Regards
    Andye

    ~~~

     
  • Anobium

    Anobium - 2024-09-01

    My error. Sorry, introduced on 26062024 by me on change 1648.

    I add a string constraint to the function.

    You can correct, test and let know the result is good.

    Edit gcbasic\include\lowlevel\string.h line 403 change

    from

    Function StringToLong(SysInString as String * 14 ) as Long
    

    to remove the string constraint.

    Function StringToLong(SysInString as String ) as Long
    

    Looking on the bright side.. the error message meant something to me... Sorry.

     
  • Andye

    Andye - 2024-09-02

    Thank you Anobium. The problem is fixed.
    Here is my working code example:

    #chip mega328p , 16       ' Arduino UNO Board
    
    '''----- Includes
    
    '''----- Configuration
    
    '''----- Define Hardware settings
     'USART settings for USART1
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    
    '''----- Variables
    Dim ML AS Long          ' Ml Mili-Liters
    DIM Pulses as Long      ' Ammount of Pulses Oil-Pump
    Dim Text as String      ' Temp Variable
    
    '''----- Interrupts
    
    '''----- Main body of program
    Do
        HSerGetString Text    ' Get Pulses Number from usart 1
        Hserprint "Input = "   
        HserPrintStringCRLF   Text  ' Send out Pulses Number TO usart 1
    
        Pulses = Val32(Text)  ' Convert Text to LONG Variable
    
        HserPrint "Result = "  
        HserPrint Pulses_To_mL (Pulses)           ' Output Result to usart 1
        HserPrintStringCRLF " mL"  
    
        wait 100 ms
    loop
    
    '''----- Subroutines
        ' Vevor Diesel Heater Pulse Pump: 1000 Pulses = 22mL heating oil:
        ' Examples 50000  Pulses = 1,1 L
        '          909080 Pulses = 20 L
        '          454540 Pulses = 10 L
        '          45454  Pulses = 1 L
        '          227270 Pulses = 5 L
        Function Pulses_To_mL (Pulses as Long) as long
            Pulses_To_mL = (Pulses * 1000) / 45454
        end function
    
     
  • Anobium

    Anobium - 2024-09-02

    Excellent! Thanks for reporting back!

    I will release the fix.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.