Hi,
I am developing a C program to communicate with a power meter which supports RS485 Serial Communication using modbus protocol.The device has a 9-pin port available on it.I am using serial to usb convertor (pl2303 converter from Prolific Technology Inc) on my laptop to connect with the device.
I am able to communicate with the device,but the response data i get from the device is nowhere near the expected values.
So My doubts are
1)whether I need to enable anything special on the software side for enabling RS485 communication?
2)Also is there seperate USB to Serial convertors for RS232 and RS485?
3)Is there any difference in the cables to be used for RS232 and RS485?
The program I am using have been tested succesfully for RS232 Communications earlier.
Here is the code snippet i am using for communication
Code:
fserial = open(port_name,O_RDWR | O_NOCTTY);
fcntl(fserial, F_SETFL, 0);
fcntl(fserial, F_SETOWN, getpid());
tcgetattr(fserial,&save_settings);
bzero(&new_settings, sizeof(new_settings));
new_settings.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;//9600bps
new_settings.c_oflag = 0;
tcflush(fserial, TCIOFLUSH);
tcsetattr(fserial,TCSANOW,&new_settings);
I am reading data using a thread with the aid of select system call.
I am not using RTS/CTS mode, although the pins are wired in the cable.
The device is continuously sending back data in response to the data i am writing to it.If i change any of the parameters like speed,parity etc,the device wont respond.That means the parameters i am using should be correct.
I am using an Ubuntu 12.04 LT system.
My kernel version is as follows
uname -a
Linux Satellite-C850 3.5.0-39-generic #60~precise1-Ubuntu SMP Wed Aug 14 15:28:09 UTC 2013 i686 i686 i386 GNU/Linux
Below is the log data(in Hex) i am senting to port
WRITE DATA 11 03 00 00 00 02 C6 9B TO /dev/ttyUSB0
Below is the log data(in Hex) i am getting from port.
The below two lines are coming one after another.
READ DATA 00 FROM /dev/ttyUSB0
READ DATA 77 7E 1F FC 34 51 A3 47 00 FROM /dev/ttyUSB0
The actual expected data is 11 03 04 00 00 5D E6 52 E8
If anybody have any ideas about this,kindly respond.
Thank You Very Much for your time.
regards,
sree