package serial;


/*-----------------------------------------------------------------------------
 * File: SendData.java
 * Function: Example to send data out the serial port
 *
 * Copyright (c) 1997,1998 Solutions Consulting, All Rights Reserved.
 *---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
 * Solutions Consulting makes no representations or warranties about the
 * suitability of the software, either express or implied, including but
 * not limited to the implied warranties of merchantability, fitness for
 * a particular purpose, or non-infringement. Solutions Consulting shall
 * not be liable for any damages suffered by licensee as a result of
 * using, modifying or distributing this software or its derivatives.
 *---------------------------------------------------------------------------*/

import java.io.*;
import Serialio.*;

class SendData {
	static String banner = "Copyright (c) 1997,1998 Solutions Consulting, All Rights Reserved.";
	static String ver = "SendData Ver 1.1";

	public static void main(String args[]) {
	SerialPortLocal sp;
	String devName = "";

	if (args.length == 0){
		PrintUsage();
		System.exit(1);
	}
	else {
		devName = args[0];
	}

	try {
    	SerialConfig serCfg = new SerialConfig(devName);
		sp = new SerialPortLocal(serCfg);
		sp.setTimeoutRx(1000);
		int verLib = sp.getLibVer();
		short vMajor = (short)(verLib >> 16);
		short vMinor = (short)(verLib & 0xffff);
		System.out.println("DLL version: "+vMajor+"."+vMinor);
		System.out.println("\nSending data...");
		for (int i = 0; i < 256; i++) {
			System.out.println("Sending "+i);
			sp.putByte((byte)i);
		}
	}
	catch (Exception ioe) {
		System.out.println(ioe);
		System.exit(1);
		}
}

	static int PrintUsage() {
		System.out.println(ver);
		System.out.println(banner);
		System.out.println("\nThis program sends values 0-255 out the serialport.");
		System.out.println("The parameters are 9600 bps, No Parity, 8 data bits, 1 stop bit.");
		System.out.println("\nEnter the serial device name as the first parameter.");
		System.out.println("To use COM2, enter this command: java SendData COM2");
		System.out.println("\nIf you use JavaTerm on the receiving end, click \"Show Hex\"");
		System.out.println("and you should see the values 0-FF displayed");
		System.out.println("in the JavaTerm receive textarea");
		return 0;
	}
}
