hi friends,
our group have been alloted a project= on linux where we have communicate with a relay machine using asynchronous= transmission through serial port. we have to use modbus protocol.
so= me of the fuctions that we are supposed to do are: starting / stopping the = relay machine or reading the various parameters to which the relay machine = is conncted.
now, we are able to write to the machine like make it st= art / stop. but when it comes to reading the parameters from the relay mach ine we are not able to and we are not understanding what is going wrong, ma= ybe some of the flags needs to be activated or deactivated and since we are= novices to linux we really can't get through it.
it will be very hel= pful if anyone of you could help us.
we have to use 'c' as the progra= mming language, also the code below is the one that we use and it works suc= cessfully for starting / stopping the machine.
#include<ter= mios.h>
#include<unistd.h>
#include<stdio.h> = #include<fcntl.h>
#define COMPORT "/dev/ttyS0" = int main()
{
int fd,i,n;
int buff3[50];
struct t= ermios options;
int buff[]={0x01,0x05,0x00,0x02,0xFF,0x00,0x2D,0xFA= };//open
int buff1[]={0x01,0x05,0x00,0x00,0xFF,0x00,0x8C,0x3A};//cl= ose
int buff2[]={0x01,0x04,0x00,0x08,0x00,0x13,0x30,0x05};//read
fd = open(COMPORT,O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd,F_SET= F,0);
tcgetattr(fd,&options);
cfsetospeed(&option,B9600= );
cfsetispeed(&option,B9600);
options.c_cflag |= ( CLOCA= L | CREAD );
options.c_cflag &= PARENB;
options.c_cflag &= amp;= ~PARODD;
options.c_cflag &= ~CSTOP;
options.c_cfl= ag &= ~CSIZE;
options.c_cflag &= ~CRTSCTS;
options.= c_cflag |= CS8;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | = ISIG);
options.c_iflag |= ( INPCK | ISTRIP );
options.c_iflag= |= ( IXON | IXOFF | IXANY);
options.c_oflag &= ~OPOST; = options.c_cc[VMIN]=1;
options.c_cc[VTIME]=0;
tcsetattr(f= d,TCSANOW,&options);
tcflush(fd,TCIOFLUSH);
for(i=0;i<= =7;i++)
n = write(fd,&buff1[i],2);
/* for(i=0= ;i<=7;i++)
n = read(fd,&buff3[i],1);
*/ = tcdrain(fd);
close(fd);
return 0;
}
when = we tried on the similar lines and what not prmutations and combinations we = just could not read the parameters. it would either hang or just terminate.= but one thing is pretty sure that the machine is sending some bits as the = LED glows on the machine indicating the same.
please reply as = soon as possible, as we need to get our project done and submit it.
<= BR> thanks.
[1]<= IMG SRC="http://ads.rediff.com/RealMedia/ads/adstream_nx.cgi/www.rediffm a= il.com/inbox.htm@Bottom" BORDER=0 VSPACE=0 HSPACE=0>
References