* Help : Asynchronous programming
@ 1998-10-30 5:00 Kim younghan
0 siblings, 0 replies; only message in thread
From: Kim younghan @ 1998-10-30 5:00 UTC (permalink / raw)
Hi
Can anybody help me?
Alpha would like to communicate with Tandem asynchronously via DECserver.
Configuration is
Alpha(Digital UNIX V4.0D) ----LAT----DECserver---Our DSU---9.6k----Their
DSU-------Tandem
Message foramt is
STX(1) + message(98) + ETX(1) + BCC(1)
Problem is
Tandem can receive whole message from Alpha
Alpha can not receive whole message except BCC.
But we can get whole message at behind of Our DSU.
If Tandem send message without ETX(0x03), Alpha can receive a whole
message.
Why?
Here is a my source program.
What's the problem? Please give me a good advice.
Thanks in advance.
mail to : yhkim@boram.co.kr
============================================================================
======
#include <signal.h>
#include <fcntl.h>
#define BUFFSIZE 4096
int sigflag;
typedef struct info_st {
char stx;
char kind[3];
char seqno[7];
char etx;
char bcc;
} INFO;
INFO info;
char inf[14];
main()
{
int fd,n,out;
char buff[BUFFSIZE];
int sigio_func();
int cnt=0;
info.stx = 0x02;
info.etx = 0x03;
info.bcc = 0;
printf("... Before open \n");
if ((fd = open("/dev/tty03",O_RDWR)) == -1) {
printf("... Can't open ttyq1 \n");
exit(1);
}
if ((out = open("bb",O_WRONLY|O_CREAT,0666)) == -1) {
printf("... Can't open aa \n");
exit(1);
}
printf("... Open Successfully \n");
signal(SIGIO, sigio_func);
if (fcntl(fd, F_SETFL, FASYNC) < 0)
printf("F_SETFL FASYNC error \n");
/*
if (fcntl(fd, F_SETFL, O_NDELAY) < 0)
printf("F_SETFL O_NDELAY error \n");
*/
sprintf(inf," %2s%6s ", "J2","000001");
inf[0] = 0x02;
inf[9] = 0x03;
inf[10] = 'A';
inf[11] = 0x0d;
inf[12] = 0x0a;
for(cnt=0;cnt<1;cnt++) {
if (write(1, inf, 13) != 13)
printf("Write error 1\n");
if (write(fd, inf, 13) != 13)
printf("Write error 3\n");
printf("write ok!\n");
sleep(1);
}
write(out,inf,13);
printf("now...receive...\n");
for ( ; ; ) {
sigblock(sigmask(SIGIO));
while (sigflag == 0)
sigpause(0); /* wait for a signal */
/*
* We're here if (sigflag != 0). Also, we know that the
* SIGIO signal is currently blocked.
*/
if (( n= read(fd, buff, BUFFSIZE)) > 0) {
if (write(1, buff, n) != n)
printf("Write error \n");
if (write(out, buff, n) != n)
printf("Write error \n");
printf(".. Received length = %d \n",n);
} else if (n < 0)
printf(" Read error \n");
else if (n == 0)
sigflag = 0; /* EOF */
/* exit(0); EOF */
/* sigflag = 0; turn off out flag */
sigsetmask(0); /* and reenable signals */
}
}
int sigio_func()
{
sigflag = 1; /* Just set flag and return */
/* the 4.3 BSD signal facilities leave this handler enabled for
any further SIGIO signals */
}
============================================================================
======
mail to : yhkim@boram.co.kr
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1998-10-30 5:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-10-30 5:00 Help : Asynchronous programming Kim younghan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox