NBATMAN
Üye
- Katılım
- 7 Şub 2008
- Mesajlar
- 136
- Puanları
- 1
Merhaba,
aşağıdaki kodları ile aynı form üzerinde 2 ayrı comport kullanarak gönderme ve alma işlemleri yapılabilir.
Imports System
Imports System.Text
Imports System.Drawing
Imports System.IO.Ports
Imports System.Threading
Imports System.Windows.Forms
Imports Microsoft.Win32
PublicClassForm1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = ""Then
MessageBox.Show("Gönderilen Data Kutusu Boş Olamaz!Bir Bilgi Giriniz!", "Giriş Hatası", MessageBoxButtons.OK, MessageBoxIcon.Warning)
TextBox1.Focus()
Else
Timer1.Start()
EndIf
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
EndSub
PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
OnErrorResumeNext
SerialPort1.Open()
SerialPort1.Write(TextBox1.Text & vbCrLf)
Dim datasay AsInteger
datasay = Label2.Text + 1
Label2.Text = Format(datasay, "00000")
SerialPort1.Close()
EndSub
PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If SerialPort2.IsOpen = TrueThen
SerialPort2.Close()
Else
SerialPort2.Open()
EndIf
Timer2.Start()
EndSub
PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If SerialPort2.IsOpen = FalseThen
SerialPort2.Open()
Else
SerialPort2.Close()
EndIf
Timer2.Stop()
EndSub
PrivateSub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OnErrorResumeNext
Dim GelenData AsString
Dim i AsInteger
Dim GelenDataFormat() AsString
Dim rdatasay AsInteger
GelenData = (SerialPort2.ReadExisting)
GelenDataFormat = GelenData.Split(Chr(13) & Chr(10))
For i = 0 To UBound(GelenDataFormat)
If GelenDataFormat(0) = ""Then
Exit Sub
Else
ListBox1.Items.Add(GelenDataFormat(i))
rdatasay = ListBox1.Items.Count / 2
Label1.Text = Format(rdatasay, "00000")
EndIf
Next i
EndSub
EndClass
aşağıdaki kodları ile aynı form üzerinde 2 ayrı comport kullanarak gönderme ve alma işlemleri yapılabilir.
Imports System
Imports System.Text
Imports System.Drawing
Imports System.IO.Ports
Imports System.Threading
Imports System.Windows.Forms
Imports Microsoft.Win32
PublicClassForm1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = ""Then
MessageBox.Show("Gönderilen Data Kutusu Boş Olamaz!Bir Bilgi Giriniz!", "Giriş Hatası", MessageBoxButtons.OK, MessageBoxIcon.Warning)
TextBox1.Focus()
Else
Timer1.Start()
EndIf
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
EndSub
PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
OnErrorResumeNext
SerialPort1.Open()
SerialPort1.Write(TextBox1.Text & vbCrLf)
Dim datasay AsInteger
datasay = Label2.Text + 1
Label2.Text = Format(datasay, "00000")
SerialPort1.Close()
EndSub
PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If SerialPort2.IsOpen = TrueThen
SerialPort2.Close()
Else
SerialPort2.Open()
EndIf
Timer2.Start()
EndSub
PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If SerialPort2.IsOpen = FalseThen
SerialPort2.Open()
Else
SerialPort2.Close()
EndIf
Timer2.Stop()
EndSub
PrivateSub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OnErrorResumeNext
Dim GelenData AsString
Dim i AsInteger
Dim GelenDataFormat() AsString
Dim rdatasay AsInteger
GelenData = (SerialPort2.ReadExisting)
GelenDataFormat = GelenData.Split(Chr(13) & Chr(10))
For i = 0 To UBound(GelenDataFormat)
If GelenDataFormat(0) = ""Then
Exit Sub
Else
ListBox1.Items.Add(GelenDataFormat(i))
rdatasay = ListBox1.Items.Count / 2
Label1.Text = Format(rdatasay, "00000")
EndIf
Next i
EndSub
EndClass