Visual Basicte Port Dinleme ve Database

truvadc

Üye
Katılım
2 Ocak 2009
Mesajlar
109
Puanları
1
Merhaba arkadaşlar.

Bir proje üzerinde çalışıyorum. Bu konuda yardımcı olursanız çok sevinirim.

Delta PLC ile 8 noktadan ölçtüğüm anolog bilgiyi bilgisayarda görüntüleyerek, database

kaydetmek istiyorum. Ayrıca sistemi açılıştırıp durdurma yapacağım basic arayüzünden.

Modbus üzerinden haberleşiyorum. Bir örnek üzerinden giderek bir yere kadar geldim. Plc

nini çıkışlarını aktif edebiliyorum. Anolog bilgileri bir butona basınca text lere

yazdırıyorum. Fakat güncel olarak, butona basmadan yapamadım. Bir değer sıkıntı

database. Eğer exele kaydetmek daha kolay ise öylede yapabilirim. Bu konuda bilgisi

olan arkadaşların yardımını bekliyorum.Yazılımı aşağıya kopyalıyorum.
--------------------------------------------------------------------
Imports System.IO
Public Class Form1
Dim a, k, l, m, n, r, t, y, dat1, dat2, dat3, dat4, dat5, dat6, dat7, dat8, Komplement1, Hesaplanan_LRC As String
Dim adres, islem, bayt_sayisi, data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12, data13, data14, data15, data16, veri, gelen_LRC, data, hesap_Lrc_Str As String
Dim toplam, Komplement, akim_alt, sayac1, sayac2 As Int32
Dim akim_ust, voltaj_alt, voltaj_ust, basinc_set, fan_deger, sistem_devreye_girme, alarm_dat1, alarm_dat2, alarm_toplam, alarm_dat As String
Dim durum As Char
Dim isi1_alt, isi1_ust, isi2_alt, isi2_ust, isi3_alt, isi3_ust, isi4_alt, İsi4_ust, isi5_alt, isi5_ust As String
Dim akim_alt_toplam, akim_alt_lrc, akim_alt_veri, akim_alt_data, akim_ust_toplam, akim_ust_lrc, akim_ust_veri, akim_ust_data As String
Dim voltaj_alt_toplam, voltaj_alt_lrc, voltaj_alt_veri, voltaj_alt_data, voltaj_ust_toplam, voltaj_ust_lrc, voltaj_ust_veri, voltaj_ust_data As String
Dim isi1_alt_toplam, isi1_alt_lrc, isi1_alt_veri, isi1_alt_data, isi1_ust_toplam, isi1_ust_lrc, isi1_ust_veri, isi1_ust_data As String
Dim isi2_alt_toplam, isi2_alt_lrc, isi2_alt_veri, isi2_alt_data, isi2_ust_toplam, isi2_ust_lrc, isi2_ust_veri, isi2_ust_data As String
Dim isi3_alt_toplam, isi3_alt_lrc, isi3_alt_veri, isi3_alt_data, isi3_ust_toplam, isi3_ust_lrc, isi3_ust_veri, isi3_ust_data As String
Dim isi4_alt_toplam, isi4_alt_lrc, isi4_alt_veri, isi4_alt_data, isi4_ust_toplam, isi4_ust_lrc, isi4_ust_veri, isi4_ust_data As String
Dim isi5_alt_toplam, isi5_alt_lrc, isi5_alt_veri, isi5_alt_data, isi5_ust_toplam, isi5_ust_lrc, isi5_ust_veri, isi5_ust_data As String
Dim basinc_set_toplam, basinc_set_lrc, basinc_set_veri, basinc_set_data As String
Dim fan_deger_toplam, fan_deger_lrc, fan_deger_veri, fan_deger_data As String
Dim sistem_devreye_girme_toplam, sistem_devreye_girme_lrc, sistem_devreye_girme_veri, sistem_devreye_girme_data As String
Dim b As Int16

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.PortName() = "COM1"
SerialPort1.Open()

'TextBox1.Text = Timer1.Interval
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

SerialPort1.WriteLine(":01050500FF00F6" + vbCr + vbLf)
End Sub

