Article View: borland.public.jbuilder.java.api
Article #357Re: chain of data
From: Owen Green
Date: Tue, 07 Oct 2003 12:05
Date: Tue, 07 Oct 2003 12:05
58 lines
2460 bytes
2460 bytes
On Mon, 6 Oct 2003 23:36:49 -0400, Eliot wrote:
> hi i need help...urgent... i need to send an chain of data
> trought the serial port and i hace the next class that send just 1
> char..
I think you need to flush() the output stream:
salida.write( mensaje.getBytes() );
salida.flush();
Also, you are 'swallowing' exceptions, which is a bad practice - if your
program stops working, then it will be difficult to know why :)
In the case of this code, any of the exceptions you are catching and
ignoring would lead to failure of the job, but are not being handled
properly. If one were thrown, the code would just carry on, and perhaps
cause a NullPointerException, or similar.
Instead:
try {
puertoSerie = ( SerialPort)idPuerto.open("AplEscritura",2000);
// Se obtiene un canal de salida
salida = puertoSerie.getOutputStream();
// Se fijan los par�metros de comunicaci�n del puerto
puertoSerie.setSerialPortParams( 4800,
SerialPort.DATABITS_7,
SerialPort.STOPBITS_2,
SerialPort.PARITY_EVEN );
// Se env�a el mensaje
salida.write( mensaje.getBytes() );
salida.flush();
}
catch( PortInUseException pe )
{
pe.printStackTrace();
//handle
}
catch( UnsupportedCommOperationException ue )
{
ue.printStackTrace();
//handle
}
catch( IOException ie )
{
ie.printStackTrace();
//handle
}
finally
{
//clean up
}
Finally, by and large it's easier to get a solution to a problem with a bit
less code to read :)
--
Owen
Technical Details
Message-ID:
<1uhd5kjng851a.1cuxpgbm1ux3l.dlg@40tude.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f823484@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1089d0,158c18cbce606cf3 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2003-10-07 05:40:23 PST From: Owen Green <o.t.green@ntlworld.com> Subject: Re: chain of data Newsgroups: borland.public.jbuilder.java.api MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit References: <3f823484@newsgroups.borland.com> Date: Tue, 7 Oct 2003 13:05:31 +0100 Message-ID: <1uhd5kjng851a.1cuxpgbm1ux3l.dlg@40tude.net> User-Agent: 40tude_Dialog/2.0.5.1 NNTP-Posting-Host: 80.1.205.234 X-Trace: newsgroups.borland.com 1065528624 80.1.205.234 (7 Oct 2003 05:10:24 -0700) Lines: 58 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail