Author Topic: OPC driver problem  (Read 2108 times)

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
OPC driver problem
« on: January 09, 2017, 10:01:08 AM »
Archie/Godra,

In my test for OPC I got now data coming, it is a very simple test, just two BasicLabel, one Barlevel, one label to see when the Timer occurs and one ProgressBarEx that need to be handle manually.
This is the code, with some MsgBox for my test:

Imports System.IO   'System library to import so StreamReader could be use
Public Class test

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        OpcDaCom1.BeginRead("M20943_A1_Scaled_Value", 1)
        Label1.Text = Now
    End Sub

    Private Sub OpcDaCom1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles OpcDaCom1.DataReceived
        If e.ErrorId <> 0 Then ' no good data received.
            MsgBox(e.ErrorId)
            Exit Sub
        End If
        MsgBox(e.Values(0))
        ProgressBarEx1.Value = CInt(e.Values(0))
    End Sub

 
    Private Sub test_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Now for some reason the BeginRead command is giving me the error “Parameter count mismatch.” Then if I change the # of elements of the BeginRead to 2 the error goes away but the DataReceived event never gets trigger, I also try with a OpcDaCom1.read but it also is giving me error.

Once again thank you guys

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #1 on: January 09, 2017, 11:25:34 AM »
What is the timer interval set for?
Can you try to do the reading with a button instead?

Have you tried similar setup with MatrikonOPC simulator (read its Bucket Brigade.Real4 tag maybe)?

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: OPC driver problem
« Reply #2 on: January 09, 2017, 11:32:58 AM »
Time interval is one second.
Try the pb with same result.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #3 on: January 09, 2017, 11:42:12 AM »
Try it like this just for test:

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = OpcDaCom1.BeginRead("M20943_A1_Scaled_Value", 1)(0)
    End Sub

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: OPC driver problem
« Reply #4 on: January 09, 2017, 12:03:33 PM »
Because a picture worth a thousand words.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #5 on: January 09, 2017, 12:47:27 PM »
Try changing it to Read instead.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #6 on: January 09, 2017, 01:55:37 PM »
It appears that the DataReceived event of the OPC driver doesn't function properly.

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: OPC driver problem
« Reply #7 on: January 09, 2017, 02:28:18 PM »
I changed to read, the only way to avoid errors was to declare the "a" as a string array, the return was a single element a(0) with nothing inside. (Label is located below the Button1, scaled was 5.62).

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #8 on: January 09, 2017, 02:36:39 PM »
What errors did you get before you declared "a"?

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: OPC driver problem
« Reply #9 on: January 09, 2017, 02:44:28 PM »
Value of type '1=dimensional array of String' cannot be converted to 'string'.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #10 on: January 09, 2017, 03:10:18 PM »
So what exactly is M20943_A1_Scaled_Value? Is it an array?

From picture in other topic a value similar to this seems to show as Single float value.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: OPC driver problem
« Reply #11 on: January 09, 2017, 05:27:49 PM »
Victor,

A line of code like this would produce that same error:

Label1.Text = OpcDaCom1.Read("M20943_A1_Scaled_Value", 1)

A line of code like this wouldn't:

Label1.Text = OpcDaCom1.Read("M20943_A1_Scaled_Value", 1)(0)

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: OPC driver problem
« Reply #12 on: January 11, 2017, 01:44:31 PM »
Godra,
Spend the last two and a half day working with Archie in the modbus, finally it appears that now my problems are centered in the communication adapter I was using, I ordered the one that he is using hoping that everything will be ok when I get it.

Now going back to this thread,  your last suggestion of using "Label1.Text = OpcDaCom1.Read("M20943_A1_Scaled_Value", 1)(0)" did not produced any error, but also returned an empty string.  tonight I will try using a subscription to see if I get any result.

Regards
Victor.