Hello,
Probably the "rare" character is a "control character" like a "carriage return" that you can probably simply ignore in this case. Since you can control what the Arduino device send, probably you need to setup a "protocol" between your publication and the Arduino device. What you can doing is to send the string with the suffix "#", for example. So you can send an string like this: "Hello!#".
Then, into the "npOnCompRxChar", you can add to the "buffer" variable every arrived characters, except the "carriage return", and until the "#" is reached. So you can write a code like this in the refered event:
- Code: Select all
:OnCompRxChar
.Read the received chars from the input
npCompReadString "[CompID]" "[Count]" "[Result]"
.Trim the received chars
npTrimStr "[Result]" "[ReceivedChars]"
.Skip control characters
If "[ReceivedChars]" "<>" ""
.Look for the end of our transmitted string
SearchStr "#" "[ReceivedChars]" "[EndTokenPosition]" ""
If "[EndTokenPosition]" "<>" "0"
.Get the received chars before the end token is found
SubStr "[ReceivedChars]" "0" "[EndTokenPosition]" "[EndTokenPosition]"
.Fill our Input buffer variable
SetVar "[InputBuffer]" "[ReceivedChars]"
.Here our Input buffer variable contains the transmitted string,
.so we can do whatever thing we need at this point, for example,
.call a subroutine to make something with the Input buffer.
GoSub "ProcessInputBuffer"
EndIf
.Fill our Input buffer variable
SetVar "[InputBuffer]" "[ReceivedChars]"
EndIf
Return
As you can see I use the
"npTrimStr" action from my
npUtil plugin in order to try to remove the possible control characters. I am not sure if the code can works as is, since I can't test it, but the idea is this:
1º Work with certain Input variable to be filled with the received chars
2º Fill the Input variable with all received chars EXCEPT "empty" chars like control characters
3º Take care if the received chars contains our "end of transmission" token ("#" in this case)
4º When the "EOT" token appear, do something with the Input buffer variable
If "Trim" the received chars don't work, maybe you can try to search for "carriage returns" and other possible control characters using some string related functions and the appropiate NeoBook variables like "[#13]". This variable is the ASCII for "carriage return", then, if the received chararacters contains such variable you can replace it by a empty string in order to skip it.
This appear difficult but I think it's more simple than I can explain. However, maybe Arduino provide a way in order to send complete strings, for example. Maybe another mate with experience in that hardware can help us in this case.