Hi everyone?
I have tried to finish rs485 communication with a sensor in DM368 IPNC.
I found that our DM368 can send data (write) to the sensor, but can't receive data(read).
I tested the sensor in PC, it worked well. I tested between DM368 and PC. It showed the same problem.
Do it support just data sending?
I tested with the following codes.
I'd appreciate it if you share me some hint on that.
Best regards,
Hyunsik
========================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <termios.h>
#include <fcntl.h>
void rs485com()
{
int i, fd;
struct termios newtio;
unsigned char buf1[20],buf2[20];
buf1[0] = 0x02;
buf1[1] = 0x30;
buf1[2] = 0x31;
buf1[3] = 0x52;
buf1[4] = 0x30;
buf1[5] = 0x03;
buf1[6] = 0x62;
fd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK );
memset( &newtio, 0, sizeof(newtio) );
newtio.c_cflag = B9600;
newtio.c_cflag |= CS8;
newtio.c_cflag |= CLOCAL;
newtio.c_cflag |= CREAD;
newtio.c_iflag = 0;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 11;
newtio.c_cc[VMIN] = 1;
tcflush (fd, TCIFLUSH );
tcsetattr(fd, TCSANOW, &newtio );
write( fd, buf1, 7);
read(fd,buf2,11);
for(i=0;i<11;i++) printf("%d>%x " ,i,buf2[i]);
printf("\n");
///usleep(500);
close( fd);
return;
}