Forums.MrPLC.com: How to read SINT (short signed Integer) with CJ2 PLC - Forums.MrPLC.com

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to read SINT (short signed Integer) with CJ2 PLC Rate Topic: -----

#1
User is offline   Nicolas 

  • Sparky
  • PipPipPip
  • Group: MrPLC Member
  • Posts: 14
  • Joined: 10-August 09
  • Location:Houston TX
  • Country:United States
    United States
I am reading some joystick data over CAN-OPEN, all analog values are 8 bit signed integers or Short Int. I know the first bit is the sign...
I can't find an easy way to read that Signed 8 Bit integer value into cx-programmer, using PLC instructions/conversion. I read about the NEG(160) two'd complement but I can't get it to work.
Any ideas?
0

#2
User is offline   Michael Walsh 

  • Omron Expert
  • Group: MrPLC Admin
  • Posts: 433
  • Joined: 03-April 06
  • Gender:Male
  • Location:Charlotte, NC
  • Country:United States
    United States
The easiest way that I can figure to do it would be to use the ANDW function to mask out bits 7-15, leaving the absolute value of the short signed integer. Then look at the sign bit, if it is on, multiply the masked value by -1, if it is off, just move the value as shown below:

Attached Image: Short int.jpg
Michael
Charlotte, NC
0

#3
User is offline   Nicolas 

  • Sparky
  • PipPipPip
  • Group: MrPLC Member
  • Posts: 14
  • Joined: 10-August 09
  • Location:Houston TX
  • Country:United States
    United States

View PostMichael Walsh, on 13 September 2012 - 07:01 PM, said:

The easiest way that I can figure to do it would be to use the ANDW function to mask out bits 7-15, leaving the absolute value of the short signed integer. Then look at the sign bit, if it is on, multiply the masked value by -1, if it is off, just move the value as shown below:

Attachment Short int.jpg


Thanks for the reply.
I tried that approach but that doesn't return the correct value...this is what you must get:
for 1111 1111 two's complement value= -1
but using the mask and multiply method you get -127
Unless I am doing something wrong...

Attached Image: ScreenShot188.jpg
0

#4
User is offline   Nicolas 

  • Sparky
  • PipPipPip
  • Group: MrPLC Member
  • Posts: 14
  • Joined: 10-August 09
  • Location:Houston TX
  • Country:United States
    United States
Here's the final answer attached for anyone interested, easy to put into a little function block:
Attached Image: ScreenShot189.jpg
Result:
Attached Image: ScreenShot190.jpg
0

#5
User is offline   Michael Walsh 

  • Omron Expert
  • Group: MrPLC Admin
  • Posts: 433
  • Joined: 03-April 06
  • Gender:Male
  • Location:Charlotte, NC
  • Country:United States
    United States
Ahh, yes, you are correct. I did not spend enough time on this and made a mistake. At least I got you headed in the right direction! :lookingaround:
Michael
Charlotte, NC
0

#6
User is offline   Sergei Troizky 

  • Expert
  • PipPipPipPip
  • Group: MrPLC Member
  • Posts: 603
  • Joined: 04-March 03
  • Gender:Male
  • Location:Montreal
  • Country:Canada
    Canada
:-)

Attached thumbnail(s)

  • Attached Image: Short Int.jpg

This post has been edited by Sergei Troizky: 14 September 2012 - 06:06 PM

0

#7
User is offline   Michael Walsh 

  • Omron Expert
  • Group: MrPLC Admin
  • Posts: 433
  • Joined: 03-April 06
  • Gender:Male
  • Location:Charlotte, NC
  • Country:United States
    United States
Ooooh! Ultra elegant! Nice!

:clap:
Michael
Charlotte, NC
0

#8
User is offline   BITS N BYTES 

  • Expert
  • PipPipPipPip
  • Group: MrPLC Member
  • Posts: 523
  • Joined: 22-December 04
  • Gender:Male
  • Location:Miami Beach FL
  • Country:United States
    United States
Structured Text conversion of Single Signed Integer.

Attached thumbnail(s)

  • Attached Image: SingleSignedData.JPG

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users