News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

HRSOUT Str byte array - review

Started by kuhrig, Jan 15, 2025, 11:44 AM

Previous topic - Next topic

kuhrig

Hi Les, hope you are doing well and thank you for all your work and support.

Please review following. According to your manual the "HRSOut Str byteArray"   should transmit all bytes of the array.
"Str array\n Send all or part of an array"
Because my 18 byte array is filled differently all the time, the number of bytes being sent are different which brings my communication out of order.

Thank you.
Kai
   

Proton 4.0.5.1
------------------------
Device = 16F18877
Dim  abTEXT [18] as byte
Str abTEXT = "AGM"
HRSOut Str abTEXT             ->  it does not send all 18 bytes. Only 3 bytes and some garbage byte
HRSOut Str abTEXT\18            ->  even forced to send 18 bytes it does not send all 18 bytes. Only 3 bytes and some garbage byte

Str abTEXT = "ABCDEFGHIJKLMNOPQR"     
HRSOut Str abTEXT                -> ALL 18 bytes are being sent correctly

Str abTEXT = "AGM"
abTEXT [17] = 111    ' tried to fill last byte with some value
HRSOut Str abTEXT             ->  it does not send all 18 bytes. Only 3 bytes and some garbage byte






JohnB

If you want to send the whole array then you should not use the Str modifier.
from the manual:
QuoteNote that we use the optional \n argument of Str. If we didn't specify this, the PICmicro™ would
try to keep sending characters until all 10 bytes of the array were transmitted. Since we do not
wish all 10 bytes to be transmitted, we chose to tell it explicitly to only send the first 5 bytes.
JohnB

kuhrig

Exactly that's what I want. I want all bytes to be transmitted.
But it does not transmit all bytes!

JohnB

As per my previous post

Str makes the array a string, strings get terminated with a 0

HrsOut abText\18
JohnB

kuhrig

Thanks John.
Tried it. Outputs an error during compiling.  (shortend my array to 16)
    hrsout abtext\16
 "Error at Line [1321] *** Square opening bracket '[' missing! ***"

I understand StrN get's terminated with a zero only.
And "HRSOut Str byteArray" I understand that the whole array will be transmitted.

trastikata

QuoteHRSOut Str abTEXT             ->  it does not send all 18 bytes. Only 3 bytes and some garbage byte
HRSOut Str abTEXT\18            ->  even forced to send 18 bytes it does not send all 18 bytes. Only 3 bytes and some garbage byte

How do you check what is being received? Sorry if this sounds obvious, but if you are looking in a terminal program in ASCII mode, the remaining 0-bytes from the array might not appear there.

kuhrig

I check it with PIC to PIC comms. And with an oscilloscope.

With "HRSout Str ByteArray" it only sends the array until it detects a 0-byte.
As I am sending more bytes after that array, my received data is garbage. Only the sent non-0-bytes are correctly received.
As described at the top. If I fill the complete array with non-0-bytes, all bytes are being sent and correctly received.

(shortend my array to 16)
My workaround which works:
Dim bIDX as byte
For bIDX = 0 to 15
  HRSout abTEXT [bIDX]
Next
On the other side of the comms (PIC16F887A):
HRSin Str abTEXT

trastikata

#7
QuoteWith "HRSout Str ByteArray" it only sends the array until it detects a 0-byte.

I think this is by design when using a Str modifier and the n-parameter allows you to send less than a full string but no more than a full string. This is at least what I found analyzing the Assembler code.

As you already discovered using a loop and sending individual elements of the array will do the job.

HRS.jpg

See_Mos

As explained above by trastikata this simply because a value 0f 0 is ASCII for a null terminator so Positron stops sending string bytes after sending the first null byte and that is why sending the characters as decimal or hex byte values works but not with string values

John Lawton

I don't know your application, but if you want the whole string to be output each time then you should prevent a null (zero) value anywhere in the string. Conventionally a space (32) might be used for this purpose.

John

kuhrig

OK. Thanks for your explanations.
The Str modifier only sends the String until a zero byte, that is the explanation.
In opposite the manual explains:
QuoteStr array\n Send all or part of an array
Note that we use the optional \n argument of Str. If we didn't specify this, the PICmicro™ would
try to keep sending characters until all 10 bytes of the array were transmitted. Since we do not
wish all 10 bytes to be transmitted, we chose to tell it explicitly to only send the first 5 bytes.

I have not used the modifier before and I was convinced it will send all bytes of the array as stated in the manual.

But if the Str modifier with HRSout only sends the bytes until a zero byte, I realized that the HRSin with Str modifier is waiting for ALL bytes of the array.
HRSout and HRSin behave different with the same Str modifier.
By chance or intentional?




top204

The Str modifier will terminate when it sees an integer 0 in the bytes.

Its use was to imitate a String variable when they were not available in the compiler, and a String is null terminated.

I'll get into the compiler's source code and see if I can make it not null terminate if all the array's elements are to be sent.