public void activateAndRunPLC() { adsClient.Connect(sysMan.GetTargetNetId(), 10000); //AMS net id of target system. TwinCAT system service port = 10000 System.Threading.Thread.Sleep(10000); //waiting for TwinCAT to go into Run mode. sysMan.ActivateConfiguration(); sysMan.StartRestartTwinCAT(); try { bool rundo = true; do { if (adsClient.ReadState().AdsState == AdsState.Run) //reads TwinCAT's system state, if it is in run mode then log into plc. { string xml = "<TreeItem><IECProjectDef><OnlineSettings><Commands><LoginCmd>true</LoginCmd><StartCmd>true</StartCmd></Commands></OnlineSettings></IECProjectDef></TreeItem>"; ITcSmTreeItem plcProject = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project"); plcProject.ConsumeXml(xml); rundo = false; } } while (rundo); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void tryConnect() { if (!connected) { if (lastErrorTime.HasValue) { // wait a bit before re-establishing connection var elapsed = DateTime.Now .Subtract(lastErrorTime.Value); if (elapsed.TotalMilliseconds < 3000) { return; } } try { client.Connect(port); connected = client.IsConnected; } catch (AdsException) { connectError(); } } }
private void Connect() { try { _twinCatClient.Connect(_adsAddress, _adsPort); _twinCatClientBackground.Connect(_adsAddress, _adsPort); _twinCatClient.Timeout = Timeout; _twinCatClientBackground.Timeout = Timeout; while (_twinCatClient.ReadState().AdsState != AdsState.Run) { Thread.Sleep(1000); if (_logger != null) { _logger.Warn("TagController still not connected to " + _adsAddress + ":" + _adsPort + " . Wait for ADS state RUN"); } } } catch (AdsException adsException) { var message = new StringBuilder().AppendLine() .AppendFormat("Tried to connect over twin cat client to '{0}:{1}'.", _adsAddress, _adsPort).AppendLine() .AppendFormat("The twin cat client returned the message: {0}", adsException.Message).AppendLine(); throw new PlcCommunicationException(message.ToString(), _adsAddress, adsException); } }
public ObservableForTests() { adsClient = new TcAdsClient(); adsClient.Connect(851); client = new TwinCatRxClient(adsClient); }
/// <summary> /// Connects to TwinCAT Ads via TcAdsClient.Connect. Hooks up Ads events to logging text box /// </summary> /// <param name="amsNetId">As defined in TwinCAT Project (in Project > System > Routes > Project Routes). Something like 192.168.0.1.1.1 </param> /// <param name="port">As defined in TwinCAT. Normally 851 or 852</param> public void Connect(string amsNetId, int port) { try { if (TcClient == null) { TcClient = new TcAdsClient(); } TcClient.ConnectionStateChanged += TcClient_ConnectionStateChanged; TcClient.AdsNotification += TcClient_AdsNotification; TcClient.AdsNotificationError += TcClient_AdsNotificationError; TcClient.AdsNotificationEx += TcClient_AdsNotificationEx; TcClient.AdsStateChanged += TcClient_AdsStateChanged; TcClient.AdsSymbolVersionChanged += TcClient_AdsSymbolVersionChanged; TcClient.AmsRouterNotification += TcClient_AmsRouterNotification; AmsNetId id = new AmsNetId(amsNetId); TcClient.Connect(id, port); } catch (Exception e) { Send_TcClient_EventHandling(DateTime.Now, LogTextCategory.Error, string.Format("Could not connect to ADS Server: {0}", e)); } }
private void IOPage_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; ioClient = new TcAdsClient(); try { ioClient.Connect(851); } catch (Exception err) { MessageBox.Show("IO page: client to PLC: " + err.Message); } try { ioClient.AddDeviceNotificationEx("GVL_General.bLamp01", AdsTransMode.OnChange, 100, 0, ioBtnLamp01, typeof(Boolean)); ioClient.AddDeviceNotificationEx("GVL_General.bLamp02", AdsTransMode.OnChange, 100, 0, ioBtnLamp02, typeof(Boolean)); ioClient.AddDeviceNotificationEx("GVL_General.bLamp03", AdsTransMode.OnChange, 100, 0, ioBtnLamp03, typeof(Boolean)); ioClient.AddDeviceNotificationEx("GVL_General.bLamp04", AdsTransMode.OnChange, 100, 0, ioBtnLamp04, typeof(Boolean)); ioClient.AdsNotificationEx += Client_AdsNotificationEx; } catch (Exception) { // throw; MessageBox.Show("add device notification"); } }
private void buttonConnect_Click(object sender, EventArgs e) { // luodaan AdsClient-olio yhteyttä varten adsClient = new TcAdsClient(); // otetaan yhteys TwinCAT PLC:hen portin 851 kautta adsClient.Connect(851); // luodaan PLC:n muuttujiin viittaavat "osoittimet" startHandle = adsClient.CreateVariableHandle("MAIN.start"); stopHandle = adsClient.CreateVariableHandle("MAIN.reset"); // Luodaan tapahtumankäsittelijä. Parametrina näyttöä päivittävän metodin nimi adsClient.AdsNotification += new AdsNotificationEventHandler(UpdateVariables); // avataan Ads-stream (luettava byte-määrä pitänee antaa parametrina this.adsStream = new AdsStream(24); binReader = new BinaryReader(this.adsStream); /* * timeHi: UDINT; // aika * timeLo: UDINT; // aika * measurement1: REAL; // mittaus 1 * measurement2: REAL; // mittaus 2 * measurement3: REAL; // mittaus 3 * counter: INT; // juokseva numero * arrayValue: INT; // jotain * */ measurementDataHandle = adsClient.AddDeviceNotification("MAIN.measurementData", this.adsStream, 0, 24, AdsTransMode.Cyclic, 100, 0, null); buttonConnect.Enabled = false; buttonSetSR1.Enabled = true; buttonResetSR1.Enabled = false; }
public bool writeToPLCString(string sName, string sValue) { bool bret = true; TcAdsClient tcClient = new TcAdsClient(); AdsStream dataStream = new AdsStream(100); AdsBinaryReader binReader = new AdsBinaryReader(dataStream); int iHandle = 0; tcClient.Connect(851); iHandle = tcClient.CreateVariableHandle(sName); try { tcClient.WriteAnyString(iHandle, sValue, sValue.Length, Encoding.Default); } catch (Exception ex) { Console.WriteLine(ex.Message); bret = false; } finally { tcClient.DeleteVariableHandle(iHandle); tcClient.Dispose(); } return(bret); }
private void Form1_Load(object sender, System.EventArgs e) { try { log.Debug("Start app debugging"); log.Info("Start timer tick- 10sec "); InitTimer(); //Connecto ADS Server log.Info("Connecting to PLC via ADS "); adsClient = new TcAdsClient(); adsClient.Connect(netidplc, 851); symbolLoader = adsClient.CreateSymbolInfoLoader(); //Open connection log.Info("Connecting to PostgreSQL Server "); TestconnOpen(); //Open connection log.Info("Connecting to PostgreSQL Server "); PrepareLiveTable(); PrepareAccuTable(); } catch (Exception err) { log.Debug(err.Message); } }
public StreamTests() { adsClient = new TcAdsClient(); adsClient.Connect(851); client = new TwinCatRxClient(adsClient); }
public void InitializeInterface() { dataStream = new AdsStream(255); //Encoding wird auf ASCII gesetzt, um Strings lesen zu können binRead = new BinaryReader(dataStream, System.Text.Encoding.ASCII); // Instanz der Klasse TcAdsClient erzeugen tcClient = new TcAdsClient(); // Verbindung mit Port 851 auf dem lokalen Computer herstellen tcClient.Connect(851); hConnect = new int[7]; aiData = new int[7]; try { hConnect[0] = tcClient.AddDeviceNotification(m_sVariabelName, dataStream, 0, 255, AdsTransMode.OnChange, 500, 0, aiData); //hConnect[1] = tcClient.AddDeviceNotification("MAIN.intVal", dataStream, 1, 2, AdsTransMode.OnChange, 100, 0, tbInt); } catch (Exception err) { bool b = true; while (b) { string message = "Connection to PLC-Variables failed. Please Run TwinCat or check declared variables and retry"; string caption = "Connection failed!"; } } tcClient.AdsNotification += new AdsNotificationEventHandler(OnNotification); }
//TcAdsClient tcClient = new TcAdsClient(); //AdsStream dataStream = new AdsStream(4); //AdsBinaryReader binReader = new AdsBinaryReader(dataStream); public bool writeToPLCInt(string sName, int iValue) { TcAdsClient tcClient = new TcAdsClient(); AdsStream dataStream = new AdsStream(4); AdsBinaryReader binReader = new AdsBinaryReader(dataStream); int iHandle = 0; tcClient.Connect(851); iHandle = tcClient.CreateVariableHandle(sName); try { tcClient.WriteAny(iHandle, iValue); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { tcClient.DeleteVariableHandle(iHandle); tcClient.Dispose(); } return(true); }
public static void WriteBusQueue(List <string> list) { try { WriteTwincat("GVL.EraseTable", true); TcAdsClient client = new TcAdsClient(); client.Connect(amsnetid, Convert.ToInt32(amsnetport)); int handle = client.CreateVariableHandle("GVL.DataFromBus"); foreach (string el in list) { AdsStream stream = new AdsStream(500); AdsBinaryWriter writer = new AdsBinaryWriter(stream); writer.WritePlcString(el, 500, Encoding.Unicode); client.Write(handle, stream); stream.Dispose(); writer.Dispose(); Thread.Sleep(10); } client.DeleteVariableHandle(handle); client.Dispose(); } catch (Exception ex) { Console.WriteLine("BusWrite: " + ex.Message); } }
private void btnLoad_Click(object sender, System.EventArgs e) { treeViewSymbols.Nodes.Clear(); //check adr info AmsAddress serverAddress = null; try { // check if port is a hex value if (tbAdsPort.Text.StartsWith(("0x")) || tbAdsPort.Text.StartsWith(("0X"))) { string sHexValue = tbAdsPort.Text.Substring(2); serverAddress = new AmsAddress(tbNetID.Text, Int32.Parse(sHexValue, System.Globalization.NumberStyles.HexNumber)); } // interpret as dec value else { serverAddress = new AmsAddress(tbNetID.Text, Int32.Parse(tbAdsPort.Text)); } } catch { MessageBox.Show("Invalid AMS NetId " + tbNetID.Text + " or Ams port " + tbAdsPort.Text + "!"); return; } //connect try { //orig for just 127.0...: adsClient.Connect(Convert.ToInt32(tbAdsPort.Text)); adsClient.Connect(serverAddress.NetId, serverAddress.Port); symbolLoader = adsClient.CreateSymbolInfoLoader(); if (!cbFlat.Checked) { TcAdsSymbolInfo symbol = symbolLoader.GetFirstSymbol(true); while (symbol != null) { treeViewSymbols.Nodes.Add(CreateNewNode(symbol)); symbol = symbol.NextSymbol; } } else { foreach (TcAdsSymbolInfo symbol in symbolLoader) { TreeNode node = new TreeNode(symbol.Name); node.Tag = symbol; treeViewSymbols.Nodes.Add(node); } } } catch (Exception err) { MessageBox.Show(err.Message); } }
static void Main(string[] args) { TcAdsClient tcClient = new TcAdsClient(); AdsStream dataStream = new AdsStream(4); AdsBinaryReader binReader = new AdsBinaryReader(dataStream); int handle = 0; int iValue = 0; int exValue = 0; string variable, adres; DateTime now = DateTime.Now; Console.WriteLine("Podaj adres serwera ADS: "); adres = Console.ReadLine(); Console.WriteLine("Podaj nazwe zmienna do zapysywania w bazie danych: "); variable = Console.ReadLine(); FileStream File = new FileStream("data.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter writer = new StreamWriter(File); writer.WriteLine(adres + " 801 " + variable + " " + now.ToString("F")); try { tcClient.Connect(adres, 801); handle = tcClient.CreateVariableHandle(variable); Console.WriteLine("Czekam na znak"); do { tcClient.Read(handle, dataStream); iValue = binReader.ReadInt32(); dataStream.Position = 0; if (iValue != exValue) { writer.WriteLine(iValue + " " + now.ToString("F")); } Console.WriteLine("Aktualna wartosc wynosi: " + iValue); exValue = iValue; } while (Console.ReadKey().Key.Equals(ConsoleKey.Enter)); } catch (Exception ex) { Console.WriteLine(ex.Message + " xdddd"); } finally { writer.Close(); tcClient.DeleteVariableHandle(handle); tcClient.Dispose(); } Console.ReadKey(); }
/** * Reads the variables contained in the list "vars" (read from the config file). * Adds each supplied variable name as a key to a JSON-object, as well as its value * as read from the PLC. A timestamp is added (Linux epoch milliseconds). The JSON-object * is then sent to CouchDB. **/ static void Main(string[] args) { TcAdsClient tcAds = new TcAdsClient(); //Dictionary containing the configuration keys and values from the data.conf file. Dictionary<string, string> props = new Dictionary<string, string>(); //List containing the variables to be read from the PLC and stored in the CouchDB database List<string> vars = new List<string>(); //Populate the props dictionary and vars list from the content of the data.conf file readFile(props, vars, "data.conf"); //Connect to the PLC Console.WriteLine("Connecting to " + props["netId"] + " on port " + props["adsport"]); tcAds.Connect(props["netId"], Convert.ToUInt16(props["adsport"])); //Create and build the JSON-object. JObject jobj = new JObject(); jobj.Add("timestamp",(long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds); foreach (string s in vars) { float value = readByString(tcAds, s, "REAL"); jobj.Add(s, value); } //End connection to the PLC. tcAds.Dispose(); //Info printout of JSON-object Console.WriteLine(jobj.ToString()); //Create a web request for posting to CouchDB. WebRequest request = WebRequest.Create(props["dbprotocol"]+"://"+props["dbip"]+":"+props["dbport"]+"/"+props["dbname"]); request.Method = "POST"; request.Credentials = new NetworkCredential(props["dbusername"],props["dbpassword"]); string postData = jobj.ToString(); byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/json"; request.ContentLength = postData.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); //Get and print the response from the server WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); reader.Close(); dataStream.Close(); response.Close(); }
public async Task OnExecute() { var adsClient = new TcAdsClient { Synchronize = false }; var handle = GetConsoleWindow(); ShowWindow(handle, SW_HIDE); CreateLogger(); var logger = LoggerFactory.GetLogger(); try { logger.Debug("Starting Json Read Writer"); logger.Debug($"Connecting to Beckhoff Port: {AdsPort} - AdsNet: '{AdsNetId}'"); adsClient.Connect(AdsNetId, AdsPort); logger.Debug($"Method: {Method}"); logger.Debug($"File: {FilePath}"); logger.Debug($"Field: {Field}"); logger.Debug($"Executing..."); if (Method == FileOperationMethod.Write) { var content = File.ReadAllText(FilePath); logger.Debug($"Writing json into {Field}..."); var objectResponse = JObject.Parse(content); await adsClient.WriteJson(Field, objectResponse); } else if (Method == FileOperationMethod.Read) { var json = await adsClient.ReadJson(Field); File.WriteAllText(FilePath, json.ToString()); } else { logger.Warn("Invalid Method"); } adsClient.Disconnect(); } catch (Exception e) { logger.Error($"Error while calling Json Parser: {e}", e); logger.Error($"{e.StackTrace}"); } finally { adsClient?.Dispose(); } }
private void ConnectAds() { _tcClient = new TcAdsClient(); string netid = "5.39.221.128.1.1"; int net_port = 0x8888; AmsAddress serverAddress = new AmsAddress(netid, net_port); //配置服务端地址 _tcClient.Connect(serverAddress.NetId, serverAddress.Port); //连接服务端 }
/// <summary> /// Establishes a connection to the ADS device. /// If AmsNetId has not been supplied this connects using localport. /// If Port has not been supplied this connects using port 851 /// </summary> public void Connect() { vStream = new AdsStream(ReadStreamSize); // Create new Stream Reader vBinaryReader = new AdsBinaryReader(vStream); // Create new binary reader vAdsClient = new TcAdsClient(); // Create new Ads Client // If amsNetId == "" use the local port, if not connect to the provided Net ID if (amsNetId == "") { vAdsClient.Connect(port); } else { vAdsClient.Connect(amsNetId, port); } // Subscribe to the ADS notification event vAdsClient.AdsNotification += new AdsNotificationEventHandler(PLCReadNotification); }
public Form1() { try { initTime = DateTime.Now; //Calls calculation method for filters highCoeff = filterCoeff(double.Parse(ConfigurationManager.AppSettings.Get("angleHighPass")), sampFreq / bufferSize, "High"); lowCoeff = filterCoeff(double.Parse(ConfigurationManager.AppSettings.Get("angleLowPass")), sampFreq / bufferSize, "Low"); bandHighCoeff = filterCoeff(double.Parse(ConfigurationManager.AppSettings.Get("velocityHighPass")), sampFreq / bufferSize, "High"); bandLowCoeff = filterCoeff(double.Parse(ConfigurationManager.AppSettings.Get("velocityLowPass")), sampFreq / bufferSize, "Low"); //2*10^-2 InitializeComponent(); // Initializes the visual components SetSize(); // Sets up the size of the window and the corresponding location of the components Frameco = 0; dayFrameCo0 = DayNr.GetDayNr(DateTime.Now); //Initialization of TwinCAT connection. 851 is the port for PLC runtime 1 if (twinCatBool) { tcAds.Connect(851); } myStopwatch = new Stopwatch(); dataWritingSyncEvent = new SyncEvents(); consumerd = new DataConsumerDelegate[2]; consumerd[0] = new DataConsumerDelegate(new DataConsumerDelegate.outputDelegate(showStatistics), true); consumerd[1] = new DataConsumerDelegate(new DataConsumerDelegate.outputDelegate(Pattern), true); consumerd[1].myThread.Priority = ThreadPriority.Highest; for (int i = 0; i < consumerd.Length; i++) { consumerd[i].myThread.Start(); } dataWritingQueue = new Queue <PeakQueueItem>(); dataWritingThreadBool = true; dataWritingThread = new Thread(dataWrite); dataWritingThread.Priority = ThreadPriority.Highest; dataWritingThread.Start(); Thread.Sleep(10); cameraThread = new Thread(initCamera); cameraThread.Priority = ThreadPriority.Highest; cameraThread.Start(); curDirec = System.IO.Path.GetDirectoryName(Application.ExecutablePath); System.Diagnostics.Process.Start(curDirec + "\\AffinitySet.bat"); } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { EmailError.emailAlert(ex); throw (ex); } }
private static void SetConfigMode() { var client = new TcAdsClient(); var mode = new StateInfo(); client.Connect((int)AmsPort.SystemService); mode.AdsState = client.ReadState().AdsState; mode.AdsState = AdsState.Reconfig; client.WriteControl(mode); client.Dispose(); }
public void Connect(int port = 851) { try { m_adsClient.Connect(port); } catch (Exception err) { throw (new SystemException(err.Message)); } }
/// <summary> /// ADS通讯连接 /// </summary> /// <param name="IpAddress">IP地址</param> /// <param name="Port">端口</param> /// <param name="Pvc">基础地址数据</param> /// <param name="IsDiffComputer">是否不在相同电脑上</param> public TwcAds(string IpAddress, int Port, PlcVariableClass Pvc, bool IsDiffComputer) { try { pvc = Pvc; isDiffComputer = IsDiffComputer; _client = new TcAdsClient(); notificationHandles = new ArrayList(); _client.AdsNotificationEx += new AdsNotificationExEventHandler(adsClient_AdsNotificationEx); if (isDiffComputer) { _client.Connect(new AmsNetId(IpAddress), Port);//不同电脑 } else { _client.Connect(851);//同一电脑 } _handBool = _client.CreateVariableHandle(pvc.Test); //测试PLC连接并注册 tr = new Thread(() => { while (true) { this.TestConnect(); if (ConnectFlag && !isRegistered) { RegNotificationHandles(); } Thread.Sleep(10); } }); tr.IsBackground = true; tr.Start(); } catch (Exception ex) { msg = ex.Message; ConnectFlag = false; return; } }
void _Connect(string IpAddress, int port) { try { m_adsClient = new TcAdsClient(); m_adsClient.Connect(IpAddress, port); } catch (Exception err) { throw (new SystemException(err.Message)); } }
private void AdsConnect_Click(Object sender, EventArgs e) { tcClient = new TcAdsClient(); tcClientTaskValues = new TcAdsClient(); readStream = new AdsStream(sizeof(double)); reader = new AdsBinaryReader(readStream); try { if (checkBoxAdsLocal.Checked) { amsAddressTcCom = new AmsAddress(10); amsAddressTask = new AmsAddress(350); tcClient.Connect(10); tcClientTaskValues.Connect(350); } else { amsAddressTcCom = new AmsAddress(RouteNetId[comboBoxAdsTargets.SelectedIndex].InnerText, 10); amsAddressTask = new AmsAddress(RouteNetId[comboBoxAdsTargets.SelectedIndex].InnerText, 350); tcClient.Connect(amsAddressTcCom); tcClientTaskValues.Connect(amsAddressTask); } // Read the state of the device StateInfo stateInfo = tcClient.ReadState(); _cts = new CancellationTokenSource(); Task.Run(async() => await AdsSymbolUpdate()); UI_Connected(); ChangeChannelSettings(Color.Green, Color.DarkGreen); SetAcquisitions(); Start_Scope(); } catch (AdsException ex) { MessageBox.Show("Could not connect to ADS target...\n\n\nException: " + ex.Message); } }
private void Form1_Load(object sender, EventArgs e) { client = new TcAdsClient(); try { client.Connect(851); hint = client.CreateVariableHandle("MAIN.int1"); } catch (Exception err) { MessageBox.Show("Form load " + err.Message); } }
public void InitializeConnection() { _tcClient = new TcAdsClient(); _tcClient.Connect("172.20.136.133.1.1", 851); if (_tcClient.IsConnected) { Debug.Log("Twin CAT ADS port connected"); } else { Debug.LogError("ADS Connection failed"); } }
private void Form1_Load(object sender, System.EventArgs e) { try { adsClient = new TcAdsClient(); adsClient.Connect(851); symbolLoader = adsClient.CreateSymbolInfoLoader(); } catch (Exception err) { MessageBox.Show(err.Message); } }
public void Connect() { lock (criticalLock) { try { if (netId == "") { client.Connect(port); } else { client.Connect(netId, port); } } catch (Exception e) { string str = string.Format("Occurred exception({0}) in UlTcAdsClient::Connect", e.ToString()); throw new Exception(str); } } }
private void Sample02_Load(object sender, EventArgs e) { try { client = new TcAdsClient(); client.Connect(851); hPLCVar = client.CreateVariableHandle("MAIN.PLCVar"); } catch (Exception err) { MessageBox.Show("Sample02_Load " + err.Message); } }
void ConnectCommand_Executed(Object Parameter) { tcClient = new TcAdsClient(); try { IP = "172.18.226.186.1.1"; Port = 851; tcClient.Connect(IP, Port); } catch (Exception ex) { MessageBox.Show(ex.Message + "Cannot connect with PLC(ConnPLC)"); } }
public WoopsaAdsServer(string netId) { _netId = netId; _tcAds = new TcAdsClient(); try { _tcAds.Connect(netId, _PORT); } catch (Exception) { isAdsConnected = false; } _woopsaAdsPropertyGet = this.ReadAdsValue; _woopsaAdsPropertySet = this.WriteAdsValue; }
public override void init() { adsClient = new TcAdsClient(); nameDict["MAIN.MDF_WhichStack"] = typeof(int); nameDict["MAIN.MDF_WhichDish"] = typeof(int); nameDict["MAIN.MDF_RunningError"] = typeof(int); nameDict["MAIN.MDF_online_state"] = typeof(int); nameDict["MAIN.MDF_Command_response"] = typeof(String); nameDict["MAIN.MDF_bar_code"] = typeof(string); nameDict["MAIN.MDF_Motor_1_cur"] = typeof(float); nameDict["MAIN.MDF_Motor_2_cur"] = typeof(float); nameDict["MAIN.MDF_Motor_3_cur"] = typeof(float); nameDict["MAIN.MDF_Motor_4_cur"] = typeof(float); nameDict["MAIN.CCS_to_MDF_command_listen"] = typeof(String); nameDict["MAIN.CCS_to_MDF_NumsperStack_listen"] = typeof(int); nameDict["MAIN.CCS_to_MDF_VolsperDish_listen"] = typeof(float); cmdString = "MAIN.MDF_Command_response"; try { adsClient.Connect(801); adsClient.AdsNotificationEx += new AdsNotificationExEventHandler(handleNotification); foreach (String s in nameDict.Keys) { handleMap[s] = adsClient.CreateVariableHandle(s); if (nameDict[s] == typeof(string)) { adsClient.AddDeviceNotificationEx(s, AdsTransMode.OnChange, 100, 0, s, nameDict[s],new int[]{ConstSettings.StringLength}); } else { adsClient.AddDeviceNotificationEx(s, AdsTransMode.OnChange, 100, 0, s, nameDict[s]); } } adsClient.WriteAny(handleMap["MAIN.MDF_online_state"], 1); } catch (Exception ex) { } }