Author Topic: Transfer Schedule Data From SQL Database to Micro850  (Read 886 times)

CalitriSan

  • Newbie
  • *
  • Posts: 4
    • View Profile
Transfer Schedule Data From SQL Database to Micro850
« on: March 24, 2021, 11:20:38 PM »
Hello - I'm very new to the world of PLC's and Advanced HMI and was thrown into the fire after the untimely passing of a co-worker, so please bear with my ignorance....

I'm trying to get our HMI set up to where an operator can load schedule data to the PLC to avoid manual data entry. I have set up an SQL server with a database and table that contains all of the data which will need sent. Two of the columns are schedule date and schedule, so I'm envisioning the user having two dropdowns (one date, one schedule name) to select a schedule and all of the corresponding data will be transferred.

I'm able to show the data in a datagridview but have no idea how to filter the data by schedule or how to write it to the PLC. Does anyone have any experience doing something similar or could provide some insight into how I would go about completing this project?

Thanks - Ray

Godra

  • Hero Member
  • *****
  • Posts: 1443
    • View Profile
Re: Transfer Schedule Data From SQL Database to Micro850
« Reply #1 on: March 26, 2021, 07:30:20 PM »
This all kind of sounds complex and without really knowing your data or your programming knowledge, I will just make some general suggestions:

- If you have several schedules per single date then you could have 2 dropdowns (date, schedule) and your date dropdown would have to control what schedules show in the schedule dropdown
- If you have only 1 schedule per single date then you could have only 1 dropdown (date)
- You might consider having a "Load" button next to dropdown(s) and use its Click event to actually send values to the PLC by checking what date or schedule was selected

As for your schedules, you can possibly create a dictionary (of string, string) for each schedule, where the key could be the PLC address and the value would be the data, from your table, that you want to write to that address. So it might look something like this:

        Dim schedule1 As New Dictionary(Of String, String)
       
        ' Add some elements to the dictionary. There are no
        ' duplicate keys, but some of the values are duplicates.
        schedule1.Add("N7:0", "whateverSQLvalue1")
        schedule1.Add("N7:1", "whateverSQLvalue2")
        schedule1.Add("N7:3", "whateverSQLvalue3")
        schedule1.Add("N7:4", "whateverSQLvalue4")

This was adopted from here so you better check what import it is using and the rest of the code:

   https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-5.0

Then you would use the driver to actually write each (key,value) pair from selected dictionary (which is a schedule) in a for loop.
Here is a link to one example of how to iterate in dictionary:

   https://stackoverflow.com/questions/18628917/how-can-iterate-in-dictionary-in-vb-net/18628972

AdvancedHMI drivers have this format for Write:
   
   driverName.Write(startAddress As String, dataToWrite As String)

so from the dictionary, for each (key,value) pair it would be writing:

   driverName.Write(key, value)

Google is your best friend, so look up stuff.
« Last Edit: March 26, 2021, 08:35:39 PM by Godra »

CalitriSan

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Transfer Schedule Data From SQL Database to Micro850
« Reply #2 on: March 26, 2021, 08:47:49 PM »
Thanks for the reply! After way too much reading on Stack Overflow and hours of YouTube videos (and a lot of trial and error) I finally got it to work. I got the date drop down to control what schedules appear in the schedule drop down using a filter in the SQL Query, then just iterate through the database values to write to the PLC variables. Seems so simple once all is said and done, but man it took a minute to get there haha.

Godra

  • Hero Member
  • *****
  • Posts: 1443
    • View Profile
Re: Transfer Schedule Data From SQL Database to Micro850
« Reply #3 on: March 26, 2021, 10:59:05 PM »
Sounds good.

Don't hesitate to post your solution, just remove any sensitive information from it first.

It might eventually help somebody else.