03-24-2011 08:21 AM
I am seeing this issue with using DAQmxReadCounterF64 with simple edge counting. If the counter reads a negative count value, it returns a number that looks like an unsigned 32-bit number rolled over (~4294967295).
I am using DAQmx v8.9.5. PXI-6602 with Windows XP, programming in C++.
Is this a bug in the driver?
03-24-2011 05:32 PM - edited 03-24-2011 05:32 PM
Hi Mroche,
You're correct that the number you are seeing is the rollover of an unsigned 32-bit integer. Newer DAQ products use a 32-bit count register (e.g. M Series, TIO, X Series). In this register, the value -1 is represented the same as 232-1.
I wouldn't call this a bug exactly. The value you are reading is what is in the count register, and I don't think it makes sense to necessarily assume that 4294967295 should be scaled to -1 for all cases. Making this assumption would result in undesired behavior for anybody trying to count to 231 or higher (at which point the count would roll over to -231).
Having said that... position measurements are treated differently starting in DAQmx 9.0 due to the behavior reported on another thread which was in fact deemed a bug (which I notice you have seen already). The driver casts the raw count to I32 before scaling it to a position.
Now, I'm not so sure it makes sense to treat the two measurement types differently, but I think the reasoning behind the decision was that negative values make sense when talking about position, but for counting edges not quite as much (what exactly is a negative number of edges?). In the count edges case, I think it makes the most sense for DAQmx to allow the user to handle rollovers himself. At the end of the day, all the driver can do is change where the rollover occurs (either at 0 = 232 or 231 = -231).
In your case, if you want to read (-) values on your count edges task, the easiest way to accomplish this is to read the data back as U32 (DAQmxReadCounterU32) then type cast it to I32. This will give the result that I think you are looking for.
If you have any suggestions to help improve usability, please feel free to post to the DAQ Idea Exchange. Some preliminary ideas to make this experience a little more intuitive might include a property node to set how the data is cast, or perhaps have the driver cast the data to I32 if the Count Direction is set to anything other than Count Up. Although, the 2nd idea has the potential to break existing applications so it might not be as viable of an option.
Best Regards,