Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionImports System Imports System.ComponentModel Imports System.Threading Imports System.IO.Ports Public Class Form1 Private Delegate Sub UpdateFormDelegate() Private UpdateFormDelegate1 As UpdateFormDelegate Dim myPort() As String 'COM Ports detected on the system will be stored here Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "Start" Then Button1.Text = "Stop" If LST_Ports.SelectedItem = "" Then MsgBox("Séléctionner un port Com dans la liste") Button1.Text = "Start" Else SerialPort1.PortName = LST_Ports.Text SerialPort1.Open() End If Else Button1.Text = "Start" SerialPort1.Close() End If MsgBox("c bien") End Sub Private Sub serialport1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived ' Event for receiving data ' Read the buffer to text box. UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf DoUpdate) Me.Invoke(UpdateFormDelegate1) End Sub Private Sub DoUpdate() TextBox4.Text = SerialPort1.ReadExisting() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer myPort = IO.Ports.SerialPort.GetPortNames() 'Get all com ports available For i = 0 To UBound(myPort) LST_Ports.Items.Add(myPort(i)) Next LST_Ports.Text = LST_Ports.Items.Item(0) 'Set cmbPort text to the first COM port detected End Sub End Class
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Donnée_serie = SerialPort1.ReadLine() 'récupère une ligne de la trame GPS If Me.InvokeRequired Then Me.BeginInvoke(New Affiche_ASCII(AddressOf _Affiche_ASCII), Donnée_serie) 'lancer la procédure une fois les données reçues Else TextBox1.Text = Donnée_serie End If If Me.InvokeRequired Then Me.BeginInvoke(New Dessin(AddressOf _dessin), Donnée_serie) End If End Sub Private Sub _Affiche_ASCII(ByVal valeur As String) If valeur <> "" Then 'si valeur n'est pas vide Try TextBox1.Text = valeur Catch ex As TimeoutException ' Do nothing End Try End If End Sub Private Sub _dessin(ByRef trame As String) trame = SerialPort1.ReadLine If trame <> "" Then Try If trame(10) = "0" Then distance.Add(CDbl(Replace(trame.Substring(10, 4), ".", ","))) MsgBox(distance(0)) Else distance.Add(CDbl(Replace(trame.Substring(10, 5), ".", ","))) MsgBox(distance(0)) End If If trame(15) = "M" Then If trame(17) = "0" Then angle.Add(CDbl(Replace(trame.Substring(17, 4), ".", ","))) MsgBox(angle(0)) Else angle.Add(CDbl(Replace(trame.Substring(17, 5), ".", ","))) MsgBox(angle(0)) End If ElseIf trame(16) = "M" Then If trame(18) = "0" Then angle.Add(CDbl(Replace(trame.Substring(18, 4), ".", ","))) MsgBox(angle(0)) Else angle.Add(CDbl(Replace(trame.Substring(18, 5), ".", ","))) MsgBox(angle(0)) End If End If If distance.Count 1 Or angle.Count 1 Then x = 100 + distance(0) * Sin((angle(0) * 180) / PI) y = 100 + distance(0) * Cos((angle(0) * 180) / PI) MsgBox(x) MsgBox(y) x = Round(x * 100) y = Round(y * 100) Point(x, y) previous_point.X = x previous_point.Y = y ElseIf distance.Count > 1 Or angle.Count > 1 Then x = 100 + distance(distance.Count - 1) * Sin((angle(angle.Count - 1) * 180) / PI) y = 100 + distance(distance.Count - 1) * Cos((angle(angle.Count - 1) * 180) / PI) MsgBox(x) MsgBox(y) x = Round(x * 100) y = Round(y * 100) Point(x, y) next_point.X = x next_point.Y = y Ligne(previous_point, next_point) previous_point = next_point End If Catch ex As TimeoutException ' Do nothing End Try End If End Sub