EmbeddedLinuxPC RS422/485 <-> Siemens S7-200

E

Thread Starter

Ernst Murnleitner

Dear Readers,
I want to connect a Linux PC with a Siemens S7 200 CPU with RS485 instead of RS232+PC/PPI Adaptor.

The first devise is an embedded PC with Linux (TRM/816 from www.ssv.de). This PC has a RS232 and a RS422/485 interface (only one can be active - which can be selected by means of two jumpers). The RS422/485 has only 2 pins: TX+/RX+ and TX-/RX-.

The second device is a Siemens S7-200 CPU 222.

This works already:
I connected the RS232 of the PC with the RS485 of the PLC by using the RS232/RS485 PC/PPI adaptor from Siemens. Now, I can read and write strings to and from the PLC. On the PC I use posix functions and on the PLC I programmed something that I can answer to the commands. This works fine with 9600 Baud (8,n,1, no handshake). Using 38400 Baud, there are sometimes errors.

This does not work:
I replaced the PC/PPI adapter and connected the RS485 interfaces directly. I thought, this would work without changes. But it didn't.

One time I connected the TX/RX+ to Signal B of the PLC(+) and TX/RX- to Signal A. The other time I changed it (TX/RX+ to A, TX/RX- to B).

My questions:
Why does it not work? Do I have to use other communication protocolls and/or settings?

I hope, somebody can help me.
Many thanks in advance
Ernst Murnleitner
 
I

Israel Cabrera G.

Ok here it goes....

What I understood from all this are the next
facts:

1) You have a Rs232-Rs485 converter from Siemens.
right?
2) You connected the Rs232 port from the PC to
the Siemens converter and the siemens rs485
port to the PLC. right??

3) Why are you connecting a (rs232 to rs485)
converter to the PC if the PC
already have a rs485 port?
You said that the direct connection between
the PC and the PLC without the converter
dosen't work.. ahh?? ok...


Here are the possible solutions:
a) The Rs485 connection needs 3 wires:
A, B and GROUND!!
you might be forgetting the ground uhh?

b) What class of wire are you using??
It's supposed that UTP can transsmit
at speeds of 1Mb/s in twisted pair in
lenghts of about mmm... 100mts.
and about 9600bps in lenghts of 1Km.
(sorry about the convertion units
I'm in Mexico) =)

c) Of course YOU DON'T need to change
your protocol, in linux something like
the next code will configure the serial
port for no handshake, no CTS/RTS and
echo:

#define SERIALPORT /dev/ttyS0

fd = open(SERIALPORT, O_RDONLY | O_NOCTTY |
O_NONBLOCK);
if (fd <0)
{
printf("Sorry, Serial port: %s is
unavailable",SERIALPORT);
exit(-1);
}

printf("\nReceiver UP!");

saio.sa_handler = signal_handler_IO;
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGIO,&saio,NULL);

fcntl(fd, F_SETOWN, getpid());
fcntl(fd, F_SETFL, O_ASYNC);
tcgetattr(fd,&oldtio);

newtio.c_cflag = SPEED | CS8 | CREAD | CLOCAL;
newtio.c_iflag = IGNBRK | IGNPAR ;
newtio.c_oflag = ONOCR | ONLRET;
newtio.c_lflag = 0;
newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=0;
tcflush(fd, TCIOFLUSH);
tcsetattr(fd,TCSANOW,&newtio);


d) the above code help me in a RT Data
acquisition project with rs485 specs.

e) Any comments?? email me at:
[email protected]

Saludos!
 
E

Ernst Murnleitner

Dear Israel,
thank you very much for your answer.

> Here are the possible solutions:
> a) The Rs485 connection needs 3 wires:
> A, B and GROUND!!
> you might be forgetting the ground uhh?

Yes, I didn't connect the ground. I thought it is not necessary, because the single board computer does not have a ground pin. It has only 2 wires: TX+/RX+ and TX-/RX-. But the Siemens S7-200 has a ground pin on the connector.

So I connect TX+/RX+ on the PC to the TX+/RX+ on the Siemens S7-200. And the same with TX-/RX-.
But what about the GND? Is it sufficient, if I connect the GND on the Siemens PLC with the GND of the power supply?

> b) What class of wire are you using??
> It's supposed that UTP can transsmit at speeds
> of 1Mb/s in twisted pair in >lenghts of about
> mmm... 100mts. >and about 9600bps in lenghts of
> 1Km. >(sorry about the convertion units I'm in
> Mexico) =)

I thought it is not important as I had only 1 m distance. I used only two 0.5 mm2 cables without any shielding.

> c) Of course YOU DON'T need to change your
> protocol, in linux something like the next code
> will configure the serial port for no
> handshake, no CTS/RTS and echo:

I used simular settings.

> #define SERIALPORT /dev/ttyS0
> fd = open(SERIALPORT, O_RDONLY | O_NOCTTY |
> O_NONBLOCK);

Here, I didn't use O_NONBLOCK.

> saio.sa_handler = signal_handler_IO;

I didn't use a callback function.

> saio.sa_flags = 0;
> saio.sa_restorer = NULL;
> sigaction(SIGIO,&saio,NULL);
> fcntl(fd, F_SETOWN, getpid());
> fcntl(fd, F_SETFL, O_ASYNC);
> tcgetattr(fd,&oldtio);

I didn't use and fcntl(...). Is it only necessary with a callback function?

> tcflush(fd, TCIOFLUSH);

Here, I used TCIFLUSH. I changed it to TCIOFLUSH now.

Greetings
Ernst Murnleitner
 
H

Hakan Ozevin

Did you place some terminating resistors in the RS485 converter? These resistors are already integrated in PC/PPI cable. Otherwise, I dont see any reason either.
 
Top