Charmed Quark Systems
Google
WWW CharmedQuark.com

Go Back   Charmed Quark Systems > General Discussion > Beta Driver Development
Register FAQ Members List Calendar Mark Forums Read

Beta Driver Development Discussion of new drivers, finding someone to write a new driver, etc...

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2012, 11:49 PM
pjgregory pjgregory is offline
 
Join Date: Aug 2004
Location: Montepulciano, Italy
Posts: 525
Default Problem with a PDL driver

I am writing a PDL driver for my energy analyzer. The data from the internal registers is returned in binary rather than ASCII format with two sequential bytes representing the MSB and LSB or a 16bit signed Integer. What is the easiest way to convert these to an INT4 field in the "Store=" structure?

So far the only thing that works is (for bytes 3 and 4 in the reply)

Store=
Register1 = Add(Mul(ToInt4(Extract(&Reply, Card1, 3)), 256) ,Extract(&Reply, Card1, 4));
EndStore;

This seems long winded and I am not sure yet if it will work for negative numbers. Is there a better way?

PJG
Reply With Quote
  #2  
Old 07-14-2012, 10:15 AM
Dean Roddey's Avatar
Dean Roddey Dean Roddey is online now
Administrator
 
Join Date: Aug 2002
Location: Mountain View, CA
Posts: 32,484
Default

Probably the best way is to extract the LSB cast to card2, then shift left 8. Then extract the MSB, to card2, and OR it with the result. So you know have the 16 bit value in the correct format. You can then just cast that to an Int2 to get the correct handling of the two's complement format. Then you can store that. So, just by eye and I'm sure with various syntax errors, something like:

Code:
Register1 = ToInt2 ( OR ( ShiftLeft(ToCard2(Extract(&Reply, Card1, 4)), 8) , ToCard2(Extract(&Reply, Card1, 3)) ) )

So, the innermost pulls the two values out, casts them to card2, shifts the first one left to make room for the next one and ORs them together to create the the raw 16 bit value. It then casts that to Int2 to covert to signed (it's important to do the Int2 so that the two's complement stuff is handled correctly.)

We really need a byte swap expression, which would make things like this easier.
__________________
Dean Roddey
Software Geek Extraordinaire
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:38 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.