Shop OBEX P1 Docs P2 Docs Learn Events
The Serial Receive block in Blockly is interpreting a space character as a NULL character — Parallax Forums

The Serial Receive block in Blockly is interpreting a space character as a NULL character

AutomaxionAutomaxion Posts: 26
edited 2020-10-01 10:37 in General Discussion
I have a program where I am trying to read values sent continuously by a balance that are in the format (sign)(3 spaces)(0.0000)(space)(g). The balance output is terminated by CR LF. When outputting zero, the sign is replaced by a space. This has been confirmed using a terminal program which also shows that sometimes the g is not appended or read (I can live without the 'g').

When using the code generated in Blockly, only '+' or '-' or '0.0000' is being displayed. Where there is a sign, then this is read but anything else after is not read. Without the sign, the leading spaces do not affect the reading of the data but are not included as text which makes extracting the text needed by position, difficult.

I interpret this as meaning that the spaces following any text are being interpreted as NULL characters and stopping text being read in.

See https://github.com/parallaxinc/solo/issues/515

Comments

  • I guess nothing is happening.
  • Automaxion wrote: »
    I guess nothing is happening.

    As per the reply from tech support, the outstanding GitHub issues will be worked through during December and January.

    An option to disable the null character will be added. There are a lot of underlying things to be fixed first to resolve compatibility issues with various Chrome updates/etc.. etc.., but the serial improvement is fairly high on the list once the ground work is completed.

    It is happening. Apologies that it's not happening as fast as you need.
  • Cluso99Cluso99 Posts: 18,069
    I don’t know Blockley, but is there a single character read that you can use repeatedly to assemble the string while using <lf> as the terminator? If so, you could make a little subroutine.
  • Cluso99 wrote: »
    I don’t know Blockley, but is there a single character read that you can use repeatedly to assemble the string while using <lf> as the terminator? If so, you could make a little subroutine.

    Thanks for the suggestion but unfortunately I do not know how to do this and in any case, I don't think there is a single character read in BlocklyProp Solo.

    The other problem is more practical: the manufacturers loaned me balances but I can't keep them here if I am not trying things (while the bug is not corrected in BlocklyProp) so they have been returned which means I can't try any suggestions outside of BlocklyProp. I can't justify getting them back on the chance something will work. Catch 22.
  • Yes, this is the solution. Apparently, the block I was using is, as designed. Basically it is a bastardised version of a C command, without the option of setting several parameters including how to react to a NULL character.


  • Well,it seems as though there are no plans to update this block in the immediate future, per this quote. Rather I have to use the single character read block :-(

  • VonSzarvasVonSzarvas Posts: 3,488
    edited 2021-01-28 12:42


    I've just messaged the web team to find out what's happening.


    The last update I had from them was this : Release 1.5.7 is just the next release of the project. It will contain some bug fixes and new under-the-hood tooling. The release is due on January 27th but it is likely that we will release earlier than that if bug fixing goes well.

  • The Serial Read block text mode is operating correctly. It parses a string and stops when it encounters 'white space', which is defined as the space character, carriage return, or line feed. The block was not designed to accept a formatting string because the underlying library the block relies on does not accept a formatting string. And the library was designed to run in a microcontroller with limited available memory. Some features just would not fit in the finite RAM available. The compound format string was one of those features. There are other read modes available in the Serial Read block that support single character reads, decimal and hexadecimal reads, and binary number reads.


    A solution to this limitation is to read the characters, one at a time, from the device and handle the line termination in your code instead of relying on the block to perform this task. This was identified in the GitHub issue and by another forum member earlier in this thread. This is supported in the Serial Read block by setting the block to read ASCII characters.

  • With help from MatzElectronics, the attached program works well with a Sartorius balance. By leaving this here, I hope others might find it useful while the other block is improved.

Sign In or Register to comment.