0

In principle my question is answered here, but in my case the variables are not simply X or Y, but pretty complex. My expression looks like

"plc3.gs_Data[1].tag1 + plc3.gs_Data[1].tag2"

and I would like to get a List {"plc3.gs_Data[1].tag1", "plc3.gs_Data[1].tag2"} as result, but NCalc.Compile() throws an Exception "missing EndOfFile at line 1:6" (which is the first character after the first period). Adding quotes around the parameters doesn't help.

Batox
  • 574
  • 1
  • 4
  • 16
  • Do you mean that you are referring to the plc object 3 and its gs_Data property, which is actually an array, its element at index 1 and the tag1 property? – tmt Jan 25 '23 at 10:48
  • yes. The NCalc parser tries to do too much here, it would be (in this case) better if it simply passed everything it doesn't understand as a symbol to my code. But that's not the way NCalc works, and I understand why, and meanwhile I found a workaround. I defined a new function symbol() which takes a string parameter, so now my expression is symbol("plc3.gs_Data[2].tag1") + symbol("plc3.gs_Data[1].tag2"), and all is well – Batox Jan 26 '23 at 16:54
  • You can try using NFun instead of NCalc - it works fine with complex input models and should be well suited for your task. – tmt Jan 27 '23 at 10:34

1 Answers1

0

NCalc does not work with complex input/output modules. If you need Ncalc functionality but with complex models - use NFun instead of Ncalc:

double result = Funny.Calc<MyComplexInputModel, double> (
                   "plc3.gs_Data[1].tag1 + plc3.gs_Data[1].tag2", 
                    complexInputModel)  
tmt
  • 686
  • 2
  • 10
  • 22