karagoncoloz
Üye
- Katılım
- 22 Eyl 2010
- Mesajlar
- 12
- Puanları
- 1
merhaba arkadaşlar, S7-300 PLC ye Cp5611 kart ile bağlandım. "Softing OPC" server a VS2010 express C# ile Client yazıp SQL e veri kaydetmek istiyorum. internette dolaşan şu örnek kodu derliyorum ama hata veriyor.
Hata mesajı :
hata mesajıyla ilgili internette 32bit/64 bit derleyici ayarlarına atıfta bulunulmuş, derleyiciyi x86 olarak ayarladım mesaj değişmedi. regasm ile automation.dll in registry'ye kayıt edilmesiyle alakalı yazılar mevcut. framework 4 klasöründen kayıt etmeyi denedim yine olmadı. daha önce benzer kodlarla TCP den kepware le schneider PLC ye baglandığımı hatırlıyorum. registry ile ilgili hiç bir ayar yapmadan değer okumuştum sanırım. fikri olan?
Kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OPCAutomation;
namespace OPC2
{
public partial class Form1 : Form
{
public OPCAutomation.OPCServer AnOPCServer;
public OPCAutomation.OPCServer ConnectedOPCServer;
public OPCAutomation.OPCGroups ConnectedServerGroup;
public OPCAutomation.OPCGroup ConnectedGroup;
public string Groupname;
int ItemCount;
Array OPCItemIDs = Array.CreateInstance(typeof(string), 10);
Array ItemServerHandles = Array.CreateInstance(typeof(Int32), 10);
Array ItemServerErrors = Array.CreateInstance(typeof(Int32), 10);
Array ClientHandles = Array.CreateInstance(typeof(Int32), 10);
Array RequestedDataTypes = Array.CreateInstance(typeof(Int16), 10);
Array AccessPaths = Array.CreateInstance(typeof(string), 10);
Array WriteItems = Array.CreateInstance(typeof(object), 10);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnConnect_Click(object sender, EventArgs e)
{
try
{
string IOServer = "Kepware.KEPServerEX.V5";
string IOGroup = "OPCGroup1";
ConnectedOPCServer = new OPCAutomation.OPCServer();
ConnectedOPCServer.Connect(IOServer, "");
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add(IOGroup);
ConnectedGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(ObjOPCGroup_DataChange);
ConnectedGroup.UpdateRate = 1000;
ConnectedGroup.IsSubscribed = ConnectedGroup.IsActive;
ItemCount = 2;
OPCItemIDs.SetValue("Channel2.Device1.R1", 1);
ClientHandles.SetValue(1, 1);
OPCItemIDs.SetValue("Channel2.Device1.R2", 2);
ClientHandles.SetValue(2, 2);
ConnectedGroup.OPCItems.DefaultIsActive = true;
ConnectedGroup.OPCItems.AddItems(ItemCount, ref OPCItemIDs, ref ClientHandles, out ItemServerHandles, out ItemServerErrors, RequestedDataTypes, AccessPaths);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
ConnectedOPCServer.Disconnect();
}
private void ObjOPCGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
{
try
{
for (int i = 1; i <= NumItems; i++)
{
if ((Convert.ToInt32(ClientHandles.GetValue(i)) == 1))
{
textBox1.Text = ItemValues.GetValue(i).ToString();
}
if ((Convert.ToInt32(ClientHandles.GetValue(i)) == 2))
{
textBox2.Text = ItemValues.GetValue(i).ToString();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void btnWrite1_Click(object sender, EventArgs e)
{
try
{
WriteItems.SetValue(textBox4.Text, 1);
ConnectedGroup.SyncWrite(ItemCount, ref ItemServerHandles, ref WriteItems, out ItemServerErrors);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
Kod:
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {28E68F9A-8D75-11D1-8DC3-3C302A000000} failed due to the following error: 80040154 Sınıf kaydedilmemiş (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\plc\belgelerim\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 45
Son düzenleme: