铁路车号读取

使用IE

2025-01-19

Written by: tdtc

Recommendation: Starting October 14, 2025, do not use ATL or MFC in new projects.

str.replace(/\s/g, "");
string.split(",");

一、js部分

我们把所有的方法放到一个对象(RepoInfo)中。

var RepoInfo = { };

1. 获取对象

RepoInfo.getObj = function(objName) {
		return new ActiveXObject(objName);
	};

2. 获取数组

RepoInfo.getArray = function(str) {
  var ret = new Array(16);

  var string = str.replace(/\s/g, "");

  ret = string.split(",");

  return ret;
};

3. 解码字串

输入字串校验

如果字串空,退出。

输出框清空

每次赋值前,清空。

执行COM中的方法

在获取对象非空的情况下,执行。

RepoInfo.decode = function(string) {
  if (string == null) return;

  var obj = RepoInfo.getObj("repoInfo.LabelInfo");
  var edtView = document.getElementById("edtView");
  edtView.value = " ";

  var str = RepoInfo.getArray(string);
  if (obj != null)
    edtView.value = obj.getInfo(str);
};

二、html部分

按钮事件

从输入框获取字串作为js方法的输入参数,注意:两种引号的配合使用。

<input type="button" id="btnOk" value="执行数据解析" onClick="RepoInfo.decode(document.getElementById('edtData').value)" />

源代码(含js代码)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>报文数据信息 - IE</title>

<script type="text/javascript">
	var RepoInfo = {
		};

	RepoInfo.getObj = function(objName) {
		return new ActiveXObject(objName);
	};

	RepoInfo.getArray = function(str) {
		var ret = new Array(16);

		var string = str.replace(/\s/g, "");
		alert(string);

		ret = string.split(",");

		return ret;
	};

	RepoInfo.decode = function(string) {
		if (string == null) return;

		var obj = RepoInfo.getObj("repoInfo.LabelInfo");
		var edtView = document.getElementById("edtView");
		edtView.value = " ";

		var str = RepoInfo.getArray(string);
		if (obj != null)
			edtView.value = obj.getInfo(str);
	};

</script>
</head>

<body>
                    
	  
	<textarea name="note" cols="98" rows="7" readonly="readonly">
       注意:本测试只能运行在IE浏览器!

  首先,要注册Dll(regsvr32 repoInfo.dll);
  然后,从“BinJiang_2005.rep”(滨江站),复制行数据到“标签数据”框。

  示例(固定格式):
    0xD3, 0x05, 0x94, 0x84, 0x00, 0x13, 0x51, 0x2F, 0x59, 0x34, 0x57, 0x45, 0x58, 0x50, 0x41, 0x98</textarea>
<br>
<br>
标签数据:<input type="text" id="edtData" size="98" />

<br>
<br>
执行结果:<input type="text" id="edtView" size="50" />
<br>
<br>
                  
<input type="button" id="btnOk" value="执行数据解析" onClick="RepoInfo.decode(document.getElementById('edtData').value)" />
</body>
</html>

Test

File Name(.DAT)Car Number
D2011914312490215
D2011926331926515
D2011955342272515
D2012009346553415
D2012035345000715
D2021643350199715
D2021741345008515
D2021743345001615
D2021926332465615
D2021959342312215
D2022011345005915
D2022044342018915
D2031744342637015
D2031752345003215
D2031913340937115
D2031932332869515
D2031958331071015
D2032039340848715
D2032042345008015
D2032339346034315
D2032344312071215
D2041241350324015
D2041738350323015
D2041808345006515
D2042012345002415
D2042017346445515
D2042038340173615
D2042140312747515
D2051607350323415
D2051746345007615
D2051922331183715
D2051934346033215
D2051946312525215
D2052008345200015
D2052022345005215
D2061808345002915
D2061920332753815
D2061945342158015
D2061957340534815
D2062015345002115
D2071750345004115
D2071915342772915
D2071934346033215
D2071949342700815
D2072018345008715
D2072047346288015
D2081108331115215
D2081118331115215
D2081325350338915
D2081757345000715
D2081917342941715

参考文档(W3School):