回复:【程序】基于Control脚本和TCP的天气预报系统

lizhigang

  • 帖子

    8
  • 精华

    1
  • 被关注

    3

论坛等级:游民

注册时间:2004-02-28

普通 普通 如何晋级?

发布于 2014-03-12 15:14:15

1楼

写的非常好,一个很创新的应用实例。
有些问题可以交流:
1. http://m.weather.com.cn/data/101010100.html该地址的数据不更新
2. 对于转码,UTF82Unicode函数似乎并不可行。

原因如下:

在PVSS的内核中,采用ANSI标准的string变量。ANSI标准的字符串是变长字符串,当我们用config文件的
langs = "zh_CN.gb2312-1"
定义运行的语言环境的时候,string变量将于操作系统的能够支持变长字节的中文字库ANSI字符串定义字库关联在一起。同样,用langs = "en_US.iso88591"
英文环境定义运行系统,则PVSS运行在纯英文环境,不支持中文的显示。

网页的文本一般为UTF-8编码,最终需要读到PVSS里并能够显示的是ANSI编码,并不是UNICODE。所以用你文中提到的函数并不能够支持中文的完整的显示。对于ANSI,UTF-8,UNICODE这三种编码中的英文字母和数字,编码的低位字节都是一样的,因此,若纯粹读数据的话,看起来是没问题的。这恐怕也就掩盖了问题的实质。

在PVSS里面,是不能够用string,dyn_string,等来表示UNICODE的字串的,必须要用blob或者dyn_blob来表示,即,用一个二进制的数据块,来存储一个UNICODE的字串。 因为UNICODE字串以'\0x00’ ‘\0x00‘连续的两个字节的0来表示结束,如果用string来存储,系统会默认读到第一个0字节就立刻终止,字串的长度、数据等就会丢失。因此,只能用blob来表示。

若要完美的实现该转码的功能,需要借助Visual C++ 2012 ,用系统的API函数编写动态链接库dll函数程序,再在系统中调用dll,当然,要注意,在c++里用blob格式的变量传递UNICODE格式的数据。

下面的说明文件是一个类似的例子,是我自己编写的从ANSI转码到UNICODE的dll函数说明:


ANSI_Unicode( )

Convert multibyte string to wide-character blob.

Synopsis

int ANSI_Unicode(string src, blob &des);

Parameters

Parameter Meaning
src ANSI string to be converted.
&des Unicode data blob .

Return value

0, when the unicode string data blob has been returned.
If an error occurs, -1 will be returned.

Errors
no/incorrect arguments.
no "chinese-simplified" language codepage.

Des cription

Translates the multibyte sequence string src to the equivalent sequence of wide-characters (which is stored in the data blob dest).

Note
The behavior of this function will use chinese language category local setting of your computer, which ensure the convertion from ANSI codepage to Unicode codepage successful.
The total length of src string characters should be less than 256.
You can not set blob data type to a string data type, Because Unicode is end with "\0\0" but not with "\0", which will cause a ANSI string error.

Example

In the following example, a multilanguage catalog string "Hi,我成功了" with the default ANSI encoding will be translated as Unicode data blob.

ANSI encoding UNICODE encoding
Hi,我成功了 48 69 2C CE D2 B3 C9 B9 A6 C1 CB 48 00 69 00 2C 00 11 62 10 62 9F 52 86 4E

///////////////////////////////
main()
{
string src,des;
blob blobDes;
src = getCatStr("sms","Hello");
if(!ANSI_Unicode(src,blobDes))
{
DebugN(src, blobDes);
}
else
{
DebugN("Converting error!");
}
}
///////////////////////////////

Availability

UI,CTRL

只不过,在你的例子中,应当正好把函数反过来重新编写一下才算是圆满了。
喵了个咪的再汪打你
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC OA (原PVSS)

共有386条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。