PHP 中的非 ASCII 字符?
我正在尝试使用 PHP 向串行端口(r232)发送一些内容。 我正在使用这个类: http://www.phpclasses.org/browse/package/ 3679.html
问题是我只允许发送 1 个字节。 但如果我发送类似“1”的内容,我实际上发送的是 49(ASCII 为 1)。 我尝试使用 send(1) 而不是 send("1"),但效果不好,因为这是有 2 个字节的整数。 那么有没有办法发送“真正的”字符,而不是 ASCII 等价的字符?
I am trying to send something to serial port (r232) with PHP.
I am using this class: http://www.phpclasses.org/browse/package/3679.html
The problem is that I am allowed to send only 1 byte.
But if I send something like "1", I am actually sending 49 (ASCII for 1).
Instead of send("1"), I tried with send(1) but it is no good, because this is integer which has 2 bytes.
So is there a way to send a "real" char, not ASCII equivalent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
chr() 函数返回由相应 ascii 字符的整数给出的字符。
The chr() function returns a character given by the integer for the corresponding ascii character.
看起来图书馆正在等待字符作为输入。 如果您需要发送编码为
0x01
的字符,只需发送“\001”即可。 函数 chr() 会将字符转换为整数值,在这里没有用处。还有一件事:整数的字节大小取决于底层系统,大部分是 4 个字节。
It looks like the library is expecting characters as input. If you need to send the character which would encode to
0x01
, you just send "\001". The function chr() would convert characters to integer values and would be no use here.One more thing: The byte size of integers depends on the underlying system and is mostly 4 bytes.
我不确定你想实现什么目标。 您是否想发送整数 1? 由于不熟悉该类,您是否尝试过仅给出值 1 作为参数? 如果这不起作用,请尝试使用
chr()
函数包装它。I'm not sure what you are trying to accomplish. Are you trying to to send the integer 1? Not being familiar with the class, have you tried to give just the value 1 as an argument? If that doesn't work, try to wrap it with the
chr()
function.