SteveMyres Posted November 13, 2012 Share Posted November 13, 2012 What's the cleanest (fastest?) way to convert two values which DAQ Factory has polled as S16's but which are actually halves of a U32, back into that U32? The values are coming in as S16's to avoid breaking a consecutive string of registers. Convert the S16's to bits or bytes, append, and back to a U32? An iif that converts the S16 to a U16, then combine using (U16#1 << 16 + U16#2)? Link to comment Share on other sites More sharing options...
AzeoTech Posted November 14, 2012 Share Posted November 14, 2012 LSW + MSW * 65536 There are other ways, but that's probably fastest. If you were doing low level assembly programming, then << is marginally faster, but then if you were doing that, you would just move the two memory locations so they were neighbors and cast it to a U32. You probably really should poll as U16, not S16. Link to comment Share on other sites More sharing options...
SteveMyres Posted November 14, 2012 Author Share Posted November 14, 2012 Won't your method view LSW as negative and subtract it (add a negative) if bit 15 is set? Can't poll as U16, because of the bundling, and can't change them ALL to U16 cause there's other stuff that needs to be signed (and I can't rearrange them completely freely). Link to comment Share on other sites More sharing options...
AzeoTech Posted November 14, 2012 Share Posted November 14, 2012 Yes, if you have to use S16, then simple math won't work. There are a couple options: to.uLong(concat(transpose(from.Word(U16#1),0), transpose(from.Word(U16#2),0))) Not sure of the byte ordering... Or, you can convert an S16 to U16 by doing: to.uWord(from.word(s16value)) so: to.uWord(from.word(LSW)) + to.uWord(from.word(MSW)) * 65536 Or to make it easier, just create a Conversion: to.uWord(from.word(Value)) and apply that to any S16 values that you really wanted to be U16. Remember, the S16 vs U16 only applies in the Modbus portion. Once its in the channel and ready to be converted, its just a double float. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.