2

我正在使用 LLRP 库开发应用程序。网关(计算机)从阅读器(使用本地主机的模拟阅读器)收到我的消息后,我想将其转换为 LLRPMessage 使用

Org.LLRP.LTK.LLRPV1.LLRPXmlParser.ParseXMLToLLRPMessage(_xmlReceived, out msg, out enumType);

但是,我在手表(VS2013 Ultimate)中检查它:msg 为 null 并且 enumType 为 0。

对此我有什么建议吗?

我的代码是:

public static void ConvertXmlToLLRPMessage()
{
    Org.LLRP.LTK.LLRPV1.DataType.Message msg;  //Only Message type is accepted.
    Org.LLRP.LTK.LLRPV1.ENUM_LLRP_MSG_TYPE enumType; //Only ENUM_LLRP_MSG_TYPE type is accepted.

    Org.LLRP.LTK.LLRPV1.LLRPXmlParser.ParseXMLToLLRPMessage(_xmlReceived, out msg, out enumType);

    Console.WriteLine();
    Console.WriteLine("Print out _xmlReceived, inside ConvertXmlToLLRPMessage.");
    Console.WriteLine(_xmlReceived);
    Console.WriteLine();
    Console.WriteLine("Out msg from ParseXMLToLLRPMessage:\n"); Console.WriteLine(msg); Console.WriteLine();
    Console.WriteLine("Out enumType from ParseXMLToLLRPMessage:\n"); Console.WriteLine(enumType); Console.WriteLine();
}

_xmlReceived是从 127.0.0.1 :5084 接收的 XML 转换数据。我必须检查它,它是正确的,这是读者发出的。

在阅读器方面,我模拟阅读器向网关发送消息。在读者方面,代码是:

public static void testData_PARAM_ROSpecID()
{
    //create and object
    PARAM_ROSpecID _rec_PARAM_ROSpecID = new PARAM_ROSpecID();

    //assign value to an object
    _rec_PARAM_ROSpecID.ROSpecID = 789;

    //Convert obj to xml
    string _xmlData = ConvertObjectToXml(_rec_PARAM_ROSpecID);

    //Convert xml to byte array
    byte [] _byteArray = CommServerSend.getSendBuffInByteAry(_xmlData);

    //Send out.
    CommServerReceive._incomingDataObj.Send(_byteArray);

    return;
}

打印数据阅读器发送到网关:

<?xml version="1.0" encoding="utf-16"?>
<PARAM_ROSpecID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ROSpecID>789</ROSpecID>
</PARAM_ROSpecID> 

打印出从阅读器接收的数据网关:

<?xml version="1.0" encoding="utf-16"?>
<PARAM_ROSpecID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ROSpecID>789</ROSpecID>
</PARAM_ROSpecID>

但在使用Org.LLRP.LTK.LLRPV1.LLRPXmlParser.ParseXMLToLLRPMessage(_xmlReceived, out msg, out enumType);并打印出 msg 和 enumType 后处理它:

Out msg from ParseXMLToLLRPMessage:
Out enumType from ParseXMLToLLRPMessage: 0

请帮助我并尽快回复。非常感谢您的努力。

4

1 回答 1

0

null obj 变量意味着方法无法从传入的 xml 中提取消息。我会更仔细地查看 xml,看看那里是否有问题。

下面是如何使用 ParseXMLToLLRPMessage() 查找代码的示例:

            Org.LLRP.LTK.LLRPV1.DataType.Message obj;
            ENUM_LLRP_MSG_TYPE msg_type;

            // read the XML from a file and validate its an SET_READER_CONFIG
            try
            {
                FileStream fs = new FileStream(@"setReaderConfig.xml", FileMode.Open);
                StreamReader sr = new StreamReader(fs);
                string s = sr.ReadToEnd();
                fs.Close();

                LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG)
                {
                    Console.WriteLine("Could not extract message from XML");
                    return;
                }
            }
            catch
            {
                Console.WriteLine("Unable to convert to valid XML");
                return;
            }

            // Communicate that message to the reader
            MSG_SET_READER_CONFIG msg = (MSG_SET_READER_CONFIG)obj;
于 2017-09-18T15:52:03.517 回答