Selasa, 27 September 2016

Komunikasi Serial (USB Serial PL2303 + Minicom) Di Ubuntu 12.04

Jika menggunakan Sistem Operasi Windows, kita bisa melakukan komunikasi serial antara PC yang sedang kita gunakan dengan perangkat eksternal melalui port DB9 / RS232 atau melalui port USB dengan bantuan kabel USB to Serial, dengan menggunakan software yang cukup melegenda Hyperterminal maupun Putty.

Namun, jika PC yang kita gunakan menggunakan Sistem Operasi Windows, maka bagaimanakah caranya untuk melakukan komunikasi serial antara PC kita dengan perangkat eksternal ? Kita bisa menggunakan software Minicom (pengganti Hyperterminal / Putty). Masalahnya adalah bagaimana cara men-set up Minicom seperti halnya melakukan set up di Hyperterminal maupun Putty ?

Kemudian masalah yang lain muncul di kala PC yang kita gunakan tidak memiliki Port Serial (RS232/DB9) onboard, sehingga kita harus menggunakan kabel USB to Serial. Bagaimanakah cara melakukan instalasi driver kabel USB to Serial di Sistem Operasi Linux ?

Maka tutorial kali ini akan menjelaskan hal-hal tersebut diatas. Disini best practice nya adalah sebagai berikut :
  1. PC menggunakan Sistem Operasi Ubuntu 12.04, dan tidak memiliki port RS232 sehingga harus menggunakan kabel USB to Serial


  2. Kabel USB to Serial yang digunakan adalah Prolific PL2303


  3. Software Serial yang digunakan adalah Minicom (Hyperterminal versi Linux)
PC yang saya gunakan untuk komunikasi serial menggunakan Sistem Operasi Ubuntu 12.04 :

it@ubuntu:~$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="12.04.1 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.1 LTS)"
VERSION_ID="12.04"

Setelah kabel USB to Serial dihubungkan ke Port USB PC Linux Ubuntu 12.04, maka akan terbaca sebagai berikut.

root@ubuntu:/home/it# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 003 Device 003: ID 1c4f:0003 SiGma Micro HID controller

Lakukan instalasi software minicom di PC Ubuntu 12.04.

root@ubuntu:/home/it# apt-get install minicom
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  gir1.2-timezonemap-1.0
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  lrzsz
The following NEW packages will be installed:
  lrzsz minicom
0 upgraded, 2 newly installed, 0 to remove and 727 not upgraded.
Need to get 392 kB of archives.
After this operation, 1,483 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y

Lihat USB Serial Adapter yang kita hubungkan ke PC Linux (Ubuntu 12.04) terhubung ke Port berapa.

root@ubuntu:/home/it# dmesg | grep USB
[    1.020652] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    1.020707] ehci_hcd 0000:00:1a.7: new USB bus registered, assigned bus number 1
[    1.036860] ehci_hcd 0000:00:1a.7: USB 2.0 started, EHCI 1.00
[    1.036999] hub 1-0:1.0: USB hub found
[    1.037103] ehci_hcd 0000:00:1d.7: new USB bus registered, assigned bus number 2
[    1.056804] ehci_hcd 0000:00:1d.7: USB 2.0 started, EHCI 1.00
[    1.056930] hub 2-0:1.0: USB hub found
[    1.056985] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    1.056994] uhci_hcd: USB Universal Host Controller Interface driver
[    1.057047] uhci_hcd 0000:00:1a.0: new USB bus registered, assigned bus number 3
[    1.057165] hub 3-0:1.0: USB hub found
[    1.057252] uhci_hcd 0000:00:1a.1: new USB bus registered, assigned bus number 4
[    1.057366] hub 4-0:1.0: USB hub found
[    1.057454] uhci_hcd 0000:00:1a.2: new USB bus registered, assigned bus number 5
[    1.057558] hub 5-0:1.0: USB hub found
[    1.057642] uhci_hcd 0000:00:1d.0: new USB bus registered, assigned bus number 6
[    1.057745] hub 6-0:1.0: USB hub found
[    1.057836] uhci_hcd 0000:00:1d.1: new USB bus registered, assigned bus number 7
[    1.057939] hub 7-0:1.0: USB hub found
[    1.058023] uhci_hcd 0000:00:1d.2: new USB bus registered, assigned bus number 8
[    1.058130] hub 8-0:1.0: USB hub found
[    1.415875] usb 1-2: new high-speed USB device number 3 using ehci_hcd
[    1.559383] Initializing USB Mass Storage driver...
[    1.559718] USB Mass Storage support registered.
[    1.794835] usb 3-1: new low-speed USB device number 2 using uhci_hcd
[    1.984886] generic-usb 0003:1C4F:0003.0001: input,hidraw0: USB HID v1.10 Mouse [SIGMACHIP Usb Mouse] on usb-0000:00:1a.0-1/input0
[    1.984906] usbhid: USB HID core driver
[   65.119757] usb 3-1: USB disconnect, device number 2
[   66.596433] usb 3-1: new low-speed USB device number 3 using uhci_hcd
[   66.785527] generic-usb 0003:1C4F:0003.0002: input,hidraw0: USB HID v1.10 Mouse [SIGMACHIP Usb Mouse] on usb-0000:00:1a.0-1/input0
[ 7032.905243] usb 1-2: USB disconnect, device number 3
[ 7047.200082] usb 3-2: new full-speed USB device number 4 using uhci_hcd
[ 7047.410359] USB Serial support registered for generic
[ 7047.410395] usbserial: USB Serial Driver core
[ 7047.411878] USB Serial support registered for pl2303
[ 7047.423915] usb 3-2: pl2303 converter now attached to ttyUSB0
[ 7047.423942] pl2303: Prolific PL2303 USB to serial adaptor driver

