Building a Remote Data Logger in Java

Encode QR Code in Java Building a Remote Data Logger
7
Encode QR Code In Java
Using Barcode printer for Java Control to generate, create QR image in Java applications.
Building a Remote Data Logger
Barcode Generation In Java
Using Barcode maker for Java Control to generate, create barcode image in Java applications.
in Listing 718 Upon construction PPPModemLink invokes its superclass s constructor to acquire and initialize the serial port It also creates a ModemCommand object to manage sending commands to and receiving responses from the modem The ModemCommand class is described later in this section Listing 718 PPPModemLink
Bar Code Scanner In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
import javaxcomm*; import javaio*; import javautilTooManyListenersException; public class PPPModemLink extends PPPSerialLink implements SerialPortEventListener { private ModemCommand mc; public PPPModemLink(String portName, int speed, DataLinkListener listener) throws DataLinkException { super(portName, speed, listener); mc = new ModemCommand(sp, in, out); try { spaddEventListener(this); } catch (TooManyListenersException tmle) { throw new DataLinkException( "Unable to register for serial events"); } } public void serialEvent(SerialPortEvent ev) { if ((evgetEventType() == SerialPortEventCD) && !evgetNewValue()) { listenerdataLinkError("Lost carrier detect"); } } }
Drawing QR In Visual C#
Using Barcode drawer for VS .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
PPPModemLink implements the SerialPortEventListener interface In this case we re speci cally interested in the SerialPortEventCD (Carrier Detect) event because we need to be noti ed if and when the modem hangs up When the modem hangs up, the CD signal transitions from high (carrier present) to low (carrier not present) If this happens, the serialEvent method is invoked by the serial port event daemon noti cation thread serialEvent checks the event type to see if it is a carrier detect change event All other events are ignored If the returned event value is false, this signals that the modem has indeed hung up, and serialEvent invokes the DataLinkListener s (PPPDaemon in this case) dataLinkError method, notifying the listener that the data link is no longer valid
QR Code Encoder In VS .NET
Using Barcode generation for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
Managing the PPP Data Link
QR-Code Encoder In VS .NET
Using Barcode drawer for .NET framework Control to generate, create Quick Response Code image in .NET applications.
The PPP daemon then closes the underlying PPP connection and frees any resources that were consumed Initializing the modem link involves the following three steps: 1 Reset the modem 2 Wait for a ring 3 Answer the phone Both the initializeLink and resetModem methods are shown in Listing 719 The modem reset is initiated by dropping the DTR (Data Terminal Ready) line low, delaying for a couple of seconds, and then raising DTR back high After toggling DTR, resetModem sends the string AT\r to the modem and waits for a response string of OK If the expected response is received, resetModem returns normally If the response is not received within the speci ed time-out value six seconds in this case a DataLinkException is thrown by the sendCommand method of the ModemCommand class This exception is allowed to propagate up the call stack to notify the method that invoked initializeLink of the failure to initialize the modem Listing 719 initializeLink and resetModem
QR Creation In VB.NET
Using Barcode generator for VS .NET Control to generate, create QR Code image in VS .NET applications.
public void initializeLink() throws DataLinkException { resetModem(); mcreceiveMatch("RING", null, 0); mcsendCommand("ATA\r", "CONNECT", 25); } private void resetModem() throws DataLinkException { // Clear RTS and DTR spsetDTR(false); spsetRTS(false); try { Threadsleep(2000); } catch (InterruptedException ie) {} // Set RTS and DTR spsetDTR(true); spsetRTS(true); try { Threadsleep(2000); } catch (InterruptedException ie) {} // Sync modem to serial port baud rate mcsendCommand("AT\r", "OK", 6); }
Encode UPC - 13 In Java
Using Barcode drawer for Java Control to generate, create EAN-13 Supplement 5 image in Java applications.
7
Bar Code Encoder In Java
Using Barcode drawer for Java Control to generate, create barcode image in Java applications.
Building a Remote Data Logger
Printing Barcode In Java
Using Barcode encoder for Java Control to generate, create bar code image in Java applications.
Note that depending on the speci c modem you re using, you may have to do more or different work in initializeLink For example, the modems used to test this class all autobaud by default when the AT\r string is transmitted immediately after the DTR reset If your modem initializes to some prede ned hardcoded speed after a DTR reset, initializeLink would have to transmit a command at the prede ned speed, setting the new desired speed Other commands may also be required to correctly reset and initialize the modem After successfully resetting the modem, initializeLink waits for a ring When the modem detects a ring on the phone line, it transmits the string RING initializeLink blocks inde nitely by specifying a time-out value of 0, waiting for this string Once it receives the string, it sends the ATA command to the modem, instructing it to answer the incoming call After answering the phone, the modem will respond with the string CONNECT We allow a 25-second time-out for the modem to answer the phone and respond because this is a time-consuming process It should typically complete within 10 or 15 seconds of ring detection After receiving the CONNECT string from the modem, the communication channel is fully established and initializeLink returns normally The ModemCommand class, partially shown in Listing 720, is a utility class used by PPPModemLink to handle the details of serial communication with the modem It is passed references to the serial port as well as serial port input and output streams for the actual data transfer ModemCommand provides these two public methods
Painting Code 128B In Java
Using Barcode creation for Java Control to generate, create Code 128 Code Set A image in Java applications.
public void sendCommand(String command, String response, int timeout) throws DataLinkException public void receiveMatch(String match, String response, int timeout) throws DataLinkException
Creating ANSI/AIM Code 39 In Java
Using Barcode drawer for Java Control to generate, create ANSI/AIM Code 39 image in Java applications.
The sendCommand method converts command to a byte array and transmits the result over the serial port to the attached modem After transmitting the command string, sendCommand invokes the waitForResponse method (described below) to wait for the modem to transmit a response equal (ignoring case) to the value supplied in response If no response is expected from the modem, null can be supplied for the response String In this case, sendCommand returns immediately after transmitting the command The receiveMatch command has the opposite sense It rst waits for a transmission from the modem equal (again ignoring case) to the supplied value of match and then transmits a response to the modem If nothing is to be transmitted to the modem after receipt of the desired match String, null is passed for the response Both methods throw DataLinkException in the event of a time-out waiting for the desired response
ISSN Creation In Java
Using Barcode drawer for Java Control to generate, create ISSN - 10 image in Java applications.
Barcode Generator In .NET
Using Barcode creation for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Creating Code-39 In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
Generating Bar Code In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Bar Code Maker In VS .NET
Using Barcode generator for ASP.NET Control to generate, create barcode image in ASP.NET applications.