Private Sub Button52_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'd102 e decimal 3000 değeri gönderildi
'SerialPort1.WriteLine(":010610660BB8C0" + vbCr + vbLf)
akim_alt = ComboBox1.Text
akim_alt_data = Hex(akim_alt)
If akim_alt < 16 Then
akim_alt_data = "0" + akim_alt_data
End If
akim_alt_data = "00" + akim_alt_data

akim_alt = 7 + akim_alt + 16 : akim_alt_toplam = 256 - akim_alt : akim_alt_lrc = Hex(akim_alt_toplam) : akim_alt_veri = ":" + "01" + "06" + "1000" + akim_alt_data + akim_alt_lrc
SerialPort1.WriteLine(akim_alt_veri + vbCr + vbLf)
End Sub

Private Sub Button53_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button53.Click

akim_alt = ComboBox1.Text : akim_ust = ComboBox2.Text : voltaj_alt = ComboBox3.Text : voltaj_ust = ComboBox4.Text
isi1_alt = ComboBox5.Text : isi1_ust = ComboBox6.Text : isi2_alt = ComboBox7.Text : isi2_ust = ComboBox8.Text
isi3_alt = ComboBox9.Text : isi3_ust = ComboBox10.Text : isi4_alt = ComboBox11.Text : İsi4_ust = ComboBox12.Text
isi5_alt = ComboBox13.Text : isi5_ust = ComboBox14.Text : basinc_set = ComboBox15.Text : fan_deger = ComboBox16.Text
sistem_devreye_girme = ComboBox17.Text

akim_alt_data = Hex(akim_alt) : akim_ust_data = Hex(akim_ust) : voltaj_alt_data = Hex(voltaj_alt) : voltaj_ust_data = Hex(voltaj_ust) : isi1_alt_data = Hex(isi1_alt)
isi1_ust_data = Hex(isi1_ust) : isi2_alt_data = Hex(isi2_alt) : isi2_ust_data = Hex(isi2_ust) : isi3_alt_data = Hex(isi3_alt) : isi3_ust_data = Hex(isi3_ust)
isi4_alt_data = Hex(isi4_alt) : isi4_ust_data = Hex(İsi4_ust) : isi5_alt_data = Hex(isi5_alt) : isi5_ust_data = Hex(isi5_ust) : basinc_set_data = Hex(basinc_set)
fan_deger_data = Hex(fan_deger) : sistem_devreye_girme_data = Hex(sistem_devreye_girme)
If akim_alt < 16 Then
akim_alt_data = "0" + akim_alt_data
End If '------------------------------
If akim_ust < 16 Then
akim_ust_data = "0" + akim_ust_data
End If '------------------------------
If voltaj_alt < 16 Then
voltaj_alt_data = "0" + voltaj_alt_data
End If '------------------------------
If voltaj_ust < 16 Then
voltaj_ust_data = "0" + voltaj_ust_data
End If '------------------------------
If isi1_alt < 16 Then
isi1_alt_data = "0" + isi1_alt_data
End If '------------------------------
If isi1_ust < 16 Then
isi1_ust_data = "0" + isi1_ust_data
End If '------------------------------
If isi2_alt < 16 Then
isi2_alt_data = "0" + isi2_alt_data
End If '------------------------------
If isi2_ust < 16 Then
isi2_ust_data = "0" + isi2_ust_data
End If '------------------------------
If isi3_alt < 16 Then
isi3_alt_data = "0" + isi3_alt_data
End If '------------------------------
If isi3_ust < 16 Then
isi3_ust_data = "0" + isi3_ust_data
End If '------------------------------
If isi4_alt < 16 Then
isi4_alt_data = "0" + isi4_alt_data
End If '------------------------------
If İsi4_ust < 16 Then
isi4_ust_data = "0" + isi4_ust_data
End If
If isi5_alt < 16 Then
isi5_alt_data = "0" + isi5_alt_data
End If '------------------------------
If isi5_ust < 16 Then
isi5_ust_data = "0" + isi5_ust_data
End If '------------------------------
If basinc_set < 16 Then
basinc_set_data = "0" + basinc_set_data
End If '------------------------------
If fan_deger < 16 Then
fan_deger_data = "0" + fan_deger_data
End If '------------------------------''
If sistem_devreye_girme < 16 Then
sistem_devreye_girme_data = "0" + sistem_devreye_girme_data
End If '------------------------------
akim_alt_data = "00" + akim_alt_data : akim_ust_data = "00" + akim_ust_data : voltaj_alt_data = "00" + voltaj_alt_data : voltaj_ust_data = "00" + voltaj_ust_data : isi1_alt_data = "00" + isi1_alt_data
isi1_ust_data = "00" + isi1_ust_data : isi2_alt_data = "00" + isi2_alt_data : isi2_ust_data = "00" + isi2_ust_data : isi3_alt_data = "00" + isi3_alt_data : isi3_ust_data = "00" + isi3_ust_data
isi4_alt_data = "00" + isi4_alt_data : isi4_ust_data = "00" + isi4_ust_data : isi5_alt_data = "00" + isi5_alt_data : isi5_ust_data = "00" + isi5_ust_data : basinc_set_data = "00" + basinc_set_data
fan_deger_data = "00" + fan_deger_data : sistem_devreye_girme_data = "00" + sistem_devreye_girme_data


