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.
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?
@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?
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
To Show a second window, I insert in PushButton 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
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
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.