Serial Interface Question

Hello,

I’m a beginner with Xojo and I would like to ask a question about serial interface. I have an Arduino connected as a serial device to a comm port in the Xojo app(Windows). It works Ok and I can read characters in output area. I added \r
in Arduino serial.write char code. In Serial \ Data available I have :
If InStr(Me.LookAhead(Encodings.ASCII), Chr(10) + Chr(13)) > 0 Then
OutputArea.Text = OutputArea.Text + Me.ReadAll(Encodings.ASCII) End If

                             I want to trigger certain character events from the OutputArea  such as " read this character and push that button "

                                                                                                        If OutputArea.Text = "c" Then
                                                                                                       call GoToGmail.Push
                                                                                                       End If

Is this possible? (Before I pull my hair out?) I can’t make it work. I tried with event handlers and no luck so far. This is just a desktop remote control for “lazy mode” :). Push a button and launch a website page or login into your email…or do other tasks.

Thank you

Hi Val,

the question is not seemingly about the serial interface, from what you say the serial part is working perfectly, you are getting the data into the OutputArea.

but a suggestion is not to directly use the OutputArea.Text to test for the character “c”.
in DataAvailable you should Me.ReadAll into a PROPERTY of the project, such as ‘received_data’.
you would then test this property for the wanted character “c”, display the data in the property if you wish, but in reality you do not need to see it for the data to work, seeing ASCII data can be extremely deceiving, the data received may not actually be what you expect, what you see is the ASCII character and not all the data that is sent.

my suspicion is that the data you have from ReadAll is actually 3 characters (at least).
you are using LookAhead to search for end of line and line feed (perfect thing to do, I use this in my main projects too), when those characters are placed in a text area you will not see them, which is one good reason not to use the textfield to search for the wanted “c” character.

if I am reading correctly the very small code sample you supplied the OutputArea will actually contain “c”+Chr(10) + Chr(13)
and your test in the ‘if’ statement for “c” can never be true, the characters Chr(10) + Chr(13) are also there but not visible to you but are visible to the ‘if’ statement.

I would suggest checking the received data for ‘Len’ of 3 and then test the 3 characters in a loop for the expected characters, if you find all the expected characters, the “c” and Chr(10) + Chr(13) then you can say that the received data is correct (presuming whatever is sending the data is only sending those characters).

as with any type of data received by the computer it must be tested for being valid, there are many ways the data can be corrupted and what you expect to get might not be what you actually receive, DO NOT use a high baud rate when debugging, keep it at 19200 baud so you reduce the risks of data loss due to poor hardware (a very likely probability).

use the debugger to look at the actual data in your received data, this is easier if you use a local variable (rather than a PROPERTY) in the DataAvailable event (dim local_data as string, then use local_data=Me.ReadAll), the debugger is not all that obvious to use, it does not make it simple to see variables, especially if you are new to the IDE, a local variable is immediately visible when the debugger stops, as it should be with any in view.

so to answer your question, yes its very possible, and not really hard at all, but there is a lot more to your simple need than might at first be obvious.

I hope that helps a little.

Mark

Thank you Mark