专家,
有没有人成功建立了Allen Bradley的1768-EWEB模块?我的问题的范围是网页之间的通信,它将更新保存在EWEB模块内的目录下的xml文件;然后由模块读取并传送回PLC。
手册非常具体,唯一的方法是使用"网页表单和POST处理程序"。
手册中提供的代码示例如下:
<html>
<head>
<title>
Data View Javascript Demo Page
</title>
<script type="text/javascript">
var xmlDoc;
var xmlhttp;
var DATAVIEW_URI = "/user/system/dataviews/Sample.xml";
var DATAVIEW_NAMESPACE = "http://www.rockwellautomation.com/technologies/data_access/data_views/1.0/";
var DATATYPES_NAMESPACE = "http://www.rockwellautomation.com/technologies/data_access/data_types/1.0/";
var ARR_ACTIVEX = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument",
"Microsoft.XmlDom"];
var STR_ACTIVEX = "";
var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
if (isIE) {
var bFound = false;
for (var i=0; i < ARR_ACTIVEX.length && !bFound; i++) {
try {
var objXML = new ActiveXObject(ARR_ACTIVEX[i]);
STR_ACTIVEX = ARR_ACTIVEX[i];
bFound = true
} catch (objException) {}
}
if (!bFound) {
/* No DOM found, so throw a message and go back */
alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please
upgrade your browser or load the appropriate patches to support XML.");
history.go(-1);
}
} else {
/* Not IE, so throw a message and go back */
alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please
upgrade your browser or load the appropriate patches to support XML.");
history.go(-1);
}
xmlDoc = new ActiveXObject(STR_ACTIVEX)
xmlDoc.async = false;
xmlDoc.setProperty("SelectionLanguage", "XPath");
if (STR_ACTIVEX.indexOf(".DOMDocument") != -1) {
xmlhttp = new ActiveXObject(STR_ACTIVEX.substring(0, STR_ACTIVEX.indexOf(".DOMDocument")) +
".XMLHTTP");
} else {
alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please
upgrade your browser or load the appropriate patches to support XML.");
history.go(-1);
}
function refresh_value() {
xmlDoc.load(DATAVIEW_URI);
xmlDoc.setProperty("SelectionNamespaces", "xmlns:dv='" + DATAVIEW_NAMESPACE + "'");
document.getElementById("tagvalue").value =
xmlDoc.selectSingleNode("/dv:view/dv:tag[@name='TEST']/dv:value").childNodes[0].nodeValue;
}
function update_value() {
xmlDoc.selectSingleNode("/dv:view/dv:tag[@name='TEST']/dv:value").childNodes[0].nodeValue =
document.getElementById("tagvalue").value;
xmlhttp.Open("POST", DATAVIEW_URI, false);
xmlhttp.Send(xmlDoc);
refresh_value();
}
</script>
</head>
<body onLoad="refresh_value();">
TEST value is <input type="text" name="tagvalue" id="tagvalue" /><br/>
<input type="button" onClick="refresh_value();" value="Refresh"/><input type="button"
onClick="update_value();" value="Update"/>
</body>
</html>
当我测试上面的代码时(在IE 10上),它不起作用。字段表单为空白。根据手册,它应该显示125.(在向导中创建xml的步骤已经完成)。
有没有人有机会使用此网络模块?该设备来自2004-2006,它只处理.asp作为服务器端语言。
提前谢谢。
答案 0 :(得分:1)
将原始代码复制到test.html文件中并在IE10中打开后,如你所说它不起作用。我发现脚本中有换行符会导致它变得无效 - 尤其是alert(" ")
中的字符串文字。我在过去发现,从手册,pdf和帮助文件中复制可能包含不需要的字符,因此请使用优秀的代码编辑器仔细检查。它还有助于设置缩进,以便您可以轻松查看代码中发生的情况。
<html>
<head>
<title>
Data View Javascript Demo Page
</title>
<script type="text/javascript">
var xmlDoc;
var xmlhttp;
var DATAVIEW_URI = "/user/system/dataviews/Sample.xml";
var DATAVIEW_NAMESPACE = "http://www.rockwellautomation.com/technologies/data_access/data_views/1.0/";
var DATATYPES_NAMESPACE = "http://www.rockwellautomation.com/technologies/data_access/data_types/1.0/";
var ARR_ACTIVEX = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
var STR_ACTIVEX = "";
var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
if (isIE) {
var bFound = false;
for (var i=0; i < ARR_ACTIVEX.length && !bFound; i++) {
try {
var objXML = new ActiveXObject(ARR_ACTIVEX[i]);
STR_ACTIVEX = ARR_ACTIVEX[i];
bFound = true
} catch (objException) {}
}
if (!bFound) {
/* No DOM found, so throw a message and go back */
alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please upgrade your browser or load the appropriate patches to support XML.");
history.go(-1);
}
} else {
/* Not IE, so throw a message and go back */
alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please upgrade your browser or load the appropriate patches to support XML.");
history.go(-1);
}
xmlDoc = new ActiveXObject(STR_ACTIVEX)
xmlDoc.async = false;
xmlDoc.setProperty("SelectionLanguage", "XPath");
if (STR_ACTIVEX.indexOf(".DOMDocument") != -1) {
xmlhttp = new ActiveXObject(STR_ACTIVEX.substring(0, STR_ACTIVEX.indexOf(".DOMDocument")) + ".XMLHTTP");
} else {
alert("Creating/editing a data view requires Internet Explorer 5.5 or greater with XML support. Please upgrade your browser or load the appropriate patches to support XML.");
history.go(-1);
}
function refresh_value() {
xmlDoc.load(DATAVIEW_URI);
xmlDoc.setProperty("SelectionNamespaces", "xmlns:dv='" + DATAVIEW_NAMESPACE + "'");
document.getElementById("tagvalue").value =
xmlDoc.selectSingleNode("/dv:view/dv:tag[@name='TEST']/dv:value").childNodes[0].nodeValue;
}
function update_value() {
xmlDoc.selectSingleNode("/dv:view/dv:tag[@name='TEST']/dv:value").childNodes[0].nodeValue =
document.getElementById("tagvalue").value;
xmlhttp.Open("POST", DATAVIEW_URI, false);
xmlhttp.Send(xmlDoc);
refresh_value();
}
</script>
</head>
<body onLoad="refresh_value();">
TEST value is <input type="text" name="tagvalue" id="tagvalue" /><br/>
<input type="button" onClick="refresh_value();" value="Refresh"/>
<input type="button" onClick="update_value();" value="Update"/>
</body>
</html>
现在您的下一个障碍是获取浏览器来运行该代码,因为IE10可能不支持ActiveX。这是一个不同的问题,但是......