Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: Async task Pin
Kenneth Haugland20-Feb-21 23:57
mvaKenneth Haugland20-Feb-21 23:57 
GeneralRe: Async task Pin
Dave Kreskowiak21-Feb-21 5:10
mveDave Kreskowiak21-Feb-21 5:10 
GeneralRe: Async task Pin
Kenneth Haugland21-Feb-21 8:10
mvaKenneth Haugland21-Feb-21 8:10 
GeneralRe: Async task Pin
Richard Deeming21-Feb-21 22:19
mveRichard Deeming21-Feb-21 22:19 
GeneralRe: Async task Pin
Kenneth Haugland22-Feb-21 6:58
mvaKenneth Haugland22-Feb-21 6:58 
GeneralRe: Async task Pin
Richard Deeming21-Feb-21 22:19
mveRichard Deeming21-Feb-21 22:19 
GeneralRe: Async task Pin
Dave Kreskowiak22-Feb-21 3:42
mveDave Kreskowiak22-Feb-21 3:42 
Questionc# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge18-Feb-21 22:00
Roberto64_Ge18-Feb-21 22:00 
I made an opc client in order to connect to Rockwell Rslinx. I used only OPCgroup.SyncRead and SyncWrite. Everything is working fine and I write and read tags from a Rockwell plc. To test the SyncWrite I used a sine wave and i see it correctly in the trend page of the plc. In addition when I press a button on the form I set a value until I keep the button pressed which return to zero when I release the button (let's say a pulse). That value is written in the PLC and I can check it in the trend the same. Then I read it back from the PLC in the form.
To do that I place the value of the sine wave in array[0] and the value of the pulse in array[1]. Then array is passed to the SyncWrite. So, as I said, here everything is OK.
Then I had to add a new functionality. This is a second order system (T(s) or second order filter).
I use the same array of course and now array[0] is the result of the filter and array[1] is again the pulse.
The pulse is read back from the PLC and is now the force perturbing the system. In order to switch from the sine wave calculation to the filtering I use a button that enable filtering or sine wave alternatively.
Here I got crazy because, when I switch to filter and press the button that generate the pulse to be read back from the plc, pulse does not arrive to the PLC. But the strangest thing is that within array[1] I see the value of the pulse at the moment when it should be sent to the PLC through the SyncWrite.
This I can see in debugging when I set the point of interrupt in the line with the SyncWrite here below
C#
public static void Write_synchr(RSIOPC r)
   {
     try
       {
         DataToSend.SetValue(r.array_to_send, 1);
         r.RSLinxOPCgroup_w.SyncWrite(1, ref r.SyncServerHandles_w, ref DataToSend, out SyncErrors2);
       }
     catch (Exception e)
       {
         MessageBox.Show(e.ToString(), "Error:  ",
                       MessageBoxButtons.OK, MessageBoxIcon.Error);
       }

   }


I mean that interrupting at the line of the SyncWrite, inside DataToSend I see the correct value but it does not reach PLC.
Even stranger the fact that sometimes I saw it working, I do not know how, but not always. So I tried with some different ways to correct but nothing to do.
Then I made a lot of other test and here below is what I saw.

C#
public float test_second_order_filter()
    {
        force[0] = ... the result of the SyncRead to read the value of the pulse ...
        filter[0] = (float) (-(filter[2] * param_filter[2] / param_filter[0]) - (filter[1] * param_filter[1] / param_filter[0]) +
                     +(force[2] * param_force[2] / param_filter[0]) + (force[1] * param_force[1] / param_filter[0]) +
                        +(force[0] * param_force[0] / param_filter[0]));
        filter[2] = filter[1];
        filter[1] = filter[0];
        force[2] = force[1];
        force[1] = force[0];
        return filter[0];
    } 

that is exactly what I have to do but the behaviour is what described in the introduction

Then I tried with a simplified version :
C#
public float test_second_order_filter()
    {
        force[0] = ... the result of the SyncRead to read the value of the pulse ...
        filter[0] = (float) (force[0] + filter[2]);
        filter[2] = filter[1];
        filter[1] = filter[0];
        force[2] = force[1];
        force[1] = force[0];
        return filter[0];
    }


(Formula here makes no sense) Again no way

Then I tried with this :
C#
public float test_second_order_filter()
    {
        force[0] = ... the result of the SyncRead to read the value of the pulse ...
        filter[0] = (float) (force[0] + 1 + filter[2]);
        filter[2] = filter[1];
        filter[1] = filter[0];
        force[2] = force[1];
        force[1] = force[0];
        return filter[0];
    }



(Formula here makes no sense) Something happens and when I press the button sometimes the pulse arrives to the PLC, I see the PLC trend moving. From the ....try ... catch error come about access violation in SyncWrite many times but code does not stop and continue doing something.

Then I tried with this :
C#
public float test_second_order_filter()
    {
        force[0] = ... the result of the SyncRead to read the value of the pulse ...
        filter[0] = (float) (force[0] + 0.005 + filter[2]);
        filter[2] = filter[1];
        filter[1] = filter[0];
        force[2] = force[1];
        force[1] = force[0];
        return filter[0];
    }


(Formula here makes no sense) But now system is working (...Ok , with a formula that makes no sense but it works). If I press button I see the pulse in the PLC that is read back from the PLC itself within the form and so I see it reflected in force[0]. This is what I need to do but with the second code sample formula.

So it seems to me there is someting related with the float management. I cannot use the double type because both SyncRead and SyncWrite return an error.

With reference to my first code sample

C#
public static void Write_synchr(RSIOPC r)
{
  try
    {
      DataToSend.SetValue(r.array_to_send, 1);
      r.RSLinxOPCgroup_w.SyncWrite(1, ref r.SyncServerHandles_w, ref DataToSend, out SyncErrors2);
    }
  catch (Exception e)
    {
      MessageBox.Show(e.ToString(), "Error:  ",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

}

In the loop I set the value of r.array_to_send[0] with the value of filter[0] and the value of r.array_to_send[1] with the value of the pulse generated with the button in the form.

I like to remember that with the following formula I have no problem at all

C#
r.array_to_send[0] = (float)(2 * Math.Cos((2 * (1.0 / Time_period[0]) * Math.PI) * t));


I tried with other formulas and this is the result


C#
filter[0] = (float) (force[0] + 0.0 + filter[2]);
NOT WORKING
C#
filter[0] = (float) (force[0] + 0.000001 + filter[2]);
NOT WORKING
C#
filter[0] = (float) (force[0] + 0.0001 + filter[2]);
WORKING

Sigh | :sigh:
AnswerRe: c# OPCgroup.SyncWrite vs. Float type Pin
OriginalGriff18-Feb-21 22:38
mveOriginalGriff18-Feb-21 22:38 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 0:24
Roberto64_Ge19-Feb-21 0:24 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
OriginalGriff19-Feb-21 0:55
mveOriginalGriff19-Feb-21 0:55 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 1:41
Roberto64_Ge19-Feb-21 1:41 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
OriginalGriff19-Feb-21 1:58
mveOriginalGriff19-Feb-21 1:58 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 2:28
Roberto64_Ge19-Feb-21 2:28 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 8:27
Roberto64_Ge19-Feb-21 8:27 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge23-Feb-21 0:53
Roberto64_Ge23-Feb-21 0:53 
QuestionWinforms Usercontrol Databinding question Pin
Member 1501196518-Feb-21 5:20
Member 1501196518-Feb-21 5:20 
AnswerRe: Winforms Usercontrol Databinding question Pin
Gerry Schmitz18-Feb-21 7:38
mveGerry Schmitz18-Feb-21 7:38 
GeneralRe: Winforms Usercontrol Databinding question Pin
Member 1501196518-Feb-21 7:47
Member 1501196518-Feb-21 7:47 
GeneralRe: Winforms Usercontrol Databinding question Pin
Gerry Schmitz18-Feb-21 8:07
mveGerry Schmitz18-Feb-21 8:07 
QuestionArticle "tip/trick "Converting Enum member names and values in C#"" Pin
Сергій Ярошко16-Feb-21 22:46
professionalСергій Ярошко16-Feb-21 22:46 
AnswerRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
PIEBALDconsult17-Feb-21 3:17
mvePIEBALDconsult17-Feb-21 3:17 
GeneralRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
Сергій Ярошко17-Feb-21 4:13
professionalСергій Ярошко17-Feb-21 4:13 
GeneralRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
Richard Deeming17-Feb-21 4:31
mveRichard Deeming17-Feb-21 4:31 
GeneralRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
PIEBALDconsult17-Feb-21 5:19
mvePIEBALDconsult17-Feb-21 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.