/// <summary> /// 从下位机加载G代码程序 /// </summary> /// <param name="ch"></param> /// <param name="name"></param> /// <param name="clientNo"></param> /// <returns></returns> public Int32 HNC_SysCtrlSelectProg(Int32 ch, String name, Int16 clientNo) { int ret = -1; if (name != null) { if (name.Length > 0) { //if (SetContentToRemoteRedisDB(database, key, hashField, content)) { HNCAPI.Data.NC_SetValueMessage m = new HNCAPI.Data.NC_SetValueMessage(); m.Type = "SysCtrlSelectProg"; m.Index = 0; m.Value = "{\"ch\":\"" + ch + "\"," + "\"name\":\"" + name + "\"}"; 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); }
/// <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); }
/// <summary> /// 设置寄存器的值, 返回值 0 :成功 -1 :失败 /// </summary> /// <param name="type"></param> /// <param name="index"></param> /// <param name="bit"></param> /// <param name="clientNo"></param> /// <returns></returns> public Int32 HNC_RegSetValue(Int32 type, Int32 index, Int32 value, Int16 clientNo) { int ret = -1; NCMessage m = new NCMessage(); m.Type = "Register"; m.Index = NCMessageFunction.REG_SET; String regType = ""; switch (type) { case (int)HncRegType.REG_TYPE_X: { regType = "X"; } break; case (int)HncRegType.REG_TYPE_Y: { regType = "Y"; } break; case (int)HncRegType.REG_TYPE_F: { regType = "F"; } break; case (int)HncRegType.REG_TYPE_G: { regType = "G"; } break; case (int)HncRegType.REG_TYPE_R: { regType = "R"; } break; case (int)HncRegType.REG_TYPE_W: { regType = "W"; } break; case (int)HncRegType.REG_TYPE_D: { regType = "D"; } break; case (int)HncRegType.REG_TYPE_B: { regType = "B"; } break; case (int)HncRegType.REG_TYPE_P: { regType = "P"; } break; default: break; } m.Value = "{\"regType\":\"" + regType + "\",\"index\": " + index + ",\"value\": " + value + "}"; String message = m.ToString(); try { if (RedisConnectLocal != null) { String MachineSN = ""; if (GetKeyValueString(clientNo, "Machine", ref MachineSN) == 0) { ISubscriber sub = RedisConnectLocal.GetSubscriber(); sub.Publish(MachineSN + ":SetValue", message); ret = 0; } } } catch (Exception ex) { Console.WriteLine("HNC_RegSetBit" + ":" + ex.Message); } return(ret); }