/* ----------------------------------------------------------- */ /* demo 4 : test RS-232 port (single VXC-182I + PC-COM1) */ /* step 1 : RS-232 port of vxc182I connect to COM1 of PC */ /* step 2 : run DEMO4.EXE */ /* NOTE : using polling (TxD==>RxD) */ /* ----------------------------------------------------------- */ #include "..\PIO.H" #include "..\VxCard.h" #define COM1 0x3f8 #define COM2 0x2f8 #define COM3 0x3e8 #define COM4 0x2e8 WORD wBase,wIrq,wBase0,wBase1; WORD wT=32000; int main() { int t,tt,i,j,ii,jj,k; char c, bSpeedMode; char cCmd[50]; int iRet,iComPort; DWORD dd; WORD wSubVendor,wSubDevice,wSubAux,wSlotBus,wSlotDevice; WORD wBoards,wRetVal,t1,t2,t3,t4,t5,t0,tt0,tt1,wA0,wA1; clrscr(); /* step 1: find address-mapping of PIO/PISO cards */ wRetVal=PIO_DriverInit(&wBoards,0x161,0x01,0x00); /* for VXC-182I */ printf("\nThrer are %d VXC-182I Cards in this PC; Ret=%d",wBoards, wRetVal); if (wBoards==0) return 1; printf("\n--------------- The Configuration Space ---------------"); for(i=0; i "); ShowPioPiso(wSubVendor,wSubDevice,wSubAux); } PIO_GetConfigAddressSpace(0,&wBase0,&wIrq,&t1,&t2,&t3,&t4,&t5); /* step 2: enable all D/I/O port */ outportb(wBase0,1); /* enable D/I/O */ Vxc_SetConfig(wBase0, VXC_182i_CONFIG); /* for VXC-142/142i/182i */ Vxc_SetSpeedMode(wBase0,1,VXC_LOW_SPEED); /* low speed */ /* step 3: select RS-485 or RS-232 port */ wA0=wBase0 + VXC_PORT2; iRet=Vxc_OpenCom(wA0, 115200L, "8N1"); /* RS-232 of VXC-182I=115200 */ if (iRet==0) printf("\n\n(1) Open card_0 OK"); else printf("\niRET=%d",iRet); iRet=Vxc_OpenCom(COM1, 115200L, "8N1"); /* RS_232 of PC-COM1=115200 */ if (iRet==0) printf("\n\n(1) Open PC COM OK"); else printf("\niRET=%d",iRet); i=0x55; j=0xaa; for (;;) { t0=0; t1=0; tt0=0; tt1=0; for (;;) { if ( t0<32 ) { if ( 0 == Vxc_SendChar(COM1, i, 2) ) /* PC-send=polling */ t0++; } if ( t1<32 ) { if ( 0 == Vxc_SendChar(wA0, j, 2) ) /* vxc-182-send=polling */ t1++; } if ( 0 == Vxc_ReceiveChar(wA0, &k, 2) ){ /* vxc-182-receive=polling */ if (k!=i) { printf("[Err0, %2x, %2x]", k, i); return 0; } printf("[tt1=%d]",tt1); tt1++; } if ( 0 == Vxc_ReceiveChar(COM1, &k, 2) ){ /* pc-receive=polling */ if (k!=j) { printf("[Err1, %2x, %2x]", k, j); return 0; } printf("[tt0=%d]",tt0); tt0++; } if ((tt0>=32) && (tt1>=32)) break; } i++; i=i&0xff; j++; j=j&0xff; if (kbhit()!=0) {getch(); break;} printf("\n[%2x, %2x]",i,j); } PIO_DriverClose(); return 0; }