www.pudn.com > 422.rar > wr.c
#include#include #include #include #include #include "../include/serial.h" int main(void) { struct serialmsg_t sendmsg[3]={{6,{10,11,12,13,14,15}},{7,{1,15,14,13,12,11,10}},{15,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}}}; struct serialmsg_t readmsg;//={{0,0,0,0,0,{0}},}; int fd,fd1,ret,ret1,i=0,j,k,n; if ((fd=open("/dev/tts2",O_RDWR)) < 0 ) { perror("open"); printf("Error opening /dev/tts0\n"); exit(1); } ret=ioctl(fd,CONF_BAUD,115200); //ret=ioctl(fd,CONF_FILTER,0x030e); printf("open tts0!!!!!!!!!!!!\n"); if ((fd1=open("/dev/tts3",O_RDWR)) < 0 ) { perror("open"); printf("Error opening /dev/tts1\n"); exit(1); } ret=ioctl(fd1,CONF_BAUD,115200); printf("open tts1!!!!!!!!!!!!\n"); // else printf("open /dev/can is ok!\n"); j=0; for(k=0;k<3;k++) { if ((ret=write(fd,&sendmsg[k],sizeof(struct serialmsg_t))) < 0) { perror("write"); printf("tts0 Error sending message\n"); break; } ret=-1; usleep(500000); printf("sent block of %d messages!\n",k+1); ret1=read(fd1,&readmsg,sizeof(struct serialmsg_t)); if(ret1<0) { perror("write"); printf("tts1 Error sending message\n"); break; } else { printf("read is OK!!!!!!!!!!\n"); printf("Received message %d: length=%d\n",k+1,readmsg.length); for(n=0 ; n