Author Topic: Swap bytes in profibus communication with Siemens CPU  (Read 2053 times)

JKN

  • Guest
Swap bytes in profibus communication with Siemens CPU
« on: August 20, 2010, 10:48:04 AM »
Hi Guys

I have a problem with Swapping my bytes from/to my Siemens PLC. My PLC is master and the robot is slave no. 8. The profibus communication is running and tested with bit communication. When i write 1 in the PLC output word I recieve 256 int the robot.......

IOSYS.INI:
[PBMASL]
;Input from PLC
inw20=127,0,x2
;Output to PLC
outw20=127,0,x2

PFBMS.INI:
[SWAP]
INWORD_SLAVE_127=2
OUTWORD_SLAVE_127=2

Someone who has an answer on this problem?
Thanks JKN.

Offline RAS-Skordos GR

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 17
  • Posts: 203
    • Robotics & Automation Systems Greece
Re: Swap bytes in profibus communication with Siemens CPU
« Reply #1 on: August 20, 2010, 11:06:58 AM »
Hi there,

I don't have a direct answer to your question, but it might give you a hint.
I had a similar problem a long time ago with an Omron PLC.
If I remember correctly there is an incompatibility between the Intel and the Motorola standards. Anyway, there was a relevant choice in the configuration menu of the Omron...not the robot. Once I swapped it from there, the prob was solved.
While waiting for others to answer, you might want to take a look towards that direction.

Best regards

JKN

  • Guest
Re: Swap bytes in profibus communication with Siemens CPU
« Reply #2 on: August 20, 2010, 12:05:41 PM »
Thanks, but Siemens don't have the feature to swap the byte's :hmmm:

Offline SkyeFire

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 13
  • -Receive: 413
  • Posts: 3270
Re: Swap bytes in profibus communication with Siemens CPU
« Reply #3 on: August 20, 2010, 12:20:29 PM »
Yep, this is a regular problem.  As long as your data words are no larger than 8bit, you're fine.  But Siemens and KUKA follow different standards (originated in the Microprocessor Wars between Intel and Motorola back in the 1970s) about how the bytes in a 16-bit word are arranged.

In a KUKA, a 16bit word looks like this:  Bit16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1

In a Siemens PLC, it looks like this:        Bit8,7,6,5,4,3,2,1,16,15,14,13,12,11,10,9

It's nutty, but there you go.

So, how to fix this?  There's more than one way.  Usually I just use a standard Siemens S7 logic block that converts multi-byte data words to the "correct" order before sending to, or after receiving from, the robot.

It can also be fixed by changing your Profibus config file -- not PFBMS.INI, but the .LDB file created using the Siemens NC software.  Or, we could even fix it by adroit manipulation of IOSYS.INI.

But you're trying to do it the "right" way, using the [SWAP] section in PFBMS.INI.  My guess is that you have something like this in your program code:
Code: [Select]
SIGNAL InputWord0 = $IN[161] TO $IN[176]
SIGNAL InputWord1 = $IN[177] TO $IN[192]

I'm trying to remember, but I believe that the offset value in the SWAP assignment is byte, not word.  So your SWAP assignment would correct the byte-swapping on InputWord1, but not on InputWord0.  You may need a SWAP assignment that looks like this:
Code: [Select]
INWORD_SLAVE_127=0,2
or
INWORD_SLAVE_127=0
depending on what you're doing with the other 16 bits.

Ah.  I found it.  Okay, your problem is that SWAP only works on data words that have been created as exactly 16bits in size.  Your IOSYS.INI assignment creates a single 4-byte 32bit word.  You need to do this:
Code: [Select]
INW20 = 127, 0
INW22 = 127, 2
OUTW20 = 127, 0
OUTW22 = 127, 2

That should do it.

Offline Tiago_Tre

  • Newbie
  • *
  • Thank You
  • -Given: 11
  • -Receive: 3
  • Posts: 10
Re: Swap bytes in profibus communication with Siemens CPU
« Reply #4 on: August 23, 2010, 10:00:40 PM »
Hi JKN!

Yes, in the SIEMENS Step 7 you can Swap the bytes!
Use the STL instrution CAW

Example:

L MW100
CAW
T QW100

But is another solution!

I have done this aplication four times and never I needed use CAW function because in the KRC, in the pfbms.ini, I put a ; in front of [SWAP]. Try this  :n1:

Best regards!

Offline Tiago_Tre

  • Newbie
  • *
  • Thank You
  • -Given: 11
  • -Receive: 3
  • Posts: 10
Re: Swap bytes in profibus communication with Siemens CPU
« Reply #5 on: August 23, 2010, 10:02:34 PM »
ops! I disable the [SWAP], I do not remember how to do it (but in the end it works!)