Imports System.IO
Imports System.Net.Http
Public Class LEDNDSample
'When the display button is pressed
Private Sub BtnDisp_Click(sender As Object, e As EventArgs) Handles BtnDisp.Click
SendData("1,234,567")
End Sub
'When the clear button is pressed
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
SendData("")
End Sub
'Execute communication
'When incorporating into a practical program, please incorporate error handling etc.
Private Sub SendData(ByVal msg As String)
Dim ret As Integer = 0
Dim sendData As String = ""
If RadioUSB.Checked Then
'For USBCOM
'If the serial port number is COM1
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.Handshake = Ports.Handshake.RequestToSend
If msg = "" Then
'Clear display
sendData = Chr(&HC)
Else
'Display
sendData = msg
End If
SerialPort1.Open()
'Data Transmission
SerialPort1.Write(sendData)
SerialPort1.Close()
ElseIf RadioWiFi.Checked Then
'For Wireless LAN
'If the IP address of LEDND is 192.168.1.250
Dim url As String = "http://192.168.1.250/disp/"
If msg = "" Then
'Clear Display
sendData = url + "%0C"
Else
'Display
sendData = url + msg
End If
'Data Transmission
SendByHttp(sendData)
End If
End Sub
' HTTP Communication Processing
Private Async Sub SendByHttp(ByVal url As String)
Dim sendUrl As Uri = New Uri(url)
Dim html As String = ""
Using httpcl As New HttpClient()
html = Await httpcl.GetStringAsync(sendUrl)
End Using
End Sub
|