/*
 *  send_read.c
 *
 *  v 0.0 2015.1.7 by Golden Wang
 *
 *  open port, then quest the name of ICP DASDCON's module 01
 *
 *  History
 *
 *  v 0.0 2015.1.7 by Golden Wang
 *    create, ... ok, i keep this as simple as possible
 */

// #define I7K_DEBUG
#include "msw.h"
#include "i7k.h"
#include "i7000.h"

#define RCVBUF_SIZE 16

int main(int argc,char **argv)
{
	int fd,rs;			/* file descriptor */
	char *cmd;			/* point to command string */
	char rbuf[RCVBUF_SIZE];		/* receive buffer */
	__tod_t texp;			/* to receive the expended time */
	int comport, baud;
	int timeout = 1;
	WORD wT;
	int c;

        while((c=getopt(argc, argv, "b:u:")) != -1)
        {
                switch(c)
                {
                        case 'b':
				baud = atoi(optarg);
                                break;

                        case 'u':
                                comport = atoi(optarg);
                                break;

                        case '?':
                                printf("wrong command\n");
                                break;
                }
        }

	rs = Open_Com(comport, baud, Data8Bit, NonParity, OneStopBit);

	if (rs > 0) 
	{
		printf("open port failed!\n");
		return -1;
	}

	cmd = "$01M\r";

        rs = Send_Receive_Cmd(comport, cmd, rbuf, timeout, 0, &wT); 

	printf("COM%d Send    Command = %s \n", comport, cmd);
	printf("COM%d Receive Command = %s \n", comport, rbuf);

        if (rs)
                printf("Send Receive Command, Error Code=%d\n", rs);

	Close_Com(comport);

	return 0;
}
