Parsing Xml Return From Http.get Call


Recommended Posts

The HTTP.Get() example in the manual shows to put the return in a string, specifically:

global string datain
datain = HTTP.Get("www.weather.gov", "/xml/current_obs/KWMC.xml")[/CODE]

I make an HTTP.Get call to a web service that returns the following:

<boolean xmlns="http://schemas.microsoft.com/2003/10/Serialization/">true</boolean>

and assigns it to the variable. You can echo the variable to the command line with ?datain, but string functions such as find() fail. What are the proper steps to parse this type of return?

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

This HTTP.Get() call takes like 6-8 seconds to return, and in the meantime my Modbus comms (on the same ethernet port) report "Illegal data address" which I suspect may be the error shown for no response because the port is tied up. Is there a way to be able to use the port for both things simultaneously? Is a port thing or is it the sequence in which the Get() is called that's tying everything up?

Link to comment
Share on other sites

More often than not. Here's the sequence:

global string FileSelected = Registry.strFileSelected
private idx

while(1)
try()
if((MarkFileSelected > -1) & (MarkFileList[MarkFileSelected] != FileSelected) & !SysBits[0][0] & (N7024[0] < 5))
FileSelected = MarkFileList[MarkFileSelected]
switch
case (FileSelected == "xPOINT05MG")
idx = 1
case (FileSelected == "xPOINT1MGx")
idx = 2
case (FileSelected == "xPOINT2MGx")
idx = 3
endcase
?"Idx: " + idx
Device.PLC.SetRegisterS16(PLC_Stn, 112, idx)
private string ParseRet = MakeUpper(ParseXML(HTTP.Get("localhost", "/LoadFile/" + FileSelected + ".dat")))
if(ParseRet == "TRUE")
?"File Accepted"
Registry.strFileSelected = FileSelected
else
?"File Not Accepted"
endif
endif
catch()
?"Error"
endcatch
delay(0.2)
endwhile[/CODE]

And from the Command/Alert Window:

Idx: 3

File Accepted

11/05/12 12:46:32.706

P-ModbusTCP 0003: Illegal Data Value

markfileselected = 1

Idx: 1

File Accepted

11/05/12 12:46:58.619

P-ModbusTCP 0003: Illegal Data Value

Or do you think the 0003 error is coming from the Device call in the sequence?

Link to comment
Share on other sites

Illegal data value is an error generated by the device. It isn't a communications issue, its simply that you are asking it to set a value that isn't correct. Are you sure that your setRegisterS16() parameters are correct? I'll bet if you look at the comm monitor for when it does that command, that DAQFactory is successfully outputting the correct Modbus command and you are getting a valid (albeit error) response from the device.

Link to comment
Share on other sites

Can't imagine why it would be a problem. It's just the 113th integer register in a block of a couple hundred. No particular limits on what can be written there. Any 16 bits should work, and certainly integer values of 1-3. It's the same call as numerous other places. Even so, I'll experiment and see if I can figure out what it doesn't like.

Link to comment
Share on other sites

From the Command/Alert window:

?device.plc.SetRegisterS16(PLC_Stn, 112, 1)

?device.plc.ReadHoldingS16(PLC_Stn, 112, 1)

1

?device.plc.SetRegisterS16(PLC_Stn, 112, 2)

?device.plc.ReadHoldingS16(PLC_Stn, 112, 1)

2

?device.plc.SetRegisterS16(PLC_Stn, 112, 3)

?device.plc.ReadHoldingS16(PLC_Stn, 112, 1)

3

So the slave doesn't seem to object to any of the relevant values being written to that address if it's done manually from the prompt. What would be the difference?

Link to comment
Share on other sites

Oh, and please don't laugh about the filenames hardcoded into the sequence. It's just a quick band-aid to temporarily restore compatibility with something that was inflicted on me in another part of the system. As soon as I get five minutes I'll do a GUI for mapping the filenames to the ordinals.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.