Terlihat bahwa USB Serial Adapter terhubung ke Port ttyUSB0. Agar minicom dapat merubah konfigurasi dari file ttyUSB0, maka rubah hak akses file /dev/ttyUSB0.

root@ubuntu:/home/it# ls -l /dev | grep ttyUSB0
crw-rw----  1 root dialout 188,   0 Sep 27 09:47 ttyUSB0
 
root@ubuntu:/home/it# chmod 0777 /dev/ttyUSB0 
 
root@ubuntu:/home/it# ls -l /dev | grep ttyUSB0
crwxrwxrwx  1 root dialout 188,   0 Sep 27 09:47 ttyUSB0

Lanjutkan dengan men-set up minicom untuk menentukan parameter-parameter komunikasi serial seperti baud rate, parity bit, stop bit, dan flow control.

it@ubuntu:~$ sudo minicom -s

            +-----[configuration]------+                                     
            | Filenames and paths      |                                     
            | File transfer protocols  |                                     
            | Serial port setup        |                                     
            | Modem and dialing        |                                     
            | Screen and keyboard      |
            | Save setup as dfl        |
            | Save setup as..          |
            | Exit                     |
            | Exit from Minicom        |
            +--------------------------+

Pilih menu "Serial port setup". Kemudian lakukan konfigurasi sesuai kebutuhan (Serial Device = /dev/ttyUSB0, Baud Rate (Bits per second) = 115200, Data Bits = 8 Parity = None, Stop bits = 1, Flow control = Hardware).

    +-----------------------------------------------------------------------+
    | A -    Serial Device      : /dev/ttyUSB0                              |
    | B - Lockfile Location     : /var/lock                                 |
    | C -   Callin Program      :                                           |
    | D -  Callout Program      :                                           |
    | E -    Bps/Par/Bits       : 115200 8N1                                |
    | F - Hardware Flow Control : Yes                                       |
    | G - Software Flow Control : No                                        |
    |                                                                       |
    |    Change which setting?                                              |
    +-----------------------------------------------------------------------+
            | Screen and keyboard      |
            | Save setup as dfl        |
            | Save setup as..          |
            | Exit                     |
            | Exit from Minicom        |
            +--------------------------+

Setelah selesai, tekan "Enter" -> Save as dfl -> Enter.

                            +-----------------------+                        
                            |                       |                        
            +-----[configura|  Configuration saved  |                        
            | Filenames and |                       |                        
            | File transfer +-----------------------+                        
            | Serial port setup        |                                     
            | Modem and dialing        |                                     
            | Screen and keyboard      |
            | Save setup as dfl        |
            | Save setup as..          |
            | Exit                     |
            | Exit from Minicom        |
            +--------------------------+

Setelah menekan menu "Exit", maka kita akan langsung dibawa ke jendela console minicom.

            +-----[configuration]------+                                     
            | Filenames and paths      |                                     
            | File transfer protocols  |                                     
            | Serial port setup        |                                     
            | Modem and dialing        |                                     
            | Screen and keyboard      |
            | Save setup as dfl        |
            | Save setup as..          |
            | Exit                     |
            | Exit from Minicom        |
            +--------------------------+

Welcome to minicom 2.5

OPTIONS: I18n                                                                
Compiled on May  2 2011, 00:39:27.                                           
Port /dev/ttyUSB0                                                            
                                                                             
Press CTRL-A Z for help on special keys
 
 
 
 
 
 
 
 
 
 

Untuk keluar dari jendela console minicom, tekan "CTRL-A" -> Z -> X.

Demikian tutorial ini. Semoga bermanfaat.

Tidak ada komentar:

Posting Komentar