/*
7K87K.c: This demo program is for 7K and 87K module general function.      
         1. User must use DCON Utility to set Address, Baudrate,CheckSum
            before running the demo.        	                         
         2. If user uses Com2 in the 8410,8411,8810 and 8811,
            user will must to add AddCom2Fun().
    
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: 87K_demo.c                                                               
         ..\Lib\(7188xa/b/c.lib,8000.Lib, 8000E.lib)   
                                                                               
Hardware: 7188/8000 <== COM port ==> 7K or 87K modelue

[24 May,2005] by Bill
*/

#include"..\..\lib\vp2k.h"
/*
=== English comments ==========================================
This demo program is for all functions of 7k and 87K I/O modules .
Users can refer the demo to excute every commands list in 7k and
 87K I/O module's document. For example: $AAM, #AA, @AA, @AA6... etc.

If users wants to use AI,AO,DI,DO,DIO, we have prepared several
demos. Uers can copy the code from these demos then paste to 
their own program.

=== Chinese comments ==========================================
這個範例是針對 87K I/O 模組的全部功能。
使用者可以參考此範例來使用每一個 87K I/O 模組命令手冊中的功能。
例如 $AAM, #AA, @AA, @AA6... 等等。

假如使用者要使用 AI, AO, DI, DO, DIO 這些功能，我們已經準備了
數個現成的範例程式。你可以將這些程式碼直接複製到你的程式中來使用。
*/
void main()
{
	unsigned char InBuf[20];   
    int iRet;
    //Step 1:
    InitLib();
    
    //if user uses Com2 in the 8410,8411,8810 and 8811, 
    //user will must to add AddCom2Fun(). 
    //AddCom2Fun();
    
    InstallCom(2,115200,8,0,1); //(Baudrate,Data bit,Parity bit,Stop bit)

    //Step 2:
    SendCmdTo7000(2,"$05M",0); 
        /*
        COM2, Command="$AAM" which AA=01,Checksum=disabled
        
        For example: command="$01M" ===> Gets module name at address 01.
        For detailed command sets,refer to 
            CD:\Napdos\DCON\IO_Module\hw_dcon_on_87kUnit or 
            CD:\Napdos\7000\Manual\ 
        */
        
    //Step 3:
    ReceiveResponseFrom7000_ms(2,InBuf,100,0); 
        /*
        COM2, 
        Put received data to InBuf
        Timeout=100 ms
        Checksum=disabled
        */ 
    
    //Step 4:
    Print("InBuf=%s",InBuf);
        
    //Step 5:
    RestoreCom2();        
}