Hi! Here I want to contribute with the start of any arduino-PC comunication.
This is a BASIC serial monitor, and sure it can improve, so that, I post here.
I know are a lot of solutions in internet, but this will be an explained solution.
I have programed with Sharpdevelope, in a Viual Basic aplication.
Please coment all improvement, or add a new code and explain how it works.
Thanks!
Next works:
-send data
-send orders (like: "Arduino send me the memory content only")
-separe data by class (to view the I/O in a text box)
-save data recived
-multiplatform
-...
Components:
- button- open
- button - close
- button - refresh
- Combobox - COM ports
- TextBox - text in
Public Partial Class MainForm
Dim text_in As String 'string to save the in text from serial port
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
GetSerialPortNames() 'catch the actual COMs in the PC
serialport.Close 'close the port
txt_read.Clear 'Clean the text
btn_open.Enabled=True 'button open enabled
btn_close.Enabled=False 'button close disabled
timer_read.Enabled=False 'turn off the timer
End Sub
Sub Btn_openClick(sender As Object, e As EventArgs) 'action when is press the OPEN button
serialport.Open 'open serial port
txt_read.Clear 'clean text in
btn_open.Enabled=False 'button open disabled
btn_close.Enabled=True 'button close enabled
timer_read.Enabled=True 'turn on the timer
End Sub
Sub Btn_closeClick(sender As Object, e As EventArgs) 'action when is press the CLOSE button
serialport.Close 'close serial port
btn_open.Enabled=True 'button open disabled
btn_close.Enabled=False 'button close enabled
timer_read.Enabled=False 'turn off the timer
End Sub
Sub GetSerialPortNames() ' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
cmbx_comports.Items.Add(sp) 'add the avaliable COM ports at CoMboBoX
Next
End Sub
Sub Timer_readTick(sender As Object, e As EventArgs) 'Action every set time in Timer_read
txt_read.Text=text_in & serialport.ReadExisting 'textbox show the text_in (string) and the serial port text
text_in= txt_read.Text 'save the previous textbox in the text_in (string)
End Sub
Sub Btn_refreshClick(sender As Object, e As EventArgs) 'Action when refrsh button is press
cmbx_comports.Items.Clear 'clean the previous COMs
GetSerialPortNames() 'Search again new COMs
End Sub
Sub MainFormFormClosing(sender As Object, e As FormClosingEventArgs) 'action when the form is closing
serialport.Close 'close serial port
timer_read.Enabled=False 'turn off the timer
End Sub
End Class