Example #1
0
        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");
            }
        }
Example #2
0
        //add notifac
        public void addNotification(String plcVarName, Object userdata)
        {
            Type t;

            plcVarTypeMap.TryGetValue(plcVarName, out t);
            int NotificationHandle = adsClient.AddDeviceNotificationEx(plcVarName, AdsTransMode.OnChange, 100, 0, userdata, t);

            plcHNotifyVarMap.Add(NotificationHandle, plcVarName);

            // notificationHandles.Add(notifyHandle);
        }
Example #3
0
        private int RegisterNotificationHandle <T>(string variableName, int cycleTime)
        {
            cycleTime = cycleTime == -1 ? _defaultCycleTime : cycleTime;

            if (typeof(T) == typeof(string))
            {
                return(_client.AddDeviceNotificationEx(variableName, AdsTransMode.OnChange, cycleTime, _maxDelay,
                                                       null,
                                                       typeof(T), new[] { 256 }));
            }
            return(_client.AddDeviceNotificationEx(variableName, AdsTransMode.OnChange, cycleTime, _maxDelay,
                                                   null, typeof(T)));
        }
Example #4
0
        private void button5_Click(object sender, EventArgs e)
        {
            notificationHandles.Clear();
            try
            {
                //register notification
                notificationHandles.Add(adsClient.AddDeviceNotificationEx("MAIN.int1", AdsTransMode.OnChange, 100, 0, textBox2, typeof(int)));

                notificationHandles.Add(adsClient.AddDeviceNotificationEx("MAIN.bool1", AdsTransMode.OnChange, 100, 0, textBox1, typeof(Boolean)));
                notificationHandles.Add(adsClient.AddDeviceNotificationEx("MAIN.lreal1", AdsTransMode.OnChange, 100, 0, textBox4, typeof(Double)));
                notificationHandles.Add(adsClient.AddDeviceNotificationEx("MAIN.str1", AdsTransMode.OnChange, 100, 0, textBox3, typeof(String), new int[] { 5 }));
                notificationHandles.Add(adsClient.AddDeviceNotificationEx("MAIN.complexStruct1", AdsTransMode.OnChange, 100, 0, textBox5, typeof(ComplexStruct)));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            button6.Enabled = true;
            button5.Enabled = false;
        }
Example #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;

            client = new TcAdsClient();
            try
            {
                client.Connect(851);
                hint           = client.CreateVariableHandle("MAIN.int1");
                hBool          = client.CreateVariableHandle("MAIN.bool1");
                hDint1         = client.CreateVariableHandle("MAIN.dint1");
                hByte1         = client.CreateVariableHandle("MAIN.byte1");
                hReal1         = client.CreateVariableHandle("MAIN.real1");
                hLreal1        = client.CreateVariableHandle("MAIN.lreal1");
                hstr1          = client.CreateVariableHandle("MAIN.str1");
                hstr2          = client.CreateVariableHandle("MAIN.str2");
                hComplexStruct = client.CreateVariableHandle("MAIN.complexStruct");

                //----------Read int array--------
                stream = new AdsStream(10 * 2);

                Reader = new AdsBinaryReader(stream);

                hintArray = client.CreateVariableHandle("MAIN.intArray");
                //-----------------------------------
                hdintArray1 = client.CreateVariableHandle("MAIN.DintArray1");

                //-----add adsNotificationEx event---------------
                client.AdsNotificationEx += new AdsNotificationExEventHandler(ads_Notification);

                client.AddDeviceNotificationEx("MAIN.int1", AdsTransMode.OnChange, 100, 0, txtINT, typeof(short));
                client.AddDeviceNotificationEx("MAIN.bool1", AdsTransMode.OnChange, 100, 0, txtBool, typeof(Boolean));
                client.AddDeviceNotificationEx("MAIN.dint1", AdsTransMode.OnChange, 100, 0, txtDint, typeof(int));
                client.AddDeviceNotificationEx("MAIN.byte1", AdsTransMode.OnChange, 100, 0, txtByte, typeof(byte));
                client.AddDeviceNotificationEx("MAIN.real1", AdsTransMode.OnChange, 100, 0, txtReal, typeof(Single));
                client.AddDeviceNotificationEx("MAIN.lreal1", AdsTransMode.OnChange, 100, 0, txtLreal, typeof(double));
                client.AddDeviceNotificationEx("MAIN.str1", AdsTransMode.OnChange, 100, 0, txtStr1, typeof(string), new int[] { 50 });
                client.AddDeviceNotificationEx("MAIN.str2", AdsTransMode.OnChange, 100, 0, txtStr2, typeof(string), new int[] { 50 });
                //ComplexStruct cs = new ComplexStruct();
                client.AddDeviceNotificationEx("MAIN.complexStruct", AdsTransMode.OnChange, 100, 0, null, typeof(ComplexStruct));
            }
            catch (Exception err)
            {
                MessageBox.Show("Form load " + err.Message);
            }
        }
Example #6
0
 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)
     {
     }
 }
 private void CreateCurrentNotification(out string symbolName)
 {
     symbolName = null;
     try
     {
         if (currentSymbol != null)
         {
             this.notificationHandle =
                 adsClient.AddDeviceNotificationEx
                 (
                     currentSymbol.IndexGroup,
                     currentSymbol.IndexOffset,
                     AdsTransMode.OnChange, 0, 0,
                     currentSymbol,
                     GetTypeForDataTypeId(currentSymbol.Datatype)
                 );
             symbolName = currentSymbol.Name;
         }
     }
     catch (Exception err)
     {
         MessageBox.Show("Failed to create notificationHandle. " + err.Message);
     }
 }
Example #8
0
        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)
            {

            }
        }