News:

;) This forum is the property of Proton software developers

Main Menu

Issue with passing strings to a Procedure

Started by JohnB, Jun 11, 2022, 11:40 AM

Previous topic - Next topic

JohnB

I put this up on an earlier question but it was off topic for the subject to I am resubmitting it in a new post.

$define NxtStnEnd "ÿÿÿ"    ',255,255,255

dim s as string*48
proc HMI_SendString(CompName As String * 8, Message As String * 32)
  s = CompName + ".txt=" + Message + "ÿÿÿ"
  HserOut2 [s]
EndProc

I call the procedure like this

  HMI_SendString("lblMsg", "RTC OK")
After making this call everything just stops including my keep alive loop so I guess it is not returning from the procedure;

If I send the same message directly it work correctly:

HserOut2["lblMsg.txt=RTCOKÿÿÿ"] and I get my message up on the HMI display

Am I doing something wrong or is there an issue here?



JohnB

top204

#1
I've tried your code and it works OK:

    Device = 18F25K20
    Declare Xtal = 16
'
' Setup USART1
'   
    Declare Hserial_Baud = 9600
    Declare HRSOut1_Pin = PORTC.6

    Dim s As String * 48
   
'--------------------------------------------------------------------
' The main program starts here
'
Main:
    HMI_SendString("lblMsg", "RTC OK")
    HSerOut ["\rContinuing"]
  
Proc HMI_SendString(CompName As String * 8, Message As String * 32)
    s = CompName + ".txt=" + Message + "ÿÿÿ"
    HSerOut [s]
EndProc

I get the following texts on the serial terminal:

lblMsg.txt=RTC OKÿÿÿ
Continuing


I added the "Continuing" text, to make sure it was following on from the procedure call.

And if I change it to use the $define to hold the ending "ÿÿÿ" character string, it still works fine:

    Device = 18F25K20
    Declare Xtal = 16
'
' Setup USART1
'   
    Declare Hserial_Baud = 9600
    Declare HRSOut1_Pin = PORTC.6

$define NxtStnEnd "ÿÿÿ"
    Dim s As String * 48
   
'--------------------------------------------------------------------
' The main program starts here
'
Main:
    HMI_SendString("lblMsg", "RTC OK")
    HSerOut ["\rContinuing"]

Proc HMI_SendString(CompName As String * 8, Message As String * 32)
    s = CompName + ".txt=" + Message + NxtStnEnd
    HSerOut [s]
EndProc

I still get the texts:

lblMsg.txt=RTC OKÿÿÿ
Continuing


The compiler creates the same assembler code for all 18F devices for String handling, so it does not matter what 18F device is being used for your program, if it operates on one 18F device it will operate on them all. Do you have anything running in the background of the program. i.e. interrupts? If so, make sure the ISR handler is context saving/restoring any SFRs used in the interrupt handler.

I also tried the code on an enhanced 14-bit core device and it worked OK.

JohnB

It was my fault, I had misread the command syntax of the HMI, the command requires that Text itself should be surrounded by double quote. 

E.g. lblMsg.txt="RTC OK"ÿÿÿ

So I have rewritten the procedure as follows:
proc HMI_SendString(Object As String * 8, Message As String * 32)
  s = Object+".txt="+$22+Message+$22+NxtStnEnd
  HserOut2 [s]
EndProc
I used the ASCII code for defining double quote to avoid the message from being shown as a String

Thanks for your help.

I am now struggling with I2C but I will leave that for another topic.
JohnB