Jump to content

Recommended Posts

Posted

I've created a fairly workable application to retrieve data from the data tables of the PLC's (PL-570) i'm working with, however I would like to also be able to gather all of the operands (MB, MI, SI, etc) as well, and format them into organized datagridviews in vb.net. I'd like to use a similar method as I've used for the tables if possible:

   Public Sub ReadDataTables(IP As String, port As Integer, protocal As EthProtocol, retries As Integer, timeoutMs As Integer)
       Dim frmClockTables As New Form
       Dim Tabs As New TabControl
       frmClockTables.Controls.Add(Tabs)
       Tabs.Dock = DockStyle.Fill
       Try
           ethernet1 = New Ethernet(IP, port, protocal, retries, timeoutMs)
           plc1 = PLCFactory.GetPLC(ethernet1, 0)
           dtTables = New DataTables(plc1, DataTablesReadOptions.StructureAndValues)
       Catch ex As Exception
           MessageBox.Show("Could not connect to " & IP & " on port " & port)
       End Try
       Try
           ethernet1 = New Ethernet(IP, port, protocal, retries, timeoutMs)
           plc1 = PLCFactory.GetPLC(ethernet1, 0)
           dtTables = New DataTables(plc1, DataTablesReadOptions.StructureAndValues)
       Catch ex As Exception
           MessageBox.Show("Could not connect to " & IP & " on port " & port)
       End Try

       Dim colcount As Integer = 0
       Dim rowcount As Integer = 0
       For Each item In dtTables.Tables
           Dim data As New DataGridView
           Dim tab As New TabPage
           tab.Text = item.Name.ToString
           tab.Controls.Add(data)
           data.Dock = DockStyle.Fill
           Tabs.TabPages.Add(tab)
           colcount = item.Columns.Count
           rowcount = item.Rows.Count

           Dim i As Integer = 0
           For Each column In item.Columns
               data.ColumnCount = colcount
               data.RowCount = rowcount
               data.Columns(i).Name = column.Name.ToString
               For Each Cell In column.Cells
                   Dim cellvalue As String = ""
                   For Each Field In Cell.Fields
                       If Not cellvalue = "" Then
                           cellvalue &= ";"
                       End If
                       cellvalue &= Field.Value
                   Next
                   data.Rows(Cell.RowIndex).Cells(Cell.ColumnIndex).Value = cellvalue
               Next
               i += 1
           Next
           NumberAllRows(data)
       Next
       frmClockTables.Show()
   End Sub

how can this be done, or can it be done at all?

Posted

Are you familiar with the plc.ReadWrite ?

You can read or/and write values of Operands. You simply send an array of ReadWriteRequest to that function, which will ultimatly return you a the requests filled with what you have requested.

What you do after that (Either showing it in a table, creating a Scada or whatever) is your own code.

You want to show it in a table, that's fine. You can create an array of requests that the first one will read 100 MIs, the second will read 100 MBs, and the 3rd 100 SIs

Iterate the indexes from 0 to 99 (le'ts call it J), and then inside it, iterate the requests inside the array.

Each Read request has a property called Values. If you get the Value at index J then you get the value of the current "Row" on your table.

  • 4 weeks later...
Posted

I'm actually not familiar with plc.readwrite, are their any examples on the forms somewhere, or maybe an API i could work with. im trying to get listen mode to work as well (cant seem to get my program to actually LISTEN on a port)? i was not able to find any detailed documentation on ether subject for .net, though admittedly i may be looking in the wrong places.

thank you for your help!

Posted

I was able to get listen mode working perfectly with this example, and reading operands looks fairly straightforward, though I've not integrated that just yet.

Thank you so much Saragani!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.