Reading data from mscomm in ABAP

时间秒杀一切 提交于 2020-01-05 03:59:05

问题


I'm trying to read data sent from serial port via MSCOMM32 object.

What I got was ##.

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.

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.

I have a legacy software using .NET and it can read the data perfectly, using the same response data.

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>

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.


回答1:


I found the answer.

set the inputlen property to 4. solve the problem.



来源:https://stackoverflow.com/questions/58727401/reading-data-from-mscomm-in-abap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!