akim_alt = 7 + akim_alt + 36 : akim_alt_toplam = 256 - akim_alt : akim_alt_lrc = Hex(akim_alt_toplam) : akim_alt_veri = ":" + "01" + "06" + "1014" + akim_alt_data + akim_alt_lrc
SerialPort1.WriteLine(akim_alt_veri + vbCr + vbLf)

akim_ust = 7 + akim_ust + 37 : akim_ust_toplam = 256 - akim_ust : akim_ust_lrc = Hex(akim_ust_toplam) : akim_ust_veri = ":" + "01" + "06" + "1015" + akim_ust_data + akim_ust_lrc
SerialPort1.WriteLine(akim_ust_veri + vbCr + vbLf)
'Timer1.Interval = 5

voltaj_alt = 7 + voltaj_alt + 38 : voltaj_alt_toplam = 256 - voltaj_alt : voltaj_alt_lrc = Hex(voltaj_alt_toplam) : voltaj_alt_veri = ":" + "01" + "06" + "1016" + voltaj_alt_data + voltaj_alt_lrc
SerialPort1.WriteLine(voltaj_alt_veri + vbCr + vbLf)


voltaj_ust = 7 + voltaj_ust + 39 : voltaj_ust_toplam = 256 - voltaj_ust : voltaj_ust_lrc = Hex(voltaj_ust_toplam) : voltaj_ust_veri = ":" + "01" + "06" + "1017" + voltaj_ust_data + voltaj_ust_lrc
SerialPort1.WriteLine(voltaj_ust_veri + vbCr + vbLf)

isi1_alt = 7 + isi1_alt + 40 : isi1_alt_toplam = 256 - isi1_alt : isi1_alt_lrc = Hex(isi1_alt_toplam) : isi1_alt_veri = ":" + "01" + "06" + "1018" + isi1_alt_data + isi1_alt_lrc
SerialPort1.WriteLine(isi1_alt_veri + vbCr + vbLf)

isi1_ust = 7 + isi1_ust + 41 : isi1_ust_toplam = 256 - isi1_ust : isi1_ust_lrc = Hex(isi1_ust_toplam) : isi1_ust_veri = ":" + "01" + "06" + "1019" + isi1_ust_data + isi1_ust_lrc
SerialPort1.WriteLine(isi1_ust_veri + vbCr + vbLf)
'Timer1.Interval = 5


isi2_alt = 7 + isi2_alt + 42 : isi2_alt_toplam = 256 - isi2_alt : isi2_alt_lrc = Hex(isi2_alt_toplam) : isi2_alt_veri = ":" + "01" + "06" + "101A" + isi2_alt_data + isi2_alt_lrc
SerialPort1.WriteLine(isi2_alt_veri + vbCr + vbLf)

isi2_ust = 7 + isi2_ust + 43 : isi2_ust_toplam = 256 - isi2_ust : isi2_ust_lrc = Hex(isi2_ust_toplam) : isi2_ust_veri = ":" + "01" + "06" + "101B" + isi2_ust_data + isi2_ust_lrc
SerialPort1.WriteLine(isi2_ust_veri + vbCr + vbLf)
'Timer1.Interval = 5


isi3_alt = 7 + isi3_alt + 44 : isi3_alt_toplam = 256 - isi3_alt : isi3_alt_lrc = Hex(isi3_alt_toplam) : isi3_alt_veri = ":" + "01" + "06" + "101C" + isi3_alt_data + isi3_alt_lrc
SerialPort1.WriteLine(isi3_alt_veri + vbCr + vbLf)
'Timer1.Interval = 5


