I'm sorry if this turns out to be a really stupid question but I'm just starting to force myself to use Entity Framework (I know I'm a long way behind), but I've fallen at the first hurdle.

The program I'm writing simply watches a PLC for a bit to become true. When it does become true an event fires and then values (random at the moment) will be entered into SQL. I then set the bit to false.

The problem I'm having is that the event fires once, the entries get added, and bit gets set false. However the event never triggers again. If I comment out all of the SQL bits then and just set the bit false then it works perfectly and fires multiple times.

@Azhar Because its being called from Main() which is static? Am I being really stupid? I thought I wouldn't be able to call a non static method from a static context?
–
Nick WilliamsFeb 21 '13 at 15:44

Incidentally I did try creating a BitChangedHelper class which was non-static and contained the code above which is in On_BitChanged. So I created a new BitChangedHelper and called the methodd HandleBit();
–
Nick WilliamsFeb 21 '13 at 16:09

1 Answer
1

You did not mention which OpcServer component you are using, but the most probable problem is that the DataChange comes into your application in a COM callback thread and you are not allowed to write back to COM while handling the callback. You need to just record the incoming value and do the actual handling in your own handler thread, which then sets the bit back to false in the PLC.

That was my initial thought too. However when the event fires for the first time the bit does get set back to false. i.e. plcListener.Confirm(); runs successfully. Also if the On_BitChanged() method just contains plcListener.Confirm(); everything works fine and the event fires whenever the plc bit becomes true
–
Nick WilliamsFeb 21 '13 at 21:12