Cara Mengetahui Serial Port yg terhubung dengan Modem



Source : http://blog.terrenjr.com/2010/09/21/meng...gan-modem/

Iseng2 maLem – malem yg dingin gini..

emang enak buat cari coding yg pas..

hohohh..

alhasi,,gara2 iseng gini..pengen tau deh gimana sih cara mengetahui Serial Port Mana yang Terhubung Dengan Modem / Bisa terkoneksi dengan Modem…

gimana sih COdingnya ??

Ada setelah ini…

hehehe..


Pertama..

kita siapin Command Button,RichTextBox,SerialPort dan Combo Box..

terus desain seperti ini..

Kemudian..

ketikan Coding ini ( SUdah ada Penjelasannya ) :


Code:
Public Class Form1

Dim comPorts As Array 'menampung Port ke dalam array
Dim rxBuff As String 'Buffer untuk menerima data

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Saat Form load
'Menampilkan PORT ke dalam Combo Box
comPorts = IO.Ports.SerialPort.GetPortNames()

For i = 0 To UBound(comPorts)
ComboBox1.Items.Add(comPorts(i))
Next

'Set ComboBox1 text untuk menampilkan port yg paling pertama
ComboBox1.Text = ComboBox1.Items.Item(0)
SerialPort1.PortName = ComboBox1.Text

'Set Attribut port
SerialPort1.BaudRate = 19200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.DataBits = 8

TextBox1.Enabled = False

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'saat button di click..buffer menjadi hilang
rxBuff = ""

'If port tertutup,maka langsung dibuka
If SerialPort1.IsOpen = False Then SerialPort1.Open()

'Tulis data ke dalap Port
SerialPort1.Write(TextBox1.Text & vbCr)

'Pause untuk 800ms
System.Threading.Thread.Sleep(800)

'saat port terbuka,langsung di tutup
If SerialPort1.IsOpen = True Then SerialPort1.Close()

'saat buffer tidak ada data maka end sub
If rxBuff = "" Then GoTo ends

'tampilakn data ke RichTextBOx
RichTextBox1.Text = rxBuff

ends:
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

If SerialPort1.IsOpen = False Then
SerialPort1.PortName = ComboBox1.Text
Else : MsgBox("Operation only valid when port is closed.", MsgBoxStyle.Exclamation, "Error")

End If

RichTextBox1.Clear()
End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

System.Threading.Thread.Sleep(300)

rxBuff = (SerialPort1.ReadExisting)

End Sub

End Class
semoga bisa di pahami ya teman......
Komentar →
Comments
0 Comments

0 comments:

Posting Komentar

komentar anda sangat penting utk kemajuan blog ini.trimakasih utk kunjungannya...

◄ Posting Baru Posting Lama ►
 

tourist n stats

W3 Directory - the World Wide Web Directory My Ping in TotalPing.com
Google PageRank Checker Powered by  MyPagerank.Net

guest room

Copyright © 2012. CYBER MANADO - All Rights Reserved B-Seo Versi 3 by Bamz