Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float comparison for range value fails #97

Open
alexxcons opened this issue Jan 25, 2022 · 0 comments
Open

float comparison for range value fails #97

alexxcons opened this issue Jan 25, 2022 · 0 comments
Labels
bug Something isn't working priority::high

Comments

@alexxcons
Copy link
Collaborator

alexxcons commented Jan 25, 2022

fel0021(triggered ps3000 scope) currently fails to run, even though the selected range 0.05 (50 mV in the flowgraph) is valid.

The reason seems to be that floating-point comparison should better not be done with ==, since already minimal discrepancies (for whatever reason) lead to a mismatch.

Edit: Problem is, that partly double and partly float is used to store the "range", which leads to conversion errors. Using the same type in all places fixes the problem.

Though a much more failsafe way would be the usage of an enum, like e.g. done for coupling (check for coupling_t).

Here the currently used code which throws an expetion, when "0.05" is passed due to floating point comparison:

    static PS3000A_RANGE
    convert_to_ps3000a_range(float range)
    {
      if (range == 0.01)
        return PS3000A_10MV;
      else if (range == 0.02)
        return PS3000A_20MV;
      else if (range == 0.05)
        return PS3000A_50MV;
      else if (range == 0.1)
        return PS3000A_100MV;
      else if (range == 0.2)
        return PS3000A_200MV;
      else if (range == 0.5)
        return PS3000A_500MV;
      else if (range == 1.0)
        return PS3000A_1V;
      else if (range == 2.0)
        return PS3000A_2V;
      else if (range == 5.0)
        return PS3000A_5V;
      else if (range == 10.0)
        return PS3000A_10V;
      else if (range == 20.0)
        return PS3000A_20V;
      else if (range == 50.0)
        return PS3000A_50V;
      else
      {
          std::ostringstream message;
          message << "Exception in " << __FILE__ << ":" << __LINE__ << ": Range value not supported: " << range;
          throw std::runtime_error(message.str());
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority::high
Projects
None yet
Development

No branches or pull requests

1 participant