private void BuildTransport(bool tx, LTKD.Message msg) { if (null != msg) { OnTransport(tx, Encoding.ASCII.GetBytes(msg.ToString()), 1000); } }
private LTKD.Message SendLlrpMessage(LTKD.Message message) { LTKD.Message response = null; PARAM_LLRPStatus llrpStatus = null; object msgType = Enum.Parse(typeof(ENUM_LLRP_MSG_TYPE), message.MSG_TYPE.ToString(), true); int timeout = (int)ParamGet("/reader/commandTimeout") + (int)ParamGet("/reader/transportTimeout"); BuildTransport(true, message); try { switch ((ENUM_LLRP_MSG_TYPE)msgType) { case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC: timeout += STOP_TIMEOUT; response = (MSG_DELETE_ROSPEC_RESPONSE)llrp.DELETE_ROSPEC((MSG_DELETE_ROSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_DELETE_ROSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC: response = (MSG_ADD_ROSPEC_RESPONSE)llrp.ADD_ROSPEC((MSG_ADD_ROSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_ADD_ROSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC: response = (MSG_ENABLE_ROSPEC_RESPONSE)llrp.ENABLE_ROSPEC((MSG_ENABLE_ROSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_ENABLE_ROSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.START_ROSPEC: response = (MSG_START_ROSPEC_RESPONSE)llrp.START_ROSPEC((MSG_START_ROSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_START_ROSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC: timeout += STOP_TIMEOUT; response = (MSG_STOP_ROSPEC_RESPONSE)llrp.STOP_ROSPEC((MSG_STOP_ROSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_STOP_ROSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC: timeout += STOP_TIMEOUT; response = (MSG_DISABLE_ROSPEC_RESPONSE)llrp.DISABLE_ROSPEC((MSG_DISABLE_ROSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_DISABLE_ROSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG: response = (MSG_SET_READER_CONFIG_RESPONSE)llrp.SET_READER_CONFIG((MSG_SET_READER_CONFIG)message, out errorMessage, timeout); llrpStatus = ((MSG_SET_READER_CONFIG_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG: response = (MSG_GET_READER_CONFIG_RESPONSE)llrp.GET_READER_CONFIG((MSG_GET_READER_CONFIG)message, out errorMessage, timeout); llrpStatus = ((MSG_GET_READER_CONFIG_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES: response = (MSG_GET_READER_CAPABILITIES_RESPONSE)llrp.GET_READER_CAPABILITIES((MSG_GET_READER_CAPABILITIES)message, out errorMessage, timeout); llrpStatus = ((MSG_GET_READER_CAPABILITIES_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS: response = (MSG_GET_ACCESSSPECS_RESPONSE)llrp.GET_ACCESSSPECS((MSG_GET_ACCESSSPECS)message, out errorMessage, timeout); llrpStatus = ((MSG_GET_ACCESSSPECS_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.GET_ROSPECS: response = (MSG_GET_ROSPECS_RESPONSE)llrp.GET_ROSPECS((MSG_GET_ROSPECS)message, out errorMessage, timeout); llrpStatus = ((MSG_GET_ROSPECS_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.KEEPALIVE_ACK: llrp.KEEPALIVE_ACK((MSG_KEEPALIVE_ACK)message, out errorMessage, timeout); break; case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC: response = (MSG_ADD_ACCESSSPEC_RESPONSE)llrp.ADD_ACCESSSPEC((MSG_ADD_ACCESSSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_ADD_ACCESSSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC: response = (MSG_ENABLE_ACCESSSPEC_RESPONSE)llrp.ENABLE_ACCESSSPEC((MSG_ENABLE_ACCESSSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_ENABLE_ACCESSSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC: response = (MSG_DELETE_ACCESSSPEC_RESPONSE)llrp.DELETE_ACCESSSPEC((MSG_DELETE_ACCESSSPEC)message, out errorMessage, timeout); llrpStatus = ((MSG_DELETE_ACCESSSPEC_RESPONSE)response).LLRPStatus; break; case ENUM_LLRP_MSG_TYPE.ENABLE_EVENTS_AND_REPORTS: llrp.ENABLE_EVENTS_AND_REPORTS((MSG_ENABLE_EVENTS_AND_REPORTS)message, out errorMessage, timeout); break; case ENUM_LLRP_MSG_TYPE.GET_REPORT: llrp.GET_REPORT((MSG_GET_REPORT)message, out errorMessage, timeout); break; case ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE: response = (MSG_THINGMAGIC_CONTROL_RESPONSE_POWER_CYCLE_READER)llrp.CUSTOM_MESSAGE((MSG_CUSTOM_MESSAGE)message, out errorMessage, timeout); break; default: throw new ReaderException("Not a valid llrp message"); } } catch (Exception ex) { if(ErrCodeNullObjectReference == (uint)System.Runtime.InteropServices.Marshal.GetHRForException(ex)) { if (continuousReading) { ReadExceptionPublisher expub = new ReadExceptionPublisher(this, new ReaderException((((ENUM_LLRP_MSG_TYPE)msgType).ToString() + " failed. Request timed out"))); Thread trd = new Thread(expub.OnReadException); trd.Name = "OnReadException"; trd.Start(); } else { throw new ReaderException(((ENUM_LLRP_MSG_TYPE)msgType).ToString() + " failed. Request timed out"); } } else { throw new Exception(ex.Message); } } BuildTransport(false, response); if (llrpStatus != null) { if (llrpStatus.StatusCode != ENUM_StatusCode.M_Success) { throw new Exception(llrpStatus.ErrorDescription == "" ? (llrpStatus.StatusCode.ToString()) : llrpStatus.ErrorDescription); } } return response; }