Author Topic: sharing data between two applications  (Read 2177 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
sharing data between two applications
« on: January 31, 2015, 12:21:34 AM »
Hi Archie,I'm having some trouble with my project and dont know if its my design or possibly the driver.  I am using ModbusTCP. I have several devices and each has its own form such that device1 is form2, device2 is form3 and so on.  I use the main (form1) to monitor all devices and this polls all the time regardless of visibility set to 500ms. I do this to monitor for events on devices that are not being viewed.  The trouble I have is sometimes when I go from the mainform to a device form, I get data that does not update.  It appears that the driver doesnt switch to the opened form and update the data everytime.  Sometimes it does though, there's no predicability.  Question: Is this a common design that the driver is known to work??

Now to the subject of this post.  My thought was to possibly create two applications where I have a mainform in app1 that monitors all devices but does not have any graphics. I would set this to minimize(not sizable)  App2 will host the devices and graphics and only poll when viewed.  But I need to get data from App1 to App2 for say alarm ack and to set a flashing indicator.  How do I pass data between the apps? Tell me am I out of my mind or is this a reasonable approach.  If its not then I will need to rethink my design. Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: sharing data between two applications
« Reply #1 on: January 31, 2015, 10:58:35 AM »
Sharing data between application can get a bit messy. At the bottom of this link, there is a little bit of an example on how to with a memory mapped file:

https://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfile(v=vs.110).aspx

If data updating stops, I would try this:

- Open ModbusBase.vb
- Go to line 88 and put a breakpoint at m_DisableSubscriptions = value
- Run the application and each time it stops at the break point hover over value to see what it is
- If it is False, then press F5 to continue, if it is True, then step through the code with F8 to get back to the source of where it is disabling subscriptions

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: sharing data between two applications
« Reply #2 on: January 31, 2015, 12:43:41 PM »
The modbusbase.vb is common for all modbus comms right?  The issue is when form1 and form2 are polling the same device at the same time. form1 all the time and form2 when the page is viewed. Sometimes data is not updated when the form2 is viewed but the subscription is still active due to form1 so checking the disable subscription would return false. I set the poll rate different between the forms so I can view the TxRx lights to determine which form subscription is "active". When data is not updated on form2 the TxRx lights indicate form1 is polling data. It appears that sometimes form2 subscription does not initiate when form2 is opened because form1 already has a subscription to the device.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: sharing data between two applications
« Reply #3 on: January 31, 2015, 01:23:26 PM »
The modbusbase.vb is common for all modbus comms right?
ModbusBase.vb is the common class definition for both TCP and RTU driver.
Sometimes data is not updated when the form2 is viewed but the subscription is still active due to form1 so checking the disable subscription would return false.
Each instance of the driver does it's own subscription handling, so the Form1 instance can continue to poll and update subscriptions, but the DisableSubscriptions can be True on the Form2 driver instance without effecting form 1.
I set the poll rate different between the forms so I can view the TxRx lights to determine which form subscription is "active". When data is not updated on form2 the TxRx lights indicate form1 is polling data. It appears that sometimes form2 subscription does not initiate when form2 is opened because form1 already has a subscription to the device.
If a driver instance is on Form2, when it comes to subscriptions and polling, it will be completely independent of Form1's instance.

By checking which value the DisableSubscriptions gets set to, you can get an idea whether one of the driver instance's subscriptions gets stopped.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: sharing data between two applications
« Reply #4 on: February 01, 2015, 06:01:30 PM »
Hey Archie, I think I had a faulty gateway and have since replaced it with much better results. 

I still have a slightly different issue that Im not sure the cause.  I can now change pages and get sucessfull data reads but there are times when I return to the main page the data seems to stop after a couple minutes.  I notice that one of my graphic indicators on the mainpage will go to the "Graphic All Off" state and will stay that way. But when I reopen the page for that device data updates fine and a return to the mainpage will now show proper data for awhile.
 I tried setting a breakpoint while the program was running but got the attached message.  I also attached a couple wireshark captures of when the data on the mainpage was not correct.  My laptop is 172.16.0.99 and the device is 172.16.0.2.  I see alot of traffic with other devices but not alot of data from the .2 device.  What is the cause of the breakpoint error and can you see anything in the captures as to is AHMI polling data or no returned data.  Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: sharing data between two applications
« Reply #5 on: February 01, 2015, 09:01:06 PM »
I'm not sure why you would be seeing that message when you put in a break point. That usually come up if you make a change to a file and put in a break point before doing a build.