This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RS485 port of DM368 can receive data from PC?


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

  • Hi Hyunsik,

    1. I suggest you as very first step to check the returned value of read(fd,buf2,11); function.

    for example:

    ssize_t bytes_read;
    bytes_read = read(fd, &buf2, 11);

    Then check the bytes_read.

    2. Could you try with blocking reading instead of blocking because it is not sure whether the PC sends data just at this moment.

    3. You can see a 'c' example for RS-485 at:

    www.acmesystems.it/rs485

    BR

    Tsvetolin Shulev