How to include Method

I am using my serial program. I connect the device to my PC and the PC recognizes it as COM. So far my program works very well.

I am using my serial program. I connect the device to my PC and the PC recognizes it as COM. So far my program works very well. Here I leave the photo of the program.

Now when I click on SEND (Actuator1) I open a second window and I see the 4 ON buttons inserted to send commands to the serial port. How can I send the commands on the serial from the second page without choosing the COM? Should I use methods, how are they used?

You can try to abstract the access to your COM. Make a class that handles the COM. Give information to the window, then you can also have your basic class talk to the second window. You can google the MVP pattern.

How to use this MVP pattern?

i guess u will just access your serialconnection object in the first window.

you could add a property in your second window to memory the first window. (dependency injection)

Public Property MainWindow as Window1

from second window you can access the serial object like this

MainWindow.SerialConnection1.Write

in the main window you open the second window like this

Var w As New Window2 w.MainWindow = Self w.Show

in the same way you can also call public methods in main form.

if you would use a class with this serialconnection u need to register this events to methods, see AddHandler
for recurring ui elements you can use a container control.

Hi @Markus Rauch, I add the Property in the second window with “Public Property MainWindow as Window1”. This “MainWindow.SerialConnection1.Write” where should I put it?

in the window 2 from where you will send data via serial port.
at button action as example.

@Markus Rauch I insert this(Var w As New Window2
w.MainWindow = Self
w.Show) when I click on the button and open the second window. I see same errors, Var not defined and the same of w. Why?

Var is a alternate key word for Dim if you use xojo 3.1, for older xojo use Dim
for Window1 and Window2 you must write your windows names.

  1. I added this property to window2:
Public Property MainWindow as Window1
  1. When I click a button for to send a command on the serial I use this:

If Self.flag Then app.SleepCurrentThread(100) flag = False Serial1.Write("#011") TextArea10.Text = "" Else app.SleepCurrentThread(100) flag = True Serial1.Write("#010") TextArea10.Text = "" End If

Where do I put this? MainWindow.SerialConnection1.Write

  1. To Show a second window, I insert in PushButton this:

Var w As New Window2 w.MainWindow = Self w.Show

It’s correct all this?

This is my errors:

one way or another

Var w As New Window2 w.MainWindow = Self w.Show

Dim w As New Window2 w.MainWindow = Self w.Show

if this is in window 1

If Self.flag Then app.SleepCurrentThread(100) flag = False Serial1.Write("#011") TextArea10.Text = "" Else app.SleepCurrentThread(100) flag = True Serial1.Write("#010") TextArea10.Text = "" End If

from window2 it would look

app.SleepCurrentThread(100)
If MainWindow.flag Then
  MainWindow.flag = False
  MainWindow.Serial1.Write("#011")
Else
  MainWindow.flag = True
  MainWindow.Serial1.Write("#010")
End If
MainWindow.TextArea10.Text = ""

[quote=477604:@Mario Castaldo]This is my errors:
[/quote]
seems your property MainWindow is type integer but its a window, you need use the name from your window in this first screenshot at top in the textbox Type

Ok, I send the first command but the second not send.

use System.DebugLog("…") and output all you send

you can also use break points and step through

My ON / OFF keys are Canvas. I send the command ON but I cannot send the command OFF. I am using the MouseDown function to send the command and the Paint function to switch from one key to another. Do I have to change anything other than what you told me?

you can subclass a canvas and then you can add a (computed) property there.
repaint can done with .invalidate(false)
so in the next paint event you can paint the icon matching a status.
in your “own” canvas you can define events and raise events.

Ok, I send the command and it works. This is my second page :

When I click on ON, I receive a command. This command I see on Window1 and not on Windows2. Why?

[quote=477615:@Mario Castaldo]Ok, I send the command and it works. This is my second page :

When I click on ON, I receive a command. This command I see on Window1 and not on Windows2. Why?[/quote]

you have a copy of this on buttons on window1 but you will switch it in window 2?
can you show a screenshot with both windows?

I had it before, now I have everything in the window2. But the receipt of the command appears to me in the TextArea of window1 and not of window2

i think because your event handler for DataReceived in window1 get this data