Retroceder   Foros del Web > Programación para sitios web > Java y JSP

Respuesta
 
Herramientas Desplegado
Antiguo 14-mar-2005, 09:24   #1 (permalink)
zaceks está en el buen camino
 
Avatar de zaceks
 
Fecha de Ingreso: abril-2004
Ubicación: Mérida, Yucatán México
Mensajes: 37
Idea API´s de Java

Hola:
estoy tratando de realizar un applet que utilice el api de java el javacomm para tener comunicacion con los puertos de la maquina del cliente, ya que lo necesito poner en una aplicacion web, quisiera saber si esto es posible, agradezco cualquier tipo de ayuda...
Gracias
__________________
:borracho: Si no me acuerdo, no paso!!! :-p
zaceks está desconectado   Responder Citando
Antiguo 14-mar-2005, 09:27   #2 (permalink)
Zerjillo ha deshabilitado el karma
 
Fecha de Ingreso: febrero-2005
Mensajes: 371
Probablemente no podrás a menos de que tengas privilegios suficientes, es decir, tendrás que firmar el applet.

Busca por el foro sobre como firmar un applet (y google) para hacerte una idea del tema

Un saludo

Zerjillo
Zerjillo está desconectado   Responder Citando
Antiguo 14-mar-2005, 09:51   #3 (permalink)
zaceks está en el buen camino
 
Avatar de zaceks
 
Fecha de Ingreso: abril-2004
Ubicación: Mérida, Yucatán México
Mensajes: 37
okas y alguien tendra idea de como realizar el applet que propongo, soy nuevo en esto y aun no he podido ejecutar los ejemplos que trae el api...

cualquier tipo de ayuda es bienvenida
__________________
:borracho: Si no me acuerdo, no paso!!! :-p
zaceks está desconectado   Responder Citando
Antiguo 17-mar-2005, 08:37   #4 (permalink)
zaceks está en el buen camino
 
Avatar de zaceks
 
Fecha de Ingreso: abril-2004
Ubicación: Mérida, Yucatán México
Mensajes: 37
ok, ya logre comunicarme con el dispositivo conectado al puerto serie, pero desde una aplicacion, aqui el codigo:

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.comm.*;

public class Bascula implements Runnable, SerialPortEventListener {
static String messageString = "P";
static SerialPort serialPort;
static OutputStream outputStream;
static CommPortIdentifier portId;
static Enumeration portList;
static InputStream inputStream;
static Thread readThread;

public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

//-------------------ciclo
//-------------------escritura
if (portId.getName().equals("COM1")) {
try {
serialPort = (SerialPort)
portId.open("BasculaApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
//---------------fin escritura
//---------------parametros lectura
Bascula reader = new Bascula();
}
}
}

}

public Bascula() {
try {
serialPort = (SerialPort) portId.open("BasculaApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}

public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
}

public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[10];

try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}

}
/*-----------------------------

ahora quiero convertir este programita en un applet lo que hice fue lo siguiente:
*/



import java.awt.*;
import java.io.*;
import java.util.*;
import javax.comm.*;
import java.applet.*;

public class bascapplet extends Applet
implements Runnable, SerialPortEventListener {

static String messageString = "P";
static SerialPort serialPort;
static OutputStream outputStream;
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
Thread readThread;
String dato;

public void init() {
portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//-------------------ciclo
//-------------------escritura
if (portId.getName().equals("COM1")) {
try {
serialPort = (SerialPort)
portId.open("bascappletApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
//---------------fin escritura
//---------------parametros lectura
bascapplet reader = new bascapplet();
}
}
}
try {
serialPort = (SerialPort) portId.open("bascappletApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
}

public void start() {
readThread.start();
}

public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[10];

try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
//System.out.print(new String(readBuffer));
dato=new String(readBuffer);
} catch (IOException e) {}
break;
}
}

public void paint( Graphics g ) {
g.drawString( "*"+dato+"*",25,25 );
}
}
/*
ya firme el applet, modifique la seguridad con el policytool, y nomas no funcia, si alguien me puede ayudar con este revoltijo, gracias...
saludos
*/
__________________
:borracho: Si no me acuerdo, no paso!!! :-p
zaceks está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Desactivado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 20:53.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93