Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Bit Array ABAP

Former Member
0 Likes
1,688

Dear Experts,

I have a requirement to send bytes array to serial port, but the legacy source code is using c# like this.

static byte[] SOH = new byte[] { 0x01 }; 
static byte[] STX = new byte[] { 0x02 }; 
static byte[] ETX = new byte[] { 0x03 }; 
static byte[] FS = new byte[] { 0x1C }; 
static byte[] US = new byte[] { 0x1F }; 
static byte[] ESC = new byte[] { 0x1B }; 
static byte[] P = new byte[] { 0x50 };

        byte[] bytes = System.Text.Encoding.ASCII.GetBytes(msgtxt);
        _serialPort.Write(STX, 0, 1);
        _serialPort.Write(SOH, 0, 1);
        _serialPort.Write(P, 0, 1);
        _serialPort.Write(SOH, 0, 1);
        _serialPort.Write(bytes, 0, bytes.Length);
        _serialPort.Write(ETX, 0, 1);

        intValue = Int32.Parse(fourthargument);
        byte[] intBytes = BitConverter.GetBytes(intValue);
        _serialPort.Write(intBytes, 0, 1);

How do you translate this code into abap?
Thanks

6 REPLIES 6
Read only

FredericGirod
Active Contributor
1,424

You assume we can understand C#

Maybe if you could read it, explain line by line the objective

Read only

Sandra_Rossi
Active Contributor
1,424

Read the ABAP documentation, data types are explained.

Byte = type X of length 1

Bytes = type X of any fixed length or type XSTRING

Table of bytes = TABLE OF "type X of length 1"

What is your problem with that?

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,424

Why don't you call the C# program from ABAP?

Read only

Former Member
0 Likes
1,424

the reason the data is not sent to serialport is because it's failed when trying to open the serial port

where I get sy-subrc = 3.

but when using dot net I can send the data with no problem.

what seems to be the problem, did you ever succussfuly open a commport using abap?


 
SET PROPERTY OF O_OBJ 'commport' =  COMMPORT.

SET PROPERTY OF O_OBJ 'settings' =  SETTINGS.

SET PROPERTY OF O_OBJ 'inputlen' = 0.

SET PROPERTY OF O_OBJ 'portopen' = 1.
Read only

1,424

Please use the COMMENT button for comments, questions, adding details, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

Read only

1,424

I'd say that sending bits/bytes to a serial port is not a common task performed in ABAP, which is a business application language. It'd be beneficial if you've explained what exactly are you trying to achieve with this. Why is this needed in SAP?

As Sandra noted, please use Comments instead of Answer, just like on StackOverflow.