Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

windows service not open connection opc

More
15 Oct 2012 19:44 #1058 by support
We provide support in English language.
Technical support is not a one way communication. You need to do your part if you want to get results. In this case, you may e.g.

Debug the Windows Service. Startup problems like this are a bit complicated to debug, but one way to do it is to put Thread.Sleep at the beginning of the code, and then, while the service is "starting" use the sleep time to attach the debugger to the process.
Put try/catch inside the OnStart method (and possibly the ItemChanged event handler), log the exceptions, and see if something interesting comes out of it.

Best regards,

Please Log in or Create an account to join the conversation.

More
15 Oct 2012 19:12 #1057 by alissonhaubert
I do not know exactly, maybe, when I start the windows service now returns me this message!
Att Alisson.

Please Log in or Create an account to join the conversation.

More
15 Oct 2012 18:57 #1056 by support
An exception in the OnStart method?

Please Log in or Create an account to join the conversation.

More
15 Oct 2012 18:14 #1055 by alissonhaubert
Hello, I installed the service you gave me, but when I start the service I get the following message.

"The Service1 service on Local Computer started and stopped. Some services stop automatically if they are not being used by other services or programs."

Any idea what might be happening?

Please Log in or Create an account to join the conversation.

More
15 Oct 2012 14:45 #1054 by support
Hello, it is not clear from your answer whether you have tried with our simulation server and wha the result was in that case, can you please clarify.
I have made a Windows service project that demonstrates SubscribeMultipleItems. It is attached here:
WindowsService1.zip
Here is the main part of the code:

public partial class Service1 : ServiceBase
{
const string FilePath = "C:\\Service1.txt";

public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
File.Create(FilePath).Close();

easyDAClient1.SubscribeMultipleItems(
new[]
{
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Incrementing (1 s)", 100, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Ramp (10 s)", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_BSTR", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_BOOL", 1000, null)
});
}

protected override void OnStop()
{
easyDAClient1.UnsubscribeAllItems();
}

// ReSharper disable InconsistentNaming
private void easyDAClient1_ItemChanged([NotNull] object sender, [NotNull] EasyDAItemChangedEventArgs e)
// ReSharper restore InconsistentNaming
{
string line;
if (e.Exception == null)
{
Trace.Assert(e.Vtq != null);
line = string.Format("{0}: {1}", e.ItemDescriptor.ItemId, e.Vtq.DisplayValue());
}
else
line = String.Format("{0}: ** {1} **", e.ItemDescriptor.ItemId, e.Exception.GetBaseException());

using (var textWriter = File.AppendText(FilePath))
textWriter.WriteLine(line);
}
}

And here is a part of the service's output:

Simulation.Incrementing (1 s):
Simulation.Register_BSTR:
Simulation.Ramp (10 s): 0.387221097946167
Simulation.Register_BOOL: False
Simulation.Incrementing (1 s): 0
Simulation.Incrementing (1 s): 1
Simulation.Ramp (10 s): 0.488921165466309
Simulation.Incrementing (1 s): 2
Simulation.Ramp (10 s): 0.589621067047119
Simulation.Incrementing (1 s): 3
Simulation.Ramp (10 s): 0.691320896148682
Simulation.Incrementing (1 s): 4
Simulation.Ramp (10 s): 0.793121099472046
Simulation.Incrementing (1 s): 5


It subscribes to items from our simulation server, and logs their changes into a file. I have verified that it works well, on a fresh machine.
Note:

If you get "Access denied" error when starting the service, change its configuration to run under Local System account.
I do not recommend calling Read or Write methods inside the service's OnStart, OnStop methods.

Please let me know whether this projects works for you - and based on the outcome, we can go further.
Best regards

Please Log in or Create an account to join the conversation.

More
15 Oct 2012 11:04 #1053 by alissonhaubert
Already tried with ReadItemVaule and also SubscribeMultipleItems, but without success in both, in the previous post I posted my code, it is quite simple exception and I'm recording in a txt through the event OPCException used in a Try Catch.

Please Log in or Create an account to join the conversation.

More
14 Oct 2012 09:32 #1052 by support
Hello,
you are right, at some point in my previous reply I got confused and assumed that we are discussing a Web service - sorry for that. Points 1 and 2 of my answer are valid, point 3 is partially valid (even if not under IIS, issues with the user account running the service still apply to Windows service), and please ignore point 4.
The error you are getting indicates that there is a problem connecting to the server, most likely of on the necessary calls has blocked for very long time. If the same works from the console app, I would still suspect some security-related problem. Is the OPC server set in DCOMCNFG to run under specific account? It should be - otherwise, two instances of it might get started. Does the same thing work with our simulation server contained in the product?
Thank you

