1
votes

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
Sorry but this is a question no one could understand. Please provide some more details. - Jagger
Does this fix it for you? - Legxis
It is also discussed a little in the topic referenced in the post I linked before, you should read it all and check if you did everything and if there is any port settings that you might have to adjust. - Legxis
If it's not too long, can you post the different parts of the legacy .NET code, and the corresponding ABAP code for each part? - Sandra Rossi
you should add sample of input, then your current output and expected output - Suncatcher

1 Answers

0
votes

I found the answer.

set the inputlen property to 4. solve the problem.