public new static MSG_GET_READER_CONFIG FromString(string str) { string val; XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(str); XmlNode node = (XmlNode)xdoc.DocumentElement; MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); try { msg.MSG_ID = Convert.ToUInt32(XmlUtil.GetNodeAttrValue(node, "MessageID")); } catch { } val = XmlUtil.GetNodeValue(node, "AntennaID"); msg.AntennaID = Convert.ToUInt16(val); val = XmlUtil.GetNodeValue(node, "RequestedData"); msg.RequestedData = ( ENUM_GetReaderConfigRequestedData)Enum.Parse(typeof( ENUM_GetReaderConfigRequestedData), val); val = XmlUtil.GetNodeValue(node, "GPIPortNum"); msg.GPIPortNum = Convert.ToUInt16(val); val = XmlUtil.GetNodeValue(node, "GPOPortNum"); msg.GPOPortNum = Convert.ToUInt16(val); try { ArrayList xnl = XmlUtil.GetXmlNodeCustomChildren(node); if (null != xnl) { if (xnl.Count != 0) { for (int i = 0; i < xnl.Count; i++) { ICustom_Parameter custom = CustomParamDecodeFactory.DecodeXmlNodeToCustomParameter((XmlNode)xnl[i]); if (custom != null) msg.AddCustomParameter(custom); } } } } catch { } return msg; }
public MSG_GET_READER_CONFIG_RESPONSE GET_READER_CONFIG(MSG_GET_READER_CONFIG msg, out MSG_ERROR_MESSAGE msg_err, int time_out) { msg_err = null; //Add your code here _event_GET_READER_CONFIG_RESPONSE = new ClientManualResetEvent(false); _event_GET_READER_CONFIG_RESPONSE.msg_id = msg.MSG_ID; _event_ERROR_MESSAGE = new ClientManualResetEvent(false); WaitHandle[] waitHandles = new WaitHandle[] { _event_GET_READER_CONFIG_RESPONSE.evt, _event_ERROR_MESSAGE.evt }; bool[] bit_array = msg.ToBitArray(); byte[] data = Util.ConvertBitArrayToByteArray(bit_array); cI.Send(data); int wait_result = WaitHandle.WaitAny(waitHandles, time_out, false); int cursor = 0; int length; BitArray bArr; try { switch (wait_result) { case 0: bArr = Util.ConvertByteArrayToBitArray(_event_GET_READER_CONFIG_RESPONSE.data); length = bArr.Count; MSG_GET_READER_CONFIG_RESPONSE msg_rsp = MSG_GET_READER_CONFIG_RESPONSE.FromBitArray(ref bArr, ref cursor, length); if (msg_rsp.MSG_ID != msg.MSG_ID) return null; else return msg_rsp; case 1: bArr = Util.ConvertByteArrayToBitArray(_event_ERROR_MESSAGE.data); length = bArr.Count; msg_err = MSG_ERROR_MESSAGE.FromBitArray(ref bArr, ref cursor, length); return null; default: return null; } } catch { return null; } }
public new static MSG_GET_READER_CONFIG FromBitArray(ref BitArray bit_array, ref int cursor, int length) { if (cursor > length) return null; int field_len = 0; object obj_val; ArrayList param_list = new ArrayList(); MSG_GET_READER_CONFIG obj = new MSG_GET_READER_CONFIG(); int msg_type = 0; cursor += 6; msg_type = (int)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 10); if (msg_type != obj.msgType) { cursor -= 16; return null; } obj.msgLen = (UInt32)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 32); obj.msgID = (UInt32)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 32); if (cursor > length) throw new Exception("Input data is not complete message"); field_len = 16; Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt16), field_len); obj.AntennaID = (UInt16)obj_val; if (cursor > length) throw new Exception("Input data is not complete message"); field_len = 8; Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof( ENUM_GetReaderConfigRequestedData), field_len); obj.RequestedData = ( ENUM_GetReaderConfigRequestedData)obj_val; if (cursor > length) throw new Exception("Input data is not complete message"); field_len = 16; Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt16), field_len); obj.GPIPortNum = (UInt16)obj_val; if (cursor > length) throw new Exception("Input data is not complete message"); field_len = 16; Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt16), field_len); obj.GPOPortNum = (UInt16)obj_val; ICustom_Parameter custom = CustomParamDecodeFactory.DecodeCustomParameter(ref bit_array, ref cursor, length); if (custom != null) { obj.Custom.Add(custom); while ((custom = CustomParamDecodeFactory.DecodeCustomParameter(ref bit_array, ref cursor, length)) != null) obj.Custom.Add(custom); } return obj; }
////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// #region Reader Config public void Get_Reader_Config() { MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); msg.AntennaID = 1; msg.GPIPortNum = 0; MSG_GET_READER_CONFIG_RESPONSE rsp = client.GET_READER_CONFIG(msg, out msg_err, 3000); if (rsp != null) { //textBox2.Text = rsp.ToString() + "\n"; WriteMessage(rsp.ToString(), "Get_Reader_Config"); } else if (msg_err != null) { WriteMessage("Get_Reader_Config " + msg_err.ToString() + "\n"); } else WriteMessage("Get_Reader_Config Command time out!" + "\n"); }