2. This is a general purpose language, concurrent,
class-based and object oriented language
becomes completely independent of the
platform and the both powerful. That
philosophy and his ability to create
applications for TCP / IP has made it one of
the most used languages today.
3. RESOURCES
To write Java programs needed to do the precompiled and interpretation of the code,
are environments that allow the creation of the bytecodes and tools include ability to
run applications of all kinds, the most famous Manual Java Developer Kit (JDK) from
Sun, However, writing and compiling programs used and is a bit uncomfortable. So
many companies make their own editing environments such as Netbeans, Eclipse. etc
4. 1. Provide the Java Communications API control over any of the
devices. Before using a device, the API must know.
2. Opening the device and put the line speed, parity, etc.. required.
3. Write or read some data using the protocol specified for the device. For
example, if you have to communicate with a printer, you can send the
codes start and end of work.
4. Close the port.
USING COMMUNICATIONS API
5. Enumeration listaPuertos = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier idPuerto = null;
boolean encontrado = false;
while (listaPuertos.hasMoreElements() && !encontrado) {
idPuerto = (CommPortIdentifier) listaPuertos.nextElement();
if (idPuerto.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (idPuerto.getName().equals("COM1")) {
encontrado = true;
INITIALIZATION API WITH SERIAL
6. Enumeration listaPuertos = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier idPuerto = null;
boolean encontrado = false;
while (listaPuertos.hasMoreElements() && !encontrado) {
idPuerto = (CommPortIdentifier) listaPuertos.nextElement();
if (idPuerto.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (idPuerto.getName().equals("COM1")) {
encontrado = true;
INITIALIZATION API WITH SERIAL
7. InputStream input = null;
OutputStream out;
SerialPort puertoSerie = null;
public ControlPuertoSerie (String device, int baud, int timeout) throws
Exception { CommPortIdentifier idPuerto =
CommPortIdentifier.getPortIdentifier (device);
puertoSerie = (SerialPort) idPuerto.openPort ("PuertoSerie", timeout);
puertoSerie.setSerialPortParams(9600SerialPort.DATABITS_8,SerialPort.STOP
BITS_1,SerialPort.PARITY_NONE);
puertoSerie.setFlowcontrolMode(SerialPort.FLOWCTRL_NONE);
puertoSerie.enableRcvThreshold(1);
puertoSerie.enableRcvTimeout(timeout);
System.out.println ("Open Serial Device");
puertoSerie.getOutputStream out = ();
puertoSerie.getInputStream input = ();
OPENING AND CONDITIONING DEVICES
8. To write, you can do:
try { salida.write (arraySalida, 0, length);
And for reading data, you only have to do:
try { int b = entrada.read ()
CLOSING PORTS
try { entrada.close ();
output.close (); }
WRITING AND READING DATA