/// <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); }