#include <dos.h>
#include <io.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#define TIME_OUT 10000000
static int base0=0x3f8; /* Port 1 base address (COM1) */
static int base1=0x2f8; /* Port 2 base address (COM2) */
static char rec[8]; /* Receive buffer */
static char cmd[20]; /* Command buffer */
static char rab[20];
static char bd[8]={'#','0','4','0','0','0','8',0x0d};
static char bdrab[5]={0x23,0x04,0x00,0x07,0x0d};
int sravn(char rab[20])
{
int i=0;
{
if (rab=='0')
{
return(0);
}
else if (rab=='m')
{
return(2);
}
else if (rab=='q')
{
return(3);
}
else if (rab=='r')
{
return(4);
}
else if (rab=='b')
{
return(5);
}
else
{
if (rab=='s')
{
return(1);
}
}
}
}
void main()
{
int i;
int r=0;
int timeout; /* counter for timeout */
int flag;
/* Set up Port 1 (COM1) */
outport((base0+2),0x01); /* enable FIFO */
outp(base0+3,0x80); /* set DLAB=1 */
outp(base0 ,0x012); outp(base0+1,0x0); /* set buad = (115200)9600 */
outp(base0+3,0x03); /* set data=8 stop=1 no parity */
outp(base0+1,0x00); /* disable COM1 interrupt */
/* Set up Port 2 (COM2) */
outport((base1+2),0x01); /* enable FIFO */
outp(base1+3,0x80); /* set DLAB=1 */
outp(base1 ,0x012); outp(base0+1,0x0); /* set buad = (115200) 9600 */
outp(base1+3,0x03); /* set data=8 stop=1 no parity */
outp(base1+1,0x00); /* disable COM2 interrupt */
VV: printf("\n Vvedite comandu \n");
gets(rab);
sravn(rab);
if (sravn(rab)==1)
{
printf("\n Vruchuyu stroku(Stroku) ili iz Bazu Dannuh(Baza)?");
gets(rab);
if (sravn(rab)==1)
{
goto SEND;
}
else if (sravn(rab)==5)
{ /*****BD*************************/
/* Send string on Port 1 (COM1) */
r=0;
i=0;
flag=1;
while (flag)
{
outportb(base0,bd); /* Send data */
if (bdrab == 0x0d)
flag=0;
i++;
r=1;
}
goto VV;
}
}
else if (sravn(rab)==2)
{
printf("\n ********************************************************************");
printf("\n **********MANUAL po komandam programmu******************************");
printf("\n **********Man(manual, etc.)->Vuvodit etot tekst*********************");
printf("\n **********Send(snd.,etc.)->Otpravit komandu na kontroller***********");
printf("\n **********Stroku(Str.,etc.)->Vvod stroki dlya otpravki vruchnuyu8***");
printf("\n **********Baza(BD.,etc.)->Otpravka komandu iz Bazu Dannuh komand****");
printf("\n **********Receive(etc.)->Priem dannuh*******************************");
printf("\n **********q(guit,etc.)->Exit****************************************");
printf("\n ********************************************************************");
goto VV;
}
else if (sravn(rab)==3)
{
return;
}
else if (sravn(rab)==4)
{
goto RECEIVE;
}
else
{
printf("\n Komanda ne opoznana");
goto VV;
}
SEND: printf("\nEnter string (max 15 char) or Q to quit:");
gets(cmd);
while (cmd[0] != 'q' && cmd[0] != 'Q')
{
/* Send string on Port 1 (COM1) */
i=0;
cmd[strlen(cmd)] = 0x0d;
flag=1;
while (flag)
{
outportb(base0,cmd); /* Send data */
if (cmd == 0x0d)
flag=0;
i++;
}
/* Receive data on Port 2 (COM2) */
RECEIVE: i=0;
flag=1;
timeout=TIME_OUT;
while (flag)
{
/* Check for received data on port 2 */
IF: if ((inportb(base1+5) & 1) !=0)
{
rec=inportb(base1); /* Receive data */
if (rec == 0x0d)
{
rec[i+1]='\0';
flag=0;
printf("\nReceived data : %s\n",rec);
}
i++;
}
else
{ /* Check timeout */
timeout--;
if (timeout == 0)
{
flag = 0;
printf("\nTimeout error\n");
}
}
} /* End of receive data while() */
goto VV;
} /* End of "Enter string" while() */
} /* End of main() */
Привожу листинг программы, основанной на Example1, поставляемом в комплекте с ADAM4500, программа посылает данные на порт, данные(проверил) "достигают" ADAM4060, но реакции никакой, я считаю, что возможно неправильный синтаксис, какие будут мнения?...