isi3_ust = 7 + isi3_ust + 45 : isi3_ust_toplam = 256 - isi3_ust : isi3_ust_lrc = Hex(isi3_ust_toplam) : isi3_ust_veri = ":" + "01" + "06" + "101D" + isi3_ust_data + isi3_ust_lrc
SerialPort1.WriteLine(isi3_ust_veri + vbCr + vbLf)
'Timer1.Interval = 5


isi4_alt = 7 + isi4_alt + 46 : isi4_alt_toplam = 256 - isi4_alt : isi4_alt_lrc = Hex(isi4_alt_toplam) : isi4_alt_veri = ":" + "01" + "06" + "101E" + isi4_alt_data + isi4_alt_lrc
SerialPort1.WriteLine(isi4_alt_veri + vbCr + vbLf)
'Timer1.Interval = 5


İsi4_ust = 7 + İsi4_ust + 47 : isi4_ust_toplam = 256 - İsi4_ust : isi4_ust_lrc = Hex(isi4_ust_toplam) : isi4_ust_veri = ":" + "01" + "06" + "101F" + isi4_ust_data + isi4_ust_lrc
SerialPort1.WriteLine(isi4_ust_veri + vbCr + vbLf)
'Timer1.Interval = 5


isi5_alt = 7 + isi5_alt + 48 : isi5_alt_toplam = 256 - isi5_alt : isi5_alt_lrc = Hex(isi5_alt_toplam) : isi5_alt_veri = ":" + "01" + "06" + "1020" + isi5_alt_data + isi5_alt_lrc
SerialPort1.WriteLine(isi5_alt_veri + vbCr + vbLf)
'Timer1.Interval = 5


isi5_ust = 7 + isi5_ust + 49 : isi5_ust_toplam = 256 - isi5_ust : isi5_ust_lrc = Hex(isi5_ust_toplam) : isi5_ust_veri = ":" + "01" + "06" + "1021" + isi5_ust_data + isi5_ust_lrc
SerialPort1.WriteLine(isi5_ust_veri + vbCr + vbLf)
'Timer1.Interval = 5


basinc_set = 7 + basinc_set + 50 : basinc_set_toplam = 256 - basinc_set : basinc_set_lrc = Hex(basinc_set_toplam) : basinc_set_veri = ":" + "01" + "06" + "1022" + basinc_set_data + basinc_set_lrc
SerialPort1.WriteLine(basinc_set_veri + vbCr + vbLf)
'Timer1.Interval = 5


fan_deger = 7 + fan_deger + 51 : fan_deger_toplam = 256 - fan_deger : fan_deger_lrc = Hex(fan_deger_toplam) : fan_deger_veri = ":" + "01" + "06" + "1023" + fan_deger_data + fan_deger_lrc
SerialPort1.WriteLine(fan_deger_veri + vbCr + vbLf)
'Timer1.Interval = 5


sistem_devreye_girme = 7 + sistem_devreye_girme + 52 : sistem_devreye_girme_toplam = 256 - sistem_devreye_girme : sistem_devreye_girme_lrc = Hex(sistem_devreye_girme_toplam) : sistem_devreye_girme_veri = ":" + "01" + "06" + "1024" + sistem_devreye_girme_data + sistem_devreye_girme_lrc
SerialPort1.WriteLine(sistem_devreye_girme_veri + vbCr + vbLf)

End Sub

Private Sub Button46_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'd101 e decimal 2000 ve d102 e decimal 4000 değeri gönderildi
SerialPort1.WriteLine(":0110106500020407D00FA0EE" + vbCr + vbLf)
End Sub

