在ABAP中从mscomm读取数据 [英] Reading data from mscomm in ABAP
问题描述
I'm trying to read data sent from serial port via MSCOMM32 object.
我得到的是##
.
首先我将十六进制转换为字符串并发送到 COMM 端口:
First I convert hex into string and send to COMM port:
DATA : xSTX TYPE xstring VALUE '02'.
DATA : sSTX TYPE string.
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = xSTX
IMPORTING
out_string = sSTX. "this value is now # but still understood by the device
SET PROPERTY OF O_OBJ 'Output' = sSTX .
然后连接到串口的机器会给出响应.我使用以下代码读取数据:
And then the machine attached to serial port will give a response. I read the data using this code below:
Data strmsg Type string.
DO 10 TIMES.
GET PROPERTY OF o_obj 'InBufferCount' = wa_buffer.
If wa_buffer > 0.
GET PROPERTY OF o_obj 'Input' = strmsg.
Endif.
ENDDO.
我可以使用监控设备看到响应,但我得到的输入只有 ##
,当我将此 ##
转换为十六进制时,我会得到 0202
.
I can see the response using monitoring device but the input that I get was only ##
, when I convert this ##
into hex then I would get 0202
.
我已经正确地进行了所有设置,因为我能够发送数据并激活机器,但我仍然无法翻译响应.
I already did all the settings correctly because I'm able to send the data and activate the machine, but I'm still not able to translate the response.
我有一个使用 .NET 的旧软件,它可以使用相同的响应数据完美读取数据.
I have a legacy software using .NET and it can read the data perfectly, using the same response data.
另一个奇怪的事情是 sSTX
的值是 #
但我并没有太在意它,因为它被设备理解了.
Another strange thing was the value of sSTX
is #
but I don't bother it too much because it's understood by the device.
预期输出是(取自监视器)
The expected output is (taken from monitor)
<ACK><STX><STX><NUL><SOH>01000000000000000000000000 P3 <ETX>
但我得到的只是 060202
But all I get was 060202 which is
<ACK><STX><STX>
不知何故文本正文不在同一个空间中.
somehow the text body is not in the same space.
我知道答案就在那里,但我好几个星期都想不通.很奇怪.
I know the answer is there but I just can't figure it out for weeks. very weird.
推荐答案
我找到了答案.
将 inputlen 属性设置为 4.解决问题.
set the inputlen property to 4. solve the problem.
这篇关于在ABAP中从mscomm读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!