2

I am developing an application using LLRP library. After gateway(computer) receive my message from reader(simulated reader using localhost) I would like to convert it to LLRPMessage using

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

However, I check it in the watch(VS2013 Ultimate): msg is null and enumType is 0.

May I have your advice on this?

My code is :

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 is the XML-converted data receive from 127.0.0.1 :5084. I have to check it and it is correct it is what the reader sent out.

On Reader side, I simulate the reader to send a message to the gateway. On reader side, the code is :

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

Print out of data reader send out to gateway :

<?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> 

Print out of data gateway receive from reader:

<?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>

but after process it using Org.LLRP.LTK.LLRPV1.LLRPXmlParser.ParseXMLToLLRPMessage(_xmlReceived, out msg, out enumType); and print out msg and enumType:

Out msg from ParseXMLToLLRPMessage:
Out enumType from ParseXMLToLLRPMessage: 0

Please help me and reply soon. Your effort is very much appreciated.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
newbuntu
  • 57
  • 6

1 Answers1

0

The null obj variable would mean that the Method was unable to extract the message from the xml passed in. I would look more closely at the xml to see if there is something wrong there.

Here is an example of how the code should look for using 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;
Daniel Cohen
  • 538
  • 1
  • 4
  • 6