background image

ADAM-454114542     User's Manual 

 

  

Example Program  

 

 

The  following  program can be used as a diagnostic test for the ADAM-454114542. It will  transmit a string to  
COM1 and also  receive a string from COM1 of the computer (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; 

Signal Wiring 

When you run the eXample  program, connect 
the ADAM-454114542 terminals as follows: 
 

 

P C  

 

R x  

static char rec[160]; 

static char cmd[160]; 

void main () 

RS-232/422  

ADAM-4541  

Tx  

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); 

Reviews: