INTERFACE AND APPLICATION PROGRAMMING
- Interpret and implement design and programming protocols to create a Graphic User Interface (GUI).
for using NETWORKING AND COMMUNICATION it would be interesting to design a simple interface that send serial data and receive the data from hardware networks. To do so I used Microsoft Visual Studio. now within the designing process i used comercial arduino for deburgging and after i migrate to my board to see the result
GUI Proposal Schetchup
After schetcking the layout i want for my interface i started to create the same layout in visual studio design tab and after customizing everything due to they way i wish i started to give every button, textbox,tab,... the way it have to behave by switching from design to embedded section where i have to write all logics, functions variable and declaration.
convert icon website
which is free to use and it have the all default size of the icon no thing to worry about just import png file then extract *.ico file directlyImports System.IO
Public Class Form1
Dim WithEvents serialPort As New IO.Ports.SerialPort
Dim baudRate As Integer
Dim state As Boolean = False
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
'grab defaut baudRate setted
baudRate = CInt(cmbBaurdRate.Text)
For Each portName As String In My.Computer.Ports.SerialPortNames
cmbPort.Items.Add(portName)
Next
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Try
If serialPort.IsOpen Then
sendCharacter(txtSend.Text)
clear()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub sendCharacter(ByRef data As String)
serialPort.Write(data)
End Sub
Sub connectPort()
Try
If state = False Then
serialPort.BaudRate = baudRate
serialPort.PortName = cmbPort.Text
serialPort.Open()
cmbPort.Enabled = False
state = True
btnConnect.Text = "Disconnect"
Else
serialPort.Close()
cmbPort.Enabled = True
state = False
btnConnect.Text = "Connect"
Timer1.Enabled = False
End If
Catch ex As Exception
serialPort.Close()
MsgBox(ex.Message)
End Try
End Sub
Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged
End Sub
Private Sub cmbBaurdRate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBaurdRate.SelectedIndexChanged
baudRate = CInt(cmbBaurdRate.SelectedItem)
End Sub
Delegate Sub myMethodDelegate(ByVal [text] As String)
Dim myD1 As New myMethodDelegate(AddressOf myShowStringMethod)
Sub myShowStringMethod(ByVal myString As String)
End Sub
Private Sub serialPort_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived
Dim Distance As String = serialPort.ReadExisting
list1.Text &= Distance
End Sub
'sub to clear the data from txtSend
Sub clear()
txtSend.Clear()
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
If cmbPort.Text = "choose port" Then
MsgBox("please select a port")
cmbPort.Focus()
Else
connectPort()
End If
End Sub
Private Sub txtSend_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSend.KeyDown
If e.KeyCode = Keys.Enter Then
sendCharacter(txtSend.Text)
clear()
End If
End Sub
Private Sub btnled1on_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnled1on.Click
sendCharacter("200")
End Sub
Private Sub btnled1off_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnled1off.Click
sendCharacter("201")
End Sub
Private Sub btnled2on_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnled2on.Click
sendCharacter("202")
End Sub
Private Sub btnled2off_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnled2off.Click
sendCharacter("203")
End Sub
'sub to send data to serial monitor and port
Sub controlServo(ByVal data As Integer)
Try
serialPort.WriteLine(data.ToString)
lblOutput.Text = Str(data)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Dim t As Integer = 0
Private Sub TrackBar1_Scroll_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
controlServo(TrackBar1.Value)
End Sub
Dim counter As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
controlServo(TrackBar1.Value)
If TrackBar1.Value < 180 Then
TrackBar1.Value = TrackBar1.Value + 1
Else
TrackBar1.Value = 0
End If
End Sub
Dim status As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim time As Integer = milliseconds.Value
If time <= 0 Then
MsgBox("please select valid milliseconds")
Else
If status = False Then
Timer1.Interval = time
Timer1.Enabled = True
Button1.Text = "Stop"
status = True
Else
Timer1.Interval = time
Timer1.Enabled = False
Button1.Text = "Set speed"
status = False
End If
End If
End Sub
Private Sub list1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles list1.GotFocus
list1.Enabled = True
End Sub
Private Sub list1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles list1.KeyDown
e.Handled = True
End Sub
Private Sub list1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles list1.KeyPress
e.Handled = True
End Sub
Private Sub list1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles list1.LostFocus
list1.Enabled = True
End Sub
Private Sub list1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles list1.TextChanged
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim stream As StreamWriter
save.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
If save.ShowDialog = Windows.Forms.DialogResult.OK Then
stream = New StreamWriter(save.FileName)
stream.Write(list1.Text)
stream.Close()
MsgBox("file saved successfully")
End If
Catch ex As Exception
End Try
End Sub
End Class
EXTRACTING INSTALLATION FILES
For extracting the installation file i used the following process as i desribed belowCODE USED IN FABBED BOARD
#includeServo myservo; // create servo object to control a servo int val; void setup() { int ledA = A2; // Pin A2 int ledB = A3; // Pin A3 pinMode(A2, OUTPUT); pinMode(A3, OUTPUT); myservo.attach(3); // attaches the servo on pin 3 to the servo object Serial.begin(9600); //begins serial communication } void loop() { String input = ""; val=Serial.parseInt(); { if (val == 200) { digitalWrite(A2, HIGH); // on } else if (val == 201) { digitalWrite(A2, LOW); // OFF } else if (val == 202) { digitalWrite(A3, HIGH); // ON } else if (val == 203) { digitalWrite(A3, LOW); // OFF } if (val <=180 && val >=0){ myservo.write(val); Serial.println(val); Serial.println(input); } } } void serialEvent(){ }
Download files
codes for application and applicationsetup is for windows user only!
board and code used in board