SERIAL RS232 VB NET - Bag1 PDF
SERIAL RS232 VB NET - Bag1 PDF
SERIAL RS232 VB NET - Bag1 PDF
DATA TERMINAL
EQUIPMENT DATA
COMMUNICATION
EQUIPMENT
Devices which use serial cables for their communication are split into two
categories. These are
DCE (Data Communications Equipment) and DTE (Data Terminal Equipment.)
Data Communications
BAGIAN SYSTEM KOMUNIKASI SERIAL
PROGRAM
C:/>_
PROGRAM PROGRAM
WIRELESS
C:/>_
1. Wire :
2. Wireless : infrared, RF, zigbee,
FORMAT DATA
5 1
1 5
6 9
9 6
6.DSR
DSR
7.RTS RTS
8.CTS
9.RI
PIN Full Name Function
RI Ring Indicator Goes active when modem detects a ringing signal from the
PSTN.
RS-232 Specifications
Cabling Single-ended
Number of Devices 1 transmit, 1 receive
Communication Mode Full duplex
Distance (max) 50 feet at 19.2kbps
Data Rate (max) 1Mbps
Signaling Unbalanced
Mark (data 1) -5V (min) -15V (max)
Space (data 0) 5V (min) 15V (max)
Input Level (min) 3V
Output Current 500mA (driver Ics in PCs are limited to 10mA)
Impedance 5kW (Internal)
Bus Architecture Point-to-Point
WORD FORMAT
START
BIT
STOP
BIT
0 1 0 1 0 0 0 1 0 0 1
D0 D7
DATA
BYTE
LEVEL TEGANGAN RS232
-15
5V
-5V
15 V
RS-232 Flow Control
REQUEST TO
CLEAR TO SEND
SEND
RTS CTS
CTS RTS
RX TX
DATA
TX RX
COM PORT
COM PORT wiring a Null Modemb
PC
PC
Above is my preferred method of wiring a Null Modem. It only requires 3 wires (TD, RD & SG)
to be wired straight through thus is more cost effective to use with long cable runs. The theory of
operation is reasonably easy. The aim is to make to computer think it is talking to a modem rather than
another computer. Any data transmitted from the first computer must be received by the second thus TD
is connected to RD. The second computer must have the same set-up thus RD is connected to TD. Signal
Ground (SG) must also be connected so both grounds are common to each computer.
The Data Terminal Ready is looped back to Data Set Ready and Carrier Detect on both
computers. When the Data Terminal Ready is asserted active, then the Data Set Ready and
Carrier
Detect immediately become active. At this point the computer thinks the Virtual Modem to
which it is
connected is ready and has detected the carrier of the other modem.
All left to worry about now is the Request to Send and Clear To Send. As both computers
communicate together at the same speed, flow control is not needed thus these two lines are
also linked
together on each computer. When the computer wishes to send data, it asserts the Request
to Send high
and as it's hooked together with the Clear to Send, It immediately gets a reply that it is ok
to send and
does so.
software flow control
REQUEST TO
CLEAR TO SEND
SEND
RTS CTS
CTS RTS
RX TX
TX Xon(11h)
RX
Xoff (13h)
REQUEST TO
SEND
RTS
RX TX
DATA
TX RX
+15V
+5V
0 0
-15V
RS-232 Microcontrollers
Penyesuaian tegangan serial RS 232 PC dgn
Microcontroller
+15V
+5V
0 0
-15V
RS232
RS-232 DRIVER Microcontrollers
Penyesuaian tegangan serial RS 232 PC dgn
Microcontroller
+15V
+5V
0 0
-15V
RS232
RS-232 DRIVER Microcontrollers
VB Net Applications can access direct to physical serial ports
The Windows Device Manager shows information about each COM port
The serial.sys driver controls communications with COM-port devices.
APLIKASI VB
NET
CLASS
SERIALPORT
Class SerialPort
Proverty BaudRate (9600, 19200, 38400 dst)
(data) DataBits ( 7 bit , 8 bit)
Parity (ODD, EVEN,NONE)
StopBits ( 1, 2 )
ReadTimeOut
PortName
BytesToRead
dll
Methode Open()
(fungsi) Close()
isOpen()
Write()
WriteByte()
ReadByte()
DtrEnable()
GetPortNames()
dll
SerialPort Methode / (fungsi)
SerialPort Proverty (data)
MENERIMA DATA DENGAN POOLING DAN INTERUPSI
standby
Aktif
interupsi
polling Bufer
serial
Bufer
serial
4. SET PROPERTY
5. OPEN PORT
7. CLOSE PORT
Sertakan namespace dimana
Class serialport berada
Namespace tempat
class SerialPort berada
Imports System.IO.Ports
BUAT OBJEK SERIALPORT
Imports System.IO.Ports
Nama class
SerialPort
Nama objek
Yg dibuat
BUAT OBJEK dengan DRAG and DROP Componen
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.PortName = COM1
SerialPort1.DataBits = 8
Pesan_eror:
MsgBox( port tdk bisa dibuka")
End Sub
4. SEND DATA
Methode Type data
Serialport1.Write() Array byte, Array Char &
String,
SerialPort1.WriteLine String + New Line
SerialPort1.WriteByte Byte
Contoh1:
SerialPort1.Write(TextBox1.text)
Contoh2:
SerialPort1.Write(TextBox1.text)
Contoh2:
If SerialPort1.IsOpen Then
SerialPort1.Closed()
End if
End Sub
Contoh KODE MENERIMA DATA DENGAN INTERUPSI
Do
ReceiveByte = SerialPort1.ReadByte
Tampung(RXcount) = ReceiveByte
RXCount++
Loop Until(SerialPort1.BytesToRead=0)
End Sub
Konversi type data
SerialPort1.Write(message, 0, message.Length);
GetResponse(ref response);
}
DataString.Substring(awalchar , jumlah_char)
Contoh
ResponseText = 1A200
TextBox1.Text = responseText.Substring(0, 1)
TextBox2.Text = responseText.Substring(1, 1)
TextBox3.Text = responseText.Substring(2, 3)
TextBox1.Text = 1
TextBox2.Text = A
TextBox3.Text = 200
Imports vb = Microsoft.VisualBasic
datasplit = vb.Split(dataserial, #)
TextBox1.Text = datasplit(0)
TextBox2.Text = datasplit(1)
TextBox3.Text = datasplit(2)
TextBox4.Text = datasplit(3)
TextBox1.Text = 123
TextBox2.Text = 456
TextBox3.Text = 789
TextBox4.Text = 777
Praktikum :
Komunikasi Serial VB.Net dgn Modem
AT COMMAND
SMS
MODEM CENTER
HANDPHONE
TAHAPAN
1. MENCARI NOMOR COM PORT
4. SET PROPERTY
5. OPEN PORT
7. CLOSE PORT
Cara Mengetahui Nomor Com Port Modem
AT COMMAND DAN RESPON MODEM
NO AT COMMAND RESPONSE contoh
1 AT <CR><LF>OK<CR><LF> OK, ERROR
2 AT+CGMM Model UW100, E153
3 AT+CGMI Manufacturer huawei
4 AT+CGSN Product Serial Number 352375041161282
5 AT+CMGF=1 OK Set ke text mode
6 AT+CMGS AT+CMGS=+62871234
567
AT COMMAND
MODEM
RESPONSE
PENGUJIAN KOMUNIKASI DENGAN
MODEM MENGGUNAKAN APLIKASI
HYPERTERMINAL
ANDA KETIK
AT COMMAND
RESPON DARI
MODEM
KETIK LALU
AT TEKAN
ENTER
AT RESPON DARI
OK MODEM
KETIK LALU
AT TEKAN
OK ENTER
AT+CGMM
AT RESPON DARI
OK MODEM
AT+CGMM
E153
Komunikasi Aplikasi VB.net dgn Modem
KETIK
AT+CGMM AT COMMAND
DISINI
E153
RESPON DARI
MODEM
Kode VB.Net mengirim string AT COMMAND
Private Sub Button1_Click( ) Handles Button1.Click
If SerialPort1.IsOpen Then
TextString = commandString.Text + Chr(13)
Try
If SerialPort1.IsOpen = False Then
openCommPort()
End If
SerialPort1.Write(TextString)
Do
RXByte = SerialPort1.ReadByte
RXArray(RXCnt) = Chr(RXByte)
RXCnt = RXCnt + 1
Loop Until (SerialPort1.BytesToRead = 0)
End Sub