Пример #1
0
        /// <summary>
        /// 按索引号设置宏变量的值
        /// </summary>
        /// <param name="no"></param>
        /// <param name="var"></param>
        /// <param name="clientNo"></param>
        /// <returns></returns>
        public Int32 HNC_MacroVarSetValue(Int32 no, SDataUnion var, Int16 clientNo)
        {
            int ret = -1;

            //if (var != null)
            {
                //if (name.Length > 0)
                {
                    //if (SetContentToRemoteRedisDB(database, key, hashField, content))
                    {
                        HNCAPI.Data.NC_SetValueMessage m = new HNCAPI.Data.NC_SetValueMessage();
                        m.Type  = "MacroVariable";
                        m.Index = 0;
                        m.Value = "{\"no\":\"" + no + "\"," + "\"var\":" + Newtonsoft.Json.JsonConvert.SerializeObject(var) + "}";
                        String message = m.ToString();
                        if (RedisConnectLocal != null)
                        {
                            String MachineSN = "";
                            GetKeyValueString(clientNo, "Machine", ref MachineSN);
                            if (MachineSN.Length > 0)
                            {
                                ISubscriber sub = RedisConnectLocal.GetSubscriber();
                                sub.Publish(MachineSN + ":SetValue", message);
                                ret = 0;
                            }
                        }
                    }
                }
            }
            return(ret);
        }
Пример #2
0
        /// <summary>
        /// 按索引号获取宏变量的值
        /// </summary>
        /// <param name="no"></param>
        /// <param name="var"></param>
        /// <param name="clientNo"></param>
        /// <returns></returns>
        public Int32 HNC_MacroVarGetValue(Int32 no, ref SDataUnion var, Int16 clientNo)
        {
            int    ret   = -1;
            String key   = "";
            String value = "";

            if (no >= VariablesDef.CHAN_MACRO_START_INDEX && no <= VariablesDef.CHAN_MACRO_END_INDEX)
            {
                key = "MacroVariables:CHAN";
            }
            else if (no >= VariablesDef.SYS_MACRO_START_INDEX && no <= VariablesDef.SYS_MACRO_END_INDEX)
            {
                key = "MacroVariables:System";
            }
            else if (no >= VariablesDef.AXIS_MACRO_START_INDEX && no <= VariablesDef.AXIS_MACRO_END_INDEX)
            {
                key = "MacroVariables:Axis";
            }
            else if (no >= VariablesDef.TOOL_MACRO_START_INDEX && no <= VariablesDef.TOOL_MACRO_END_INDEX)
            {
                key = "MacroVariables:Tool";
            }
            if (GetHashKeyValueString(clientNo, key, no.ToString(), ref value) == 0)
            {
                Variables <SDataUnion> macroVariables = Newtonsoft.Json.JsonConvert.DeserializeObject <Variables <SDataUnion> >(value);
                var = macroVariables.Value;
            }
            return(ret);
        }
Пример #3
0
        public Int32 HNC_MacroVarSetValue(Int32 no, SDataUnion var)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDataUnion)));

            Marshal.StructureToPtr(var, ptr, true);
            ret = HncApi.HNC_MacroVarSetValue(no, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Пример #4
0
 public Int32 HNC_MacroVarGetValue(Int32 no, ref SDataUnion var)
 {
     return(HncApi.HNC_MacroVarGetValue(no, ref var, _ClientNo));
 }