Click here to Skip to main content
15,902,275 members

Comments by Dammak Karim (Top 2 by date)

Dammak Karim 29-Apr-22 6:59am View    
Imports System.IO.Ports

Public Class Form1
Dim dataIN As String
Dim dataOUT As String
Private Delegate Sub AccesDelegue(ByVal AjouterText As String)

Private Sub AccesFormPrinpal(ByVal TextForms As String)
dataOUT = TextForms
dataIN=Replace(dataIN,"04", Environment.NewLine & "04")
TxtDonnesRecus.Text += dataOUT
End Sub

Private Sub PortAcceesInteruption(ByVal bufferin As String)

Dim textinteruption As Object = {bufferin}

Dim delegateinteruption As AccesDelegue
delegateinteruption = New AccesDelegue(AddressOf AccesFormPrinpal)
MyBase.Invoke(delegateinteruption, bufferin)

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dataIN = ""
dataOUT = ""
BtnConnecter.Enabled = False
BtnEnvoyesData.Enabled = False


End Sub

Private Sub BtnChercherPorts_Click(sender As Object, e As EventArgs) Handles BtnChercherPorts.Click
CboxPorts.Items.Clear()
For Each PortDinsponible As String In My.Computer.Ports.SerialPortNames
CboxPorts.Items.Add(PortDinsponible)
Next
If CboxPorts.Items.Count > 0 Then
CboxPorts.Text = CboxPorts.Items(0)
MessageBox.Show("selectionner le port de travail")
BtnConnecter.Enabled = True
Else
MessageBox.Show("NON Port Trouve")
BtnConnecter.Enabled = False
BtnEnvoyesData.Enabled = False
CboxPorts.Items.Clear()
End If

End Sub

Private Sub BtnConnecter_Click(sender As Object, e As EventArgs) Handles BtnConnecter.Click
If BtnConnecter.Text = "Connecter" Then
Try
With SerialPort1
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.StopBits = IO.Ports.StopBits.One
.DataBits = 8
.PortName = CboxPorts.Text
.Open()
End With
BtnConnecter.Text = "deconnecter"
BtnEnvoyesData.Enabled = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
ElseIf BtnConnecter.Text = "deconnecter" Then
BtnConnecter.Text = "Connecter"
BtnEnvoyesData.Enabled = False
SerialPort1.Close()
End If



End Sub

Private Sub BtnEnvoyesData_Click(sender As Object, e As EventArgs) Handles BtnEnvoyesData.Click
SerialPort1.DiscardOutBuffer()
dataIN = TxtEnvoyerDonnes.Text
SerialPort1.Write(dataIN)
End Sub

Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim datainterruption As String
datainterruption = SerialPort1.ReadExisting
PortAcceesInteruption(datainterruption)
End Sub
End Class
this is the serial communication
Dammak Karim 29-Apr-22 6:56am View    
in my project I make a serial communication between my pc and another device I receive the data in my pc in series and do the accumulation with each other
so I want to limit the size of this flux so I want to do when it finds "04" it starts accumulating data then it stops with the next "04" and like the example I describe above