Please Log in or Create an account to join the conversation.

More
11 Oct 2012 12:54 #1051 by alissonhaubert
I think you're not very good at understanding what I'm trying to do is a windows service, and not a web service, does not involve IIS, now I'm trying to do a very simple, which generates a txt file with the value of reading , or opc exception, below the code I'm using:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Linq;

using System.ServiceProcess;

using System.Text;

using System.Threading.Tasks;

using OpcLabs;

using OpcLabs.EasyOpc;

using OpcLabs.EasyOpc.DataAccess;



namespace WindowsService2

{

public partial class Service1 : ServiceBase

{

public Service1()

{

InitializeComponent();

}



protected override void OnStart(string[] args)

{





var t = new EasyDAClient();

string texto = "";



try

{

texto = t.ReadItemValue("", "CoDeSys.OPC.02", "PLC1:.TAG_Example").ToString();

}

catch (OpcException Err)

{

text = Err.ToString();

}





String ArchiveName = "C:/TestArchive.txt";



if (!System.IO.File.Exists(ArchiveName))

System.IO.File.Create(ArchiveName).Close();



System.IO.TextWriter arqTXT = System.IO.File.AppendText(ArchiveName);



arqTXT.WriteLine(text);



arqTXT.Close();







}



protected override void OnStop()

{

}

}

}


the service is starting and is generating an exception OPC, which is as follows:
OpcLabs.EasyOpc.OpcException: OPC operation failure. ---> System.Runtime.InteropServices.COMException: Cannot connect Data Access client (timeout).
--- End of inner exception stack trace ---
at OpcLabs.EasyOpc.OperationResult.ThrowIfFailed()
at OpcLabs.EasyOpc.DataAccess.EasyDAClient.ReadItemValue(ServerDescriptor serverDescriptor, DAItemDescriptor itemDescriptor)
at OpcLabs.EasyOpc.DataAccess.EasyDAClient.ReadItemValue(String machineName, String serverClass, String itemId, VarType dataType)
at OpcLabs.EasyOpc.DataAccess.EasyDAClient.ReadItemValue(String machineName, String serverClass, String itemId)
at WindowsService2.Service1.OnStart(String[] args) in c:\Users\Flessak\Documents\Visual Studio 2012\Projects\WindowsService2\WindowsService2\Service1.cs:line 32
I have given permissions to the temp folder of the user that I am using ...
Att Alisson.



Please Log in or Create an account to join the conversation.

More
11 Oct 2012 07:19 #1049 by support
Alright, there are multiple things involved here.

You should be able to debug the windows service. It is supported by Microsoft. Without having information about what is happening inside, hardly any recommendations or conclusions can be made.
Even if debugging using the debugger is not possible, it is practically always possible to debug using other tools, such as by logging the progress of the code into a file, including values that are of interest. We need to know if your code is even getting to the SubscribeItem/SubscribeMultipleItems statement, what are precisely the values you are complaining about, whether there are exceptions, etc.
The component needs access to a temporary folder (this is per-user temp folder, not \Windows\Temp). This can be a problem under IIS, where the default app pool does not allow it. For start, assign the Web service to a newly created app pool, and set that AppPool to run under identity that has guaranteed good access to a temp file location - such as your own account. If that helps, the right setting (security-wise) can be determined later.
I do not quite understand how you intend to use OPC subscriptions with the Web service. There is a clash between the two models: OPC subscriptions come "when they want", whereas the Web service must fulfill requests "when the client wants". You cannot have both at the same time. The closest you can get is to store the outcome of subscription notifications somewhere, and then provide those values to the clients from that storage. But that would be too much coding for nothing: You can omit the OPC subscriptions, simply call ReadItem or ReadMultipleItems, and the component will make OPC subscriptions internally, invisible to you, if needed.

Best regards
Zbynek Zahradnik

Please Log in or Create an account to join the conversation.

More
10 Oct 2012 11:07 #1046 by alissonhaubert
Hello, I am not able to debug the windows service to know more precisely what happens, so I can not tell you what happens.
How do I know quand starts the windows service does not start the opc? Is that what I have here the OPC opens an icon next to the clock windows whenever the OPC starts and this is not happening at all.
Would not you could send me an example of a windows service running on multiple items subscribe? can be very basic, just for me to build it.
I thank you understand!

Att
Alisson R. S. Haubert

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.072 seconds