Private Sub Button45_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button45.Click
'd111 in değerini hexedecimal olarak okur
'SerialPort1.WriteLine(":0103106F00017C" + vbCr + vbLf)' bir adreten okuma
SerialPort1.WriteLine(":0103106F000875" + vbCr + vbLf) ' sekiz adresten veri okuma
veri = (SerialPort1.ReadLine)
adres = Mid(veri, 2, 2) ' verinin 2. karakterinden itibaren 2 karakter alır
islem = Mid(veri, 4, 2)
bayt_sayisi = Mid(veri, 6, 2)
dat1 = Mid(veri, 8, 4) : dat1 = Val("&H" + dat1) ' datayı alır
dat2 = Mid(veri, 12, 4) : dat2 = Val("&H" + dat2)
dat3 = Mid(veri, 16, 4) : dat3 = Val("&H" + dat3)
dat4 = Mid(veri, 20, 4) : dat4 = Val("&H" + dat4)
dat5 = Mid(veri, 24, 4) : dat5 = Val("&H" + dat5)
dat6 = Mid(veri, 28, 4) : dat6 = Val("&H" + dat6)
dat7 = Mid(veri, 32, 4) : dat7 = Val("&H" + dat7)
dat8 = Mid(veri, 36, 4) : dat8 = Val("&H" + dat8)
data1 = Mid(veri, 8, 2) : data1 = Val("&H" + data1) 'LRC hesabı için 2bayt olarak ayırır.
data2 = Mid(veri, 10, 2) : data2 = Val("&H" + data2)
data3 = Mid(veri, 12, 2) : data3 = Val("&H" + data3)
data4 = Mid(veri, 14, 2) : data4 = Val("&H" + data4)
data5 = Mid(veri, 16, 2) : data5 = Val("&H" + data5)
data6 = Mid(veri, 18, 2) : data6 = Val("&H" + data6)
data7 = Mid(veri, 20, 2) : data7 = Val("&H" + data7)
data8 = Mid(veri, 22, 2) : data8 = Val("&H" + data8)
data9 = Mid(veri, 24, 2) : data9 = Val("&H" + data9)
data10 = Mid(veri, 26, 2) : data10 = Val("&H" + data10)
data11 = Mid(veri, 28, 2) : data11 = Val("&H" + data11)
data12 = Mid(veri, 30, 2) : data12 = Val("&H" + data12)
data13 = Mid(veri, 32, 2) : data13 = Val("&H" + data13)
data14 = Mid(veri, 34, 2) : data14 = Val("&H" + data14)
data15 = Mid(veri, 36, 2) : data15 = Val("&H" + data15)
data16 = Mid(veri, 38, 2) : data16 = Val("&H" + data16)
gelen_LRC = Mid(veri, 40, 2)

'TextBox2.Text = gelen_LRC

'TextBox1.Text = data3
toplam = Val("&H" + adres) + Val("&H" + islem) + Val("&H" + bayt_sayisi) + data1 + data2 + data3 + data4 + data5 + data6 +
data7 + data8 + data9 + data10 + data11 + data12 + data13 + data14 + data15 + data16 ' gelen veri 2 bayt şeklinde toplanır
'a = adres + islem + bayt_sayisi + data1 + data2 + data3 + data4 + data5 + data6 + data7 + data8


' y = Convert.ToString(toplam)
'TextBox2.Text = toplam
Komplement = 65536 - toplam 'toplamı komplementi alınır.
Komplement1 = Hex(Komplement) ' komplementi alınan sayı hexdecimala çevrilir.
'TextBox2.Text = hesaplanan_LRC
'hesap_Lrc_Str = Str(hesaplanan_LRC)
'TextBox2.Text = hesap_Lrc_Str


Hesaplanan_LRC = Microsoft.VisualBasic.Right(Komplement1, 2) 'Komplement 2 basamaktan büyük olduğu için komlementin sondan iki karakteri alınıyor.
If Hesaplanan_LRC = gelen_LRC Then

TextBox3.Text = dat1
TextBox4.Text = dat2
TextBox5.Text = dat3
TextBox6.Text = dat4
TextBox7.Text = dat5
TextBox8.Text = dat6
TextBox9.Text = dat7
TextBox10.Text = dat8

End If
End Sub
Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.WriteLine(":01050500FF00F6" + vbCr + vbLf)
Panel1.BackColor = Color.GreenYellow
End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.WriteLine(":010505000000F5" + vbCr + vbLf)
Panel1.BackColor = Color.Red
End Sub

Private Sub GroupBox5_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox5.Enter


End Sub


Private Sub ComboBox13_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox13.SelectedIndexChanged

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListBox1.ResetText()

End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub ComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

End Sub

End Class
 

Forum istatistikleri

Konular
122,196
Mesajlar
861,861
Kullanıcılar
438,692
Son üye
ünaltorlakli67

Yeni konular

Üst