/* 
InOut.c : InOut.c demo for how to Read/Write the byte data via COM port.         

Compiler: BC++ 3.1, 
          Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum)
          MSC 6.0,
          MSVC 1.52.
          
Compile mode: large

Project: Slv_COM.c
         ..\..\Lib\(8000E.Lib,7188XAL.Lib,7188XBL.Lib,7188XCL.Lib or 7188EL.Lib) 

Detail description:
    This demo use block style loop to read data from COM Port,and exit the loop if 
    hit the ESC key.
    
    ToCom and ToComBufn will write Byte data to COM port,
    ToComStr will Send out a string(end with '\0') to COM port.
    In this demo,it also show how to use diffenent format of Byte data,
    such as unsigned char data(ASCII) 'A' will represent as 0x41 in hex format 
    or 65 in decimal format.

Hardware: 7188/8000

[May,19,2005] by Martin
*/


#include<stdio.h>                                                
#include<conio.h>                                                
#include"..\..\lib\vp2k.h"                                          
                                                                 
void main(void)                                                  
{                                                                
 unsigned char outBuf[100];
 int i;
    InitLib();
    InstallCom(1, 115200L,8, 0, 1);   
    ToComBufn(1,"Use ToCom(port,char)\n",21); 
    
    //ASCII
    outBuf[0]= 'A';
    outBuf[1]= 'B';
    outBuf[2]= 'C';
    outBuf[3]= 'D';
    
    // Hex -> ASCII visible character
    outBuf[4]=0x31;  //0x31 = '1'
    outBuf[5]=0x65;  //0x65 = 'e'
    
    // DEC -> ASCII visible character
    outBuf[6]=57;    //  57 = '9'
    outBuf[7]=43;    //  43 = '+'
    
    // Hex -> ASCII not visible character    
    outBuf[8]=0x07;  //0x07 = bell
    outBuf[9]=0x0A;  //0x0A = LF (line feed)
    
    
    // use ToCom(port,char) to send 1 byte to COM Port one by one.
    for(i=0;i<10;i++)
    {
        ToCom(1,outBuf[i]);    
    }     
    Delay(3000);
 
    ToComBufn(1,"Use ToComBufn(port,charBuf,bytes)\n",31); 
    
    // use ToComBufn(port,charBuf,bytes) to send an array to COM Port at a time.
    ToComBufn(1,outBuf,10);   
    
    printCom(1,"Now please hit any key to show the ASCII Table,\n");
    printCom(1,"Hit the ESC to exit the program !\n");

    for(;;)                                                         
    {                                                              
        unsigned char item;                                      
        if(IsCom(1))                                                  
        {                                                            
            item=ReadCom(1);  
            if(item==0x1B) //"Hit the ESC to exit the program"                                              
            {                                                             
                RestoreCom(1);                                               
                return;                                                     
            }
            else
            {                                                  
                printCom(1,"ASCII(%c);Hex(%02X);DEC(%03d)\n\r",item,item,item); 
            }                                      
        }                            
    }                                                              
}                                                      