Two way communcation with the serial port

From Rxtx

Revision as of 16:01, 24 September 2007 by 207.44.238.95 (Talk)
Jump to: navigation, search

giner heroes of might libreria librerie e scaffalature san damiano url tomtom car kit quarant selen ex pornostar oki c5540 mfp my last breath cortefranca intervento prostata alaska intrattenimento motore sat una lacrima sul viso secondo me l amore map ibanez 7 corde video converter pal ntsc offerte di lavoro in emila romagna page link software downolad gratis jk tapis roulant dogma feat adattatori audio lg 5410 carmail fai come simone wyandot brian mcfadden delta goodrem almost here bastard prog dvb brasileirinha rai tv free grannies garmin geko www cmtv com cheb kaled aischa slovoed url dlink access point all i want for christmas is you mp3 cerca i pirati no di questo tempo gonna bianco gonne donna digimon world 2003 tastiere benq esami d avvocato i cieli narrano video alex baroni storia del design desktop ashlee simpson sardegna traghetti emulatori per pc ida corr viaggi last second voli aerei europa cerco trovo trulli www marmi e graniti it cartine stradali codice rebecca hitachi 7k250 sata homepage map logiciel fr plug in dvd video don t cry for me argentina giochi on line per sole donne hotel nevada dreux vergilio tpo model nude amplificatore finale stereo batteria per nokia 9110 capesante tutto in un abbraccio baglioni map san dorligo della valle films milano logitech momo force presidenti esami di stato johnny weir frigorifero e congelatore aspirapolvere senza sacchetto home honki tonk train blues the gold mine palermo chapter calze e prezzi sars michael invia suonerie polifoniche hotel dioscuri bay palace newsgroup home vivo per lei di andrea bocelli bambola patty bravo toshiba a60 186 iq test a60 p4 tec precision Amateur wifes Besa Prenotazioni albergo costa smeralda Barzelletta chuck norris Offerta televisore lcd samsung Tuttoperinternet it eros escort htm Timbri autoinchiostranti Hotel aurum ischia Risorsa webmaster gratis Foto tyra bank Turistipercaso Testo parte intollerante caparezza Programma scaricare mp3 gratis Striscia notizia it Temi svolti gratis Case vendita milano Teens nude gratis I simpson porno Casa ivrea Nude beach Prezzo dvd vergine Www porno clip Villa in tuscany Omosessualita psicologia Recensione film finestra fronte Software gps palmare Volo per birmingham Racconto erotici porno storia Troie che scopano con animali Hotel economici lisbona Prendi casa lecce Gemelle Vacanza isola elba Festa per bambini in roma Leasing acquisto barca Analisi strategia borsa Download bearshare free Timcafe Canalis porno Taranto night Tuttosport Accendino pipa Annuncio relazioni personali Bper it Cazzeggiare Consip lombardia Video fighe gratis Video eiaculazione femminile Copridivano angolare Cristina quaranta gyno porn clinic Lycos chat spagnol Crociera last minute Tesi laurea popper Paris hilton sex tape Affitti fano Inculate da animali Investimento sicuri Hotlegsandfeet Stacy keibler naked Panda antivirus La maddalena Cuckold roma Video objection shakira Hotel acapulco Gaia bermani amaral Prestito messina Trailers porno Hotel normanno Lanny barby Storia di sesso Voli per israele Arte contemporanea Ricetta famiglia toscana Troie gratis vicenza Dei manicomio Foto donne in tanga Helen svedin gallery Raccolta punti plasmon Greencard Hotel alcamo Tettedure Segaioli Videosorveglianza Teen asian anal cartoni porno xxx Bmw m6 Enasarco it Albergo puglia Posizioni kamasutra Adriana karembeu Soluzione gratis mafia ps2 Screensaver cani Crazy frog Cardellino org Disegni geco Adattatore Suoneria polifoniche gratis Parrucca corta Erica campbell Below is a simple program that shows how to open a connection to a serial device and then interact with it (receiving data and sending data). One thing to note is that the package gnu.io is used instead of javax.comm, though other than the change in package name the API follows the Java Communication API. To find the names of the available ports, see the Discovering comm ports example.

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class TwoWaySerialComm
{
    public TwoWaySerialComm()
    {
        super();
    }
    
    void connect ( String portName ) throws Exception
    {
        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
        if ( portIdentifier.isCurrentlyOwned() )
        {
            System.out.println("Error: Port is currently in use");
        }
        else
        {
            CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
            
            if ( commPort instanceof SerialPort )
            {
                SerialPort serialPort = (SerialPort) commPort;
                serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
                
                InputStream in = serialPort.getInputStream();
                OutputStream out = serialPort.getOutputStream();
                
                (new Thread(new SerialReader(in))).start();
                (new Thread(new SerialWriter(out))).start();

            }
            else
            {
                System.out.println("Error: Only serial ports are handled by this example.");
            }
        }     
    }
    
    /** */
    public static class SerialReader implements Runnable 
    {
        InputStream in;
        
        public SerialReader ( InputStream in )
        {
            this.in = in;
        }
        
        public void run ()
        {
            byte[] buffer = new byte[1024];
            int len = -1;
            try
            {
                while ( ( len = this.in.read(buffer)) > -1 )
                {
                    System.out.print(new String(buffer,0,len));
                }
            }
            catch ( IOException e )
            {
                e.printStackTrace();
            }            
        }
    }

    /** */
    public static class SerialWriter implements Runnable 
    {
        OutputStream out;
        
        public SerialWriter ( OutputStream out )
        {
            this.out = out;
        }
        
        public void run ()
        {
            try
            {                
                int c = 0;
                while ( ( c = System.in.read()) > -1 )
                {
                    this.out.write(c);
                }                
            }
            catch ( IOException e )
            {
                e.printStackTrace();
            }            
        }
    }
    
    public static void main ( String[] args )
    {
        try
        {
            (new TwoWaySerialComm()).connect("COM3");
        }
        catch ( Exception e )
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Personal tools