java : serial communication

a few weeks ago, I build a GUI [graphical user interface] to communicate [read and write] with a device. to communicate with PC [machine], a device must have an interface. the interface can be a serial port, parallel port or USB port. at this time, the device uses a serial port. unfortunately my PC doesn’t have a serial port [high end PC :D] so i’m using USB to serial adapter…

source : almaadin.files.wordpress.com/2010/09/belakang-kom.jpg

serial, parallel, USB port

usb to serial adapter

usb to serial adapter

so, let’s start…

1. the first step making a GUI form including the class. the GUI has been created like this…

GUI

GUI

gui_class

gui_class

gui_button

gui_button

2. after determine the GUI and the class, second step is creating a class Communicator to serve the overall communication with the device and import/add a native class of java…

communicator_class

communicator_class

3. in the Communicator class , must create a constructor in order to communicate with GUI class…

communicator_constructor

communicator_constructor

4. to detect the serial port, create a method [searchForPorts]…

communicator_searchport

communicator_searchport

5. to make a connection with the device, create a method connect. into this method parameters serial port like baud rate, parity bit, stop bit etc. must be defined. i’m using baud rate 38400 bps, 8N1…

communicator_connect

communicator_connect

6. to send a command [write command] to the device create a method Write_Command…

communicator_write

communicator_write

7. to detect IO streaming serial port….

communicator_stream

communicator_stream

8. to read feedback from the device make a method serialEvent…

communicator_read_catch

communicator_read_catch

at the time to read streaming data from the device, java has some ways to do it. with byte array, char array or integer array. after the data streaming saved, the data can be straight to show in GUI with syntax window.txtData.append(…) or can be converted to another type of data like string, ascii, hex etc.

9. the last, to disconnect the communication with the device, create a method [disconnect]…

communicator_disconnect

communicator_disconnect

I just want to share knowledge how to create a communicate with serial port. I hope this blog can help anyone who want to increase knowledge about java especially serial port :).  for further information, you can see the link java2s or roseindia.

#NB : sorry if my english grammar is too poor 😀

Advertisements

5 thoughts on “java : serial communication

  1. mas rizky, ada contact yang bisa dihubungin ga, facebook gitu, mau konsultasi nih soal Java sama akses hardware
    best regards,
    Ichroman R. Duwila

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s