Report Bugs Here

Moderator: Mmiscool

User avatar
By Electroguard
#63068 I was referring to online serial port docs which says that full serial2 is available, but it seems that serial2.read.int() returns an error so apparently is not supported. Doesn't prevent you from trying to read serial2 into a pre-declared int variable though (without $), it will either be read as numeric or not.

It all depends on what data is being sent to serial2, and what you are trying to accomplish with it.

If you have a look at the ascii table that mmiscool has helpfully included at the bottom of the online docs, you'll see that all the numbers from 0 to 31 are translated as control codes (which do not display), eg: number 13 causes a carraige return when 'printed' to screen.

You'll notice that ascii 0 (zero) is interpreted as NULL, whereas the printable ascii character "0" is represented by the decimal number 48.

So you can see that if you want to display incoming numeric digits (eg: for dev and debugging purposes) you can add 48 to each serial digit to turn it into it's printable ascii equivalent - but bear in mind that non-separated consecutive digits (such as 32) would originally comprise a multiple digit decimal (or hex) number.
User avatar
By marcomart
#63385 Hello!!!

The same is happening with chr(0) when I compose a string, 0 is the the end of the string character so if
you compose a string to send to a device everything after 0 will be truncated.

Example:

bla = chr(1) & chr(2) & chr(0) chr(3) & chr(4) & chr(5)

so bla will contain only up to chr(2) the rest ( chr(0) chr(3) & chr(4) & chr(5) ) will be truncated, I was suspected this and seems that you confirmed as well that is happening, in some applications is quite vital
send also chr(0) ,in arduino I see that this is treat as null string , this is a big issue!!!

Please see yhe post above STRING COMPARISON

Marco.
User avatar
By Electroguard
#63412 Yes, the Arduino also uses serial byte zero to signify end of transmission - but if it has to use something then there isn't really any other more appropriate number available to use, is there.

That is why I have suggested that if you have control of what data is being sent and you need to send zero, you could send your numbers as text then convert them from text back to numbers after they are received.

But that is NOT what you are doing by sending eg: chr(0), because that is still sending a numeric byte of zero which will still be interpreted as the end of transmission character.

You would need to send the ascii text character for "0" which is actually chr(48), then deduct 48 from the received ascii value to end up with the required numeric zero. So your example should have been bla = "120345"
After the serial text is received, you can step through each received ascii digit and convert it to it's equivalent numeric value.
User avatar
By marcomart
#63419 Yes I know that but with modbus rtu I' m forced to send raw byte , and thus also 0, that's why.
Sending string isn't a problem, by the way in a string composition the character from 1 to 255 are working the
only problem is the 0 that will truncate the string
I have to try to put the string character by character inside an array, we will see. By the way with serial port everything should work fine.

Thank You.
Marco.