Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Badguy13 Badguy13 is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 399
Rep Power: 15
Badguy13 mempunyai hidup yang Normal
Default openning port with java

ini sya mau share sedit ilmu yg udah saya dapetin tentang bagaimana cara membuka port dengan menggunakan java n command prom:



/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/



package child;



import java.io.*;

import javax.swing.*;

import POSfix.Config;



/**

*

* @author lephoe

*/

public class PoleDisplay {

Runtime rt = Runtime.getRuntime();

Config conf = new Config();

Process p = null;

public String portname;

public String newPort;



public void transaksi(String msg){

FileInputStream fis = null;

try{

fis = new FileInputStream("config");

}

catch(Exception e){

JOptionPane.showMessageDialog(null, "Please configure your port",

"Port Status", JOptionPane.WARNING_MESSAGE);

}



try{

char data;

String port = "";

int temp;

do

{

temp = fis.read();

data = (char)temp;

port = port + data;

} while(temp!=-1);

portname = port;

int panjang = portname.length();

newPort = portname.substring(0, panjang-1);

fis.close();

}

catch(Exception e){

JOptionPane.showMessageDialog(null, "Cannot reading file",

"Configure", JOptionPane.WARNING_MESSAGE);

}



String cmd[] = {

"c:\\Windows\\system32\\cmd.exe", "/c",

"start", "/min",

"c:\\Windows\\system32\\mode.com", newPort,

"baud=9600", "parity=n", "data=8",

"stop=1",

};

try {

p = rt.exec( cmd );

if( p.waitFor() != 0 ) {

System.out.println("Error executing command: " + cmd );

System.exit( -1 );

}

byte data[] = msg.getBytes();

byte data1[] = "Sutisna".getBytes();

FileOutputStream fos = new FileOutputStream( newPort );

BufferedOutputStream bos = new BufferedOutputStream( fos );

fos.write(0x0c); //acsii clear screen

fos.write(data);

fos.write(0x0a); //ascii newline

fos.write(data1);

fos.close();

}

catch( Exception e ) {

e.printStackTrace();

}

}



public void welcome(){

FileInputStream fis = null;

try{

fis = new FileInputStream("config");



try{

char data;

String port = "";

int temp;

do

{

temp = fis.read();

data = (char)temp;

port = port + data;

} while(temp!=-1);

portname = port;

int panjang = portname.length();

newPort = portname.substring(0, panjang-1);

fis.close();

}

catch(Exception e){

JOptionPane.showMessageDialog(null, "Cannot reading file",

"Configure", JOptionPane.WARNING_MESSAGE);

}

}

catch(Exception e){

JOptionPane.showMessageDialog(null, "Please configure your port",

"Port Status", JOptionPane.WARNING_MESSAGE);

}



String cmd[] = {

"c:\\Windows\\system32\\cmd.exe", "/c",

"start", "/min",

"c:\\Windows\\system32\\mode.com", newPort,

"baud=9600", "parity=n", "data=8",

"stop=1",

};



try {

p = rt.exec( cmd );

if( p.waitFor() != 0 ) {

System.out.println("Error executing command: " + cmd );

System.exit( -1 );

}

byte data[] = "Have A Nice Day".getBytes();

byte data1[] = "And Thanks".getBytes();

FileOutputStream fos = new FileOutputStream( newPort );

BufferedOutputStream bos = new BufferedOutputStream( fos );

fos.write(0x0c); //acsii clear screen

fos.write(data);

fos.write(0x0a); //newline

fos.write(data1);

fos.close();

}

catch( Exception e ) {

e.printStackTrace();

}

}

}





mudah2an gk repost gan, n bleh kalo berkenan bagi nya donk





</div>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Terkait
Thread Thread Starter Forum Replies Last Post
JUAL Grosir & Ecer Modem Pool Simbox 8 Port, 16 Port, 32 Port USB / Serial [Kiswara.Net] kiswarajogja Networking & Communications 0 18th February 2014 05:29 PM
JUAL Grosir Murah Modem Pool Simbox 8 Port, 16 Port, 32 Port USB / Serial - Kiswara.Net- kiswarajogja Networking & Communications 0 17th October 2013 05:24 PM
JUAL Modem Pool Wavecom 8 Port / 16 Port / 32 Port Termurah Paling Murah kiswarajogja Aksesoris & perangkat lainnya 0 30th April 2012 04:07 PM
membuka port serial menggunakan java Badguy13 Programming 0 20th November 2011 12:33 AM
membuka port serial menggunakan java Braincode Programming 0 11th November 2011 02:25 PM

 


All times are GMT +7. The time now is 10:05 AM.