Announcement

Collapse
No announcement yet.

Sending Data to Shared Memory

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending Data to Shared Memory

    Hello All,

    I keep reading about data and parsing and best practices. I also keep hearing that sending data to shared memory is the best way to update data on a scene. How is that done? As always i must say that I am not great at scripting so simple explanations are needed for me. I can parse my XML data but need the most efficient way to update the scene when the data is called and once it is called it updated at certain intervals.

  • #2
    i'm curious about that. I have some examples. But if can someone share good example, i will be thankful.

    Comment


    • #3
      Ok All,

      This is what i have so far: I'm not sure if this is the correct way to put items in shared memory but trying to learn.

      In dim a i have the data that is being fed into containers, I am using that to feed an array for the system map. If someone can guide on a better way for me to get data to shared memory please help!!.

      I am having trouble with the data updating when the shared memory changes. See below.

      Any help is greatly appreciated.

      Shotski

      '-----------------------------------------
      dim a = Cand1_FirstName.Geometry.Text & " " & Cand1_LastName.Geometry.Text & " " & Cand1_Vote_Total_Commified.Geometry.Text

      System.Map["my_global_variable"] = a

      println a


      Dim MyVariable as string
      MyVariable = (string)System.Map["my_global_variable"]

      Dim MyArray as array [string]
      MyVariable.split(" ",MyArray)

      println MyVariable

      Scene.FindContainer("myTest").geometry.text = MyArray[0]
      Scene.FindContainer("myTest2").geometry.text = MyArray[1]
      Scene.FindContainer("myTestVotes").geometry.text = MyArray[2]


      sub OnInit()

      System.Map.RegisterChangedCallback("my_global_variable")

      end sub

      Sub OnSharedMemoryVariableChanged(map as SharedMemory, mapKey as String)

      'NOT SURE WHAT TO PUT HERE TO MAKE IT UPDATE THE DATA ONCE ITS CHANGED????

      End Sub

      Comment


      • #4
        Hi There,

        You need to add an IF statement to check which shm var that has been changed. I have only used this with Vizcommunication.map["shmVar"]. I haven't tested it with System.Map["my_global_variable"]

        Sub OnSharedMemoryVariableChanged(map as SharedMemory, mapKey as String) <- also note this is only invoked if the shm var changes to a different val

        If mapKey = "My_SHM_VAR_NAME" then

        Dim data as string = VizCommunication.map["My_SHM_VAR_NAME"]
        Dim lineData as array[string]
        data.Split("|",lineData)
        SomeFontContainer.geometry.text = lineData[2]

        End if
        End Sub

        With regards to sending data, I use C# to either send one big delimited string package to viz shm over TCP Connection per update or I send multiple packets packets over UDP connection depending on the purpose of the data.

        If you send data to a viz engine, Make sure you configured for UDP or TCP in the viz config and set a port number.

        Then when you send the data you will want to send it like this. This is to populate one shared memory var called "MyVar". and we are populating it with a string that is saying "TheNewValue"

        string example = "/myData/Dir1/MyVar|TheNewValue" then end command Character '\0' <- so its your shared-memory directory, then the varName and then a pipe char "|". Then the value you want to populate.

        So you can send that using a loop and udp or you can chain multiple ones together and send as one package..
        To send multiple you can build a string with multiple "/myData/Dir1/ValueName|NewValue" string seperated by the end command Char = \0

        Best Regards
        Graham
        Last edited by Novacane89; 05-21-2019, 09:43 AM.

        Comment


        • #5
          Hi Novacane,

          Do you have any scenes to share? I'm still confused about the whole thing. Does not seem to be as simple.

          Comment


          • #6
            So i updated the script to what is below but the data still does not update on change. The data updates on the containers but not in shared memory. What am i missing?

            '-----------------------------------------
            sub OnInit()

            System.Map.RegisterChangedCallback("my_global_variable")

            end sub

            '----------------------------------------
            dim a = Cand1_FirstName.Geometry.Text & " " & Cand1_LastName.Geometry.Text & " " & Cand1_Vote_Total_Commified.Geometry.Text
            System.Map["my_global_variable"] = a

            println a


            Sub OnSharedMemoryVariableChanged(map as SharedMemory, mapKey as String)
            If mapKey = "my_global_variable" then

            Dim MyVariable as string = System.Map["my_global_variable"]

            Dim MyArray as array [string]
            MyVariable.split(" ",MyArray)

            println MyVariable

            Scene.FindContainer("myTest").geometry.text = MyArray[0]
            Scene.FindContainer("myTest2").geometry.text = MyArray[1]
            Scene.FindContainer("myTestVotes").geometry.text = MyArray[2]


            end if
            End Sub

            Comment


            • #7
              Hi Shotski,

              You should be updating the Shared memory variable , Which I see you did by storing it in the variable "a" and then setting it equal to System.Map["my_global_variable"].... Let me test your script quick. In the meantime, here is a little shared memory scene example

              Put the flatFileDB.txt in your C:\ root. Or where ever you want but then you need to change the path in the viz script.
              Attached Files
              Last edited by Novacane89; 05-21-2019, 04:59 PM.

              Comment


              • #8
                I just tested your script and it works fine. It loads the memory into the map. On another font container I added a new script this.geometry.text = ["my_global_variable"] and the info popped up... Closed the scene, Pasted the script again in a new scene and it retrieved the info again correctly onto a new font container
                How are you planning on using shared memory?

                The idea is to have the OnInit register and OnSharedMemoryVariableChanged on another font. Then it will Change as soon as you populate the shared memory variable.... For test cases we populate the shared memory from the font containers in viz like map["blah"] = this.geometry.text... But for elections you will populate the shared memory directly using SQL connection , XML , text file ect...

                Unless of course we are talking about touch screen. In that case you could populate shared memory data from font containers as it might be a user-interface funtionality or if you wanted operators to update your database with the graphic templates they are inputing or saving..
                Attached Files
                Last edited by Novacane89; 05-21-2019, 05:39 PM.

                Comment


                • #9
                  Can you send me the via of your scene? I still cant get it to work.

                  Comment


                  • #10
                    I am trying to put the data into shared memory because 1) Data Reader is too slow, 2) Using TCP causes an issue with a 1 second lag when loading the data and causes any animations to stop for that 1 second and transition logic causes an issue with the data update as well.

                    So Basically i want to take the data from the XML feed have it update every 20 seconds or so and also have data be available for other monitor wall graphics.

                    I know in Viz there are so many ways to do things, bug this one thing that i have been wanting to do, i can never get it to work.

                    Comment


                    • #11
                      SO this is the latest script. It only updates when i compile & Run the shared memory script to put the values into shared memory. But when the data changes it does not update the containers that have the script below:

                      I have attached a .via file. SMH_Work.via

                      '-----------------------------------------
                      sub OnInit()

                      VizCommunication.map.registerChangedCallback("MyVariable")

                      end sub

                      '----------------------------------------

                      Sub OnSharedMemoryVariableChanged(map as SharedMemory, mapKey as String)

                      If mapKey = "MyVariable" then

                      Dim MyVariable as string = VizCommunication.map["MyVariable"]

                      Dim MyArray as array [string]
                      MyVariable.split(" ",MyArray)

                      Scene.FindContainer("F_Name").geometry.text = MyArray[0]
                      Scene.FindContainer("L_Name").geometry.text = MyArray[1]
                      Scene.FindContainer("Votes").geometry.text = MyArray[2]


                      end if
                      End Sub

                      Comment


                      • #12
                        Agreed DataReader is slow ... but TCP causes 1 second delay ? In my experience tcp to shared memory is the fastest and most stable. Also the idea is to update a memory map constantly or OnSourceFileUpdated , and then the templates just pick the data when firing to on-air which is basically instantaneous in my experience. I will have a look at your script, In the meantime did you check the example via I attached above?

                        ---edited...

                        Can you send me the example xml ? , otherwise I need to alter your code to read from another data source...

                        Perhaps if you want I can make you a small exe you can trigger with viz to parse that xml for you and send it to shared memory . Then your scene script just has to pick the data based on one control text. (as a extra method for your tests) and it takes some load away from your scene scripts


                        --latest edit, I tested your script in the scene by just adding basic script to push something into that VizCommunication.map["MyVariable"].

                        When I poplated it with a 3 word sentence your 3 font containers successfully changed so your OnSharedMemoryVariableChanged callback is working. Your problem must lie somewhere in the in the data collection part? Hence I need the xml.
                        Last edited by Novacane89; 05-22-2019, 07:39 AM.

                        Comment


                        • #13
                          Thanks for your help on this. XML data below:

                          <DATA>
                          <RUN_DATE>Thu May 23 09:51:35 EDT 2019</RUN_DATE>
                          <RUN_EPOCH>1558619495</RUN_EPOCH>
                          <RACE>
                          <RACE_ID>1</RACE_ID>
                          <JURISDICTION_ID>2</JURISDICTION_ID>
                          <RACE_NAME1>Mayor</RACE_NAME1>
                          <RACE_NAME2>City of Tampa</RACE_NAME2>
                          <NUM_SEATS>1</NUM_SEATS>
                          <ALLCAND_VOTES>48514</ALLCAND_VOTES>
                          <PRECINCTS_TOTAL>103</PRECINCTS_TOTAL>
                          <PRECINCTS_TOTAL_COMMIFIED>103</PRECINCTS_TOTAL_COMMIFIED>
                          <PRECINCTS_REPORTING>103</PRECINCTS_REPORTING>
                          <PRECINCTS_REPORTING_COMMIFIED>103</PRECINCTS_REPORTING_COMMIFIED>
                          <PCT_PRECINCTS_REPORTING>100</PCT_PRECINCTS_REPORTING>
                          <UPDATED>2019-03-05 22:38:00</UPDATED>
                          <CAND1_CANDIDATE_ID>1</CAND1_CANDIDATE_ID>
                          <CAND1_DISPLAY_ORDER>1</CAND1_DISPLAY_ORDER>
                          <CAND1_VISIBLE>Y</CAND1_VISIBLE>
                          <CAND1_FIRST_NAME>Jane</CAND1_FIRST_NAME>
                          <CAND1_LAST_NAME>Castor</CAND1_LAST_NAME>
                          <CAND1_INCUMBENT>N</CAND1_INCUMBENT>
                          <CAND1_WINNER/>
                          <CAND1_PARTY_ID/>
                          <CAND1_PARTY_ABBR/>
                          <CAND1_PARTY_NAME1/>
                          <CAND1_PARTY_NAME2/>
                          <CAND1_VOTE_TOTAL>23318</CAND1_VOTE_TOTAL>
                          <CAND1_VOTE_TOTAL_COMMIFIED>23,318</CAND1_VOTE_TOTAL_COMMIFIED>
                          <CAND1_PCT_TOTAL>48</CAND1_PCT_TOTAL>
                          <CAND1_PIC_ID>jcasto</CAND1_PIC_ID>
                          <CAND2_CANDIDATE_ID>5</CAND2_CANDIDATE_ID>
                          <CAND2_DISPLAY_ORDER>5</CAND2_DISPLAY_ORDER>
                          <CAND2_VISIBLE>Y</CAND2_VISIBLE>
                          <CAND2_FIRST_NAME>David</CAND2_FIRST_NAME>
                          <CAND2_LAST_NAME>Straz</CAND2_LAST_NAME>
                          <CAND2_INCUMBENT>N</CAND2_INCUMBENT>
                          <CAND2_WINNER/>
                          <CAND2_PARTY_ID/>
                          <CAND2_PARTY_ABBR/>
                          <CAND2_PARTY_NAME1/>
                          <CAND2_PARTY_NAME2/>
                          <CAND2_VOTE_TOTAL>7518</CAND2_VOTE_TOTAL>
                          <CAND2_VOTE_TOTAL_COMMIFIED>7,518</CAND2_VOTE_TOTAL_COMMIFIED>
                          <CAND2_PCT_TOTAL>15</CAND2_PCT_TOTAL>
                          <CAND2_PIC_ID>dstraz</CAND2_PIC_ID>
                          <CAND3_CANDIDATE_ID>2</CAND3_CANDIDATE_ID>
                          <CAND3_DISPLAY_ORDER>2</CAND3_DISPLAY_ORDER>
                          <CAND3_VISIBLE>Y</CAND3_VISIBLE>
                          <CAND3_FIRST_NAME>Harry</CAND3_FIRST_NAME>
                          <CAND3_LAST_NAME>Cohen</CAND3_LAST_NAME>
                          <CAND3_INCUMBENT>N</CAND3_INCUMBENT>
                          <CAND3_WINNER/>
                          <CAND3_PARTY_ID/>
                          <CAND3_PARTY_ABBR/>
                          <CAND3_PARTY_NAME1/>
                          <CAND3_PARTY_NAME2/>
                          <CAND3_VOTE_TOTAL>5904</CAND3_VOTE_TOTAL>
                          <CAND3_VOTE_TOTAL_COMMIFIED>5,904</CAND3_VOTE_TOTAL_COMMIFIED>
                          <CAND3_PCT_TOTAL>12</CAND3_PCT_TOTAL>
                          <CAND3_PIC_ID>hcohen</CAND3_PIC_ID>
                          <CAND4_CANDIDATE_ID>7</CAND4_CANDIDATE_ID>
                          <CAND4_DISPLAY_ORDER>7</CAND4_DISPLAY_ORDER>
                          <CAND4_VISIBLE>Y</CAND4_VISIBLE>
                          <CAND4_FIRST_NAME>Ed</CAND4_FIRST_NAME>
                          <CAND4_LAST_NAME>Turanchik</CAND4_LAST_NAME>
                          <CAND4_INCUMBENT>N</CAND4_INCUMBENT>
                          <CAND4_WINNER/>
                          <CAND4_PARTY_ID/>
                          <CAND4_PARTY_ABBR/>
                          <CAND4_PARTY_NAME1/>
                          <CAND4_PARTY_NAME2/>
                          <CAND4_VOTE_TOTAL>4319</CAND4_VOTE_TOTAL>
                          <CAND4_VOTE_TOTAL_COMMIFIED>4,319</CAND4_VOTE_TOTAL_COMMIFIED>
                          <CAND4_PCT_TOTAL>9</CAND4_PCT_TOTAL>
                          <CAND4_PIC_ID>eturan</CAND4_PIC_ID>
                          <CAND5_CANDIDATE_ID>3</CAND5_CANDIDATE_ID>
                          <CAND5_DISPLAY_ORDER>3</CAND5_DISPLAY_ORDER>
                          <CAND5_VISIBLE>Y</CAND5_VISIBLE>
                          <CAND5_FIRST_NAME>Dick</CAND5_FIRST_NAME>
                          <CAND5_LAST_NAME>Greco, Jr.</CAND5_LAST_NAME>
                          <CAND5_INCUMBENT>N</CAND5_INCUMBENT>
                          <CAND5_WINNER/>
                          <CAND5_PARTY_ID/>
                          <CAND5_PARTY_ABBR/>
                          <CAND5_PARTY_NAME1/>
                          <CAND5_PARTY_NAME2/>
                          <CAND5_VOTE_TOTAL>4156</CAND5_VOTE_TOTAL>
                          <CAND5_VOTE_TOTAL_COMMIFIED>4,156</CAND5_VOTE_TOTAL_COMMIFIED>
                          <CAND5_PCT_TOTAL>9</CAND5_PCT_TOTAL>
                          <CAND5_PIC_ID>dgreco</CAND5_PIC_ID>
                          <CAND6_CANDIDATE_ID>6</CAND6_CANDIDATE_ID>
                          <CAND6_DISPLAY_ORDER>6</CAND6_DISPLAY_ORDER>
                          <CAND6_VISIBLE>Y</CAND6_VISIBLE>
                          <CAND6_FIRST_NAME>Mike</CAND6_FIRST_NAME>
                          <CAND6_LAST_NAME>Suarez</CAND6_LAST_NAME>
                          <CAND6_INCUMBENT>N</CAND6_INCUMBENT>
                          <CAND6_WINNER/>
                          <CAND6_PARTY_ID/>
                          <CAND6_PARTY_ABBR/>
                          <CAND6_PARTY_NAME1/>
                          <CAND6_PARTY_NAME2/>
                          <CAND6_VOTE_TOTAL>2461</CAND6_VOTE_TOTAL>
                          <CAND6_VOTE_TOTAL_COMMIFIED>2,461</CAND6_VOTE_TOTAL_COMMIFIED>
                          <CAND6_PCT_TOTAL>5</CAND6_PCT_TOTAL>
                          <CAND6_PIC_ID>msuare</CAND6_PIC_ID>
                          <CAND7_CANDIDATE_ID>4</CAND7_CANDIDATE_ID>
                          <CAND7_DISPLAY_ORDER>4</CAND7_DISPLAY_ORDER>
                          <CAND7_VISIBLE>Y</CAND7_VISIBLE>
                          <CAND7_FIRST_NAME>Christopher</CAND7_FIRST_NAME>
                          <CAND7_LAST_NAME>Morrison</CAND7_LAST_NAME>
                          <CAND7_INCUMBENT>N</CAND7_INCUMBENT>
                          <CAND7_WINNER/>
                          <CAND7_PARTY_ID/>
                          <CAND7_PARTY_ABBR/>
                          <CAND7_PARTY_NAME1/>
                          <CAND7_PARTY_NAME2/>
                          <CAND7_VOTE_TOTAL>838</CAND7_VOTE_TOTAL>
                          <CAND7_VOTE_TOTAL_COMMIFIED>838</CAND7_VOTE_TOTAL_COMMIFIED>
                          <CAND7_PCT_TOTAL>2</CAND7_PCT_TOTAL>
                          <CAND7_PIC_ID>tmorri</CAND7_PIC_ID>
                          </RACE>
                          </DATA>

                          Comment


                          • #14
                            Hi Shotski,

                            I attached a .via scene with viz script examples on how you can retrieve the data, Includes OnSharedMemoryVariableChange.
                            Please note that in this example I included OnExecPerfield events whilst testing but you can remove all the OnExecPerfield Events with their code and it all will still work and update On Change.
                            Except for the small realtime selector example I added as a bonus , that one is mainly to illustrate how you can dynamically alter the shm path and data will reveal.

                            If you have any other questions feel free to ask. If you wanted to build your own version of my examples here you need to learn "How to send a TCP string command using C#" and "Parsing XML in C#"


                            Download the rar file attached.
                            Inside you will find 2 solutions. Test both and pick the one that works for you.


                            Both are lightning fast.

                            Option 1 - Use the GUI.

                            -1 In the GUI you set the Viz engine host machine, and you set the SHM port for viz
                            -2 Click Browse XML and select the XML file
                            -3 Set your refresh timer interval in seconds
                            -4 Start timer and it will constantly update the xml into the SHM every X seconds

                            -5 You have a manual test button also.. REMEMBER to set Viz Config>Communication>Shared Memory Tab TCP port = 6914 or whatever. And make sure the gui also is pointing to the same port nr




                            Option 2 - Use the Console App.

                            -1 The console app uses the Config txt file to see where it must read and push,
                            for example localhost|6914|C:\ElectionData2019.xml .

                            -2 In viz You can use an action keyframe or Viz script to Trigger the exe in animation or with loop. (Application.Start(C:\\blah))


                            NOTE! you can switch on Debug in Communication>shared memory Tab> to see the data coming in at console


                            FINAL note , Instead of the timer you could use WindowsFileWatcher to make the C# app trigger whenever it detects the XML is updated, I was going to add it in the console app, then you just leave the console app open and it will refresh SHM data when it detects the XML file updated, But I am tired now and going to have a beer. Maybe tomorrow. lol
                            Attached Files
                            Last edited by Novacane89; 05-23-2019, 07:46 PM.

                            Comment


                            • #15
                              Thanks so much for this Nocavane, I will dive into it and report back. Thanks again so much

                              Comment

                              Working...
                              X