FileDocCategorySizeDatePackage
CommPortModem.javaAPI DocExample1754Sun Apr 11 19:50:40 BST 2004None

CommPortModem

public class CommPortModem extends CommPortOpen
Subclasses CommPortOpen and adds send/expect handling for dealing with Hayes-type modems.
author
Ian F. Darwin, http://www.darwinsys.com/

Fields Summary
protected String
response
The last line read from the serial port.
protected boolean
debug
A flag to control debugging output.
Constructors Summary
public CommPortModem(JFrame f)


	  
		  
			 
		super(f);
	
Methods Summary
protected booleanexpect(java.lang.String exp)
Read a line, saving it in "response".

return
true if the expected String is contained in the response, false if not.

		response = is.readLine();
		if (debug) {
			System.out.print("<<< ");
			System.out.print(response);
			System.out.println();
		}
		return response.indexOf(exp) >= 0;
	
protected voidsend(java.lang.String s)
Send a line to a PC-style modem. Send \r\n, regardless of what platform we're on, instead of using println().

		if (debug) {
			System.out.print(">>> ");
			System.out.print(s);
			System.out.println();
		}
		os.print(s);
		os.print("\r\n");

		// Expect the modem to echo the command.
		if (!expect(s)) {
			System.err.println("WARNING: Modem did not echo command.");
		}

		// The modem sends an extra blank line by way of a prompt.
		// Here we read and discard it.
		String junk = is.readLine();
		if (junk.length() != 0) {
			System.err.print("Warning: unexpected response: ");
			System.err.println(junk);
		}