I'm struggling with text coming from an arduino over bluetooth. I'm working on what should be a simple BT interface to an arduino sketch that's been around for a while and isn't my creation. I don't have the option of making changes to it.
I'm trying to place the text that comes in response to a command sent to the arduino into a label. An example is that by sending the text :00# to the arduino it responds with the position of a stepper motor in the format P1234# where P is the beginning of the string, # is the end, and 1234 is the position. The position can be anything from 1 to 2000000 so the number of digits can vary from 1 to 6. Always starting with the P and ending with the #.
In order for the counter to not lose track of its position I perform a check to see if the motor is currently stepping before telling it to move. Right now I just have a test label for that response. By sending :01# to the arduino it responds with I01# (that's a capital "I") if the motor is currently moving, and I00# if it is not. This should be easier since the response will be one of two options but it isn't working out that way.
What's happening is I'm getting half the step position string in the "is moving" label, and sometimes parts of the "is moving" response is showing up in the position label. I can't find a way to reliably grab everything between the P and # and put it in the position label, or a way to positively identify IXX# as the response to the :01# command.
The bluetooth connection is stable and movement commands sent to arduino are executed reliably, although I'm looking at the motor to see if it's already moving before sending the command instead of checking the status via bluetooth.
Any advice would be greatly appreciated. The two sections giving me fits are below. I don't think that's the correct use of the "contains text piece" block but documentation and examples of it are scarce.