‎2019 Oct 28 5:45 AM
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
‎2019 Oct 28 6:35 AM
You assume we can understand C#
Maybe if you could read it, explain line by line the objective
‎2019 Oct 28 6:48 AM
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?
‎2019 Oct 28 6:49 AM
‎2019 Oct 28 8:52 AM
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.
‎2019 Oct 28 10:24 AM
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.
‎2019 Oct 28 6:10 PM
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.