News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

hrsout and hrsin help

Started by krizpin, Jul 28, 2023, 08:29 AM

Previous topic - Next topic

krizpin

hello, everyone.
I have a problem with hrsout and hrsin .
I need to send the following data through the serial port
hrsout "Main.n4.val=",dec 56
This data needs to be read through an interrupt in another pic with hrsin. The problem I have is that if I send them that way and try to read them with
         for x = 0 to 90
            hrsin {550, input_buffer}, buffer_rs485

            Next
it only receives the integer values but not the string string . I have tried a thousand ways and I cannot receive the data correctly because in one of the tests what it does is receive the integer value "56" in 2 different bytes.
  Can you give me a hand? thank you


------------------------

The only way I've found to make it work is:
hrsout "main=",56

and in the slave pic:
         for x = 0 to 90
            hrsin {550, input_buffer}, buffer_rs485

            Next

because if I write:
         for x = 0 to 90
            hrsin {550,input_buffer},dec buffer_rs485

            Next
then you get nothing.
The problem of doing it this way is that when I connect the terminal in proteus, what I see in the terminal is the text on one side and the entire value I see as an ascii code.

RGV250

QuoteI could send text and data separately but I don't know how to identify one or the other at the reception
This is not my strong point but are you constantly sending or is there a gap between messages, if so the receiving end would know the first is text and the second is data, also what about the length of the messages, could you use that to validate?
I have done something in the past where I used a special character that will never otherwise be sent such as ! or * as the first character for the receiving end to decide how to process.

Bob

Dompie

#2
You may need to use the VAL function to convert the received ASCII string to integer (manual page 373).

Syntax Val
Assignment Variable = Val (Array Variable, Modifier)
Overview
Convert a Byte Array or String containing Decimal, Hex, or Binary numeric text into its integer
equivalent.

Johan

For a good example from @top204 see here

krizpin

Thanks for your help. I Will see the command and try it