-
Notifications
You must be signed in to change notification settings - Fork 5
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
Exception: (Expected: UInt16, but was: UInt16) #73
Comments
The workaround I have found so far is to just take a double for every argument and cast it straight away to whatever I actually wanted to accept. It's awful, but it works for now. public static void Main()
{
string script = "UInt16ToUInt16(input + input)";
var runtime = Funny.Hardcore
.WithFunction(nameof(DoubleToDouble), (double number) => DoubleToDouble(number))
.WithFunction(nameof(FloatToFloat), (double number) => FloatToFloat(number))
.WithFunction(nameof(Int32ToInt32), (double number) => Int32ToInt32(number))
.WithFunction(nameof(UInt32ToUInt32), (double number) => UInt32ToUInt32(number))
.WithFunction(nameof(Int16ToInt16), (double number) => Int16ToInt16(number))
.WithFunction(nameof(UInt16ToUInt16), (double number) => UInt16ToUInt16(number))
.Build(script);
runtime["input"].Value = (UInt16)2;
runtime.Run();
Console.WriteLine(runtime["out"]);
}
private static double DoubleToDouble(double number) => number;
private static float FloatToFloat(double number) => (float)number;
private static Int32 Int32ToInt32(double number) => (Int32)number;
private static UInt32 UInt32ToUInt32(double number) => (UInt32)number;
private static Int16 Int16ToInt16(double number) => (Int16)number;
private static UInt16 UInt16ToUInt16(double number) => (UInt16)number; |
Hi, thank for report. I discovered the issue and figure out that it is not a bug, but wrong error message text, and lack of diallect settings Actual Nfun error explanation According to borring specification operator So original problem is that in script The same story for C# itself. Try to execute following C# code:
Workaround Use Int32 or Uint32 for your function paramers instead of Int16 or Uint16 Call to action
|
Thank you so much for an amazing explanation so quickly. I was unaware that c# automatically converts UInt16/Int16 types. Due to working with Modbus devices, I will be dealing with Uint16 and Uint16[] data types a lot. These Uint16/Uint16[] types in Modbus represent the raw Modbus registers that in tern make up whatever data types the manufacturer has deemed them to be used for (they quite often enjoy making up their own new data types). I think my solution as you said is to use a larger data type as the function parameters to allow for manipulation of these values. Thank you again. |
Under most cases when working with UInt16 and Int16 types seem to have a bug saying it didn't receive what it expected even though the exception actually says it did receive the correct type.
I thought the casting of the input value before going into the runtime would help, but it didn't. Maybe there is some way for me to cast in the script that makes this work, but I tried that and was unable to fix the issue.
If there are any workarounds I could use in the meantime, please let me know.
Results from the following scripts
The text was updated successfully, but these errors were encountered: