Jump to content

Read Operands?


foxxs

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 weeks later...

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...