#include #include #include #include #include "..\lib\7188.h" /* Demo11: Use 7188 COM2 link to 7053(16 D/I) x 2. address 01 : 7053-1, connect to COM2(RS485) of 7188 9600,N,8,1 address 02 : 7053-2, connect to COM2(RS485) of 7188 9600,N,8,1 7188 COM4 link to PC com1(or com2) 5digitled : digit 1 will show channel no digit 2-5 will show the input value */ extern char hex_to_ascii[16]; int ascii_to_hex(char c); int SendCmdTo7000(int iPort, unsigned char *cCmd, int iChksum); int read_7000(unsigned char *cmd); int ReceiveResponseFrom7000(int iPort, unsigned char *cCmd, long lTimeout, int iChksum); /* ------------------------------------------------------------------- */ char OutCmd[10]="@01"; void main() { int i,k; unsigned char c,cmd[80]; int ledmode=1; int quit=0; clock_t start,end,start2; InitLib(); /* driver initial */ InstallCom(2,9600L,8,0,1); /* COM2, RS-485, half-duplex mode, INT */ /* --> need to control 485 direction */ /* --> initial 485 direction = Receive */ /* --> address 1 = 7060 */ /* COM4, RS-232, connect to PC's COM port for download */ Init5DigitLed(); /* initial & blank the 5-digit LED */ LedOn(); /* red-LED on */ start=clock(); Show5DigitLed(1,1); read_7000("$01M"); /* read module name of address 1 */ /* 7053 will echo !017053 */ read_7000("$02M"); /* read module name of address 2 */ /* 7053 will echo !027053 */ printf("\n'1': show channel 1" "\n'2': show channel 2" "\n'q' : quit" "\npress any key to start."); for (;!quit;) { end=clock(); if((end-start)/CLK_TCK >= 0.5){ ledmode=!ledmode; if (ledmode) LedOn(); else LedOff(); start=clock(); } if (kbhit()) { /* is user press PC's keyboard from COM4 */ c=getch(); /* if this key is Q or Q --> exit this program */ if ((c=='q') || (c=='Q')) quit=1; else { if(c=='1'){ OutCmd[2]='1'; /* switch to channel 1 --> @01 */ Show5DigitLed(1,1); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,16); Show5DigitLed(5,16); } else if(c=='2'){ OutCmd[2]='2'; /* switch to channel 2 --> @02 */ Show5DigitLed(1,2); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,16); Show5DigitLed(5,16); } } } else { read_7000(OutCmd); } } RestoreCom(2); return; } /* ------------------------------------------------------------------- */ /* send cmd & receive result to 7000 module */ char *Binary[16]= { "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111", }; int read_7000(unsigned char *cmd) { unsigned char str[20]; int val,data; static unsigned long count=0; count++; SendCmdTo7000(2, cmd, 0); printf("\n[%lu]Send=%s, Receive=",count,cmd); val=ReceiveResponseFrom7000(2, str, 60000L, 0); if (val==NoError) { printf("%s ",str); /* show the I/O value */ data=ascii_to_hex(str[1]); Show5DigitLed(2,data); printf("[%s",Binary[data]); data=ascii_to_hex(str[2]); Show5DigitLed(3,data); printf(" %s",Binary[data]); data=ascii_to_hex(str[3]); Show5DigitLed(4,data); printf(" %s",Binary[data]); data=ascii_to_hex(str[4]); Show5DigitLed(5,data); printf(" %s]",Binary[data]); } else printf("Errorno=%d(%s)",val,val==TimeOut?"TimeOut":""); return val; }