User Manual
ADAM-4541 User's Manual
Example Program
This program can be used as a diagnostic test for the ADAM-4541. It will transmit a string to COM1 and then
receive a string from COM1 (a loop-back test).
Program: LOOPBACK.C
#include <dos.h>
#include <io.h>
#include <stdio.h>
#include <conio.h>
#define TIME OUT 4000
static int base0=0x3f8;
static int base1=0x2f8;
static char rec[160];
static char cmd[160];
void main ()
{
int i,timeout;
char rflag,tflag;
bioscom(0,0xE3,0); /* Set COM1 as follows: Baud Rate = 9600, Data Bits = 8, */
printf("\nInput string : "); /* Parity = none, Stop Bits = 1 */
gets(cmd);
while (cmd[0] != 'q' && cmd[0] != 'Q')
{
cmd[strlen(cmd)] = 0x0d;
i=0;
tflag=1;
while (tflag)
{ /* Send data */
outportb (base0,cmd[i];
while ((inportb(base0+5) & 32) !=32);
rflag=1;
timeout=TIME_OUT;
while (rflag)
{ /* Check received data */
if ((inportb(base0+5) & 1) !=0)
{ /*Receive data */
rec[i]=inportb(base0);
if (rec[i] == 0x0d)
{
rec[i+1]='\0';
printf("\nReceived data : %s\n,rec);
tflag==0;
}
rflag=0;
}
else
{ /* Check timeout */
timeout--;
if (timeout == 0)
{
printf("Timeout error");
rec[i+1]='\0';
rflag=0;
tflag=0;
}
}
}
i++;
}
printf("\nInput command : ");
gets(cmd);
}
}
Signal Wiring
When you run the example program, you must
connect the ADAM-4541's terminals as follows:
Rx
Tx
PC
ADAM-4541ADAM-4541
RS-232/422




