0

I am calling an as400 Rpg program from C#. I pass it 6 parameters with value and a 7th that is null and to be returned from the program. I do receive a value from the program in the form of a byte. The returned value is supposed to be either 1 or 0 depending on the execution of the program. enter image description here

enter image description here

I have tried using this string result = System.Text.Encoding.UTF8.GetString(byteArray);

Which returns this � symbol. I have tried converting to Hex which returns F1. How can i get the value of that byte in C#? Again i know that the only possible values are 1 or 0.

Update if I use stringConverter.FromBytes(parameters["p7"].Value i always receive a 1.

  ProgramParameters parameters = new ProgramParameters();
                parameters.Append("P1", cwbrcParameterTypeEnum.cwbrcInout, 3);
                parameters["P1"].Value = stringConverter.ToBytes(uwDecision.Param1.PadRight(paramLength, ' '));
                parameters.Append("P2", cwbrcParameterTypeEnum.cwbrcInput, 10);
                parameters["P2"].Value = stringConverter.ToBytes(uwDecision.Param2.PadRight(parmlenth2, ' '));
                parameters.Append("P3", cwbrcParameterTypeEnum.cwbrcInput, 10);
                parameters["P3"].Value = stringConverter.ToBytes(uwDecision.Param3.ToUpper().PadRight(parmlenth2, ' '));
                parameters.Append("P4", cwbrcParameterTypeEnum.cwbrcInput, 1);
                parameters["P4"].Value = stringConverter.ToBytes(uwDecision.Param4.PadRight(paramlength3, ' '));
                parameters.Append("P5", cwbrcParameterTypeEnum.cwbrcInput, 3);
                parameters["P5"].Value = stringConverter.ToBytes(uwDecision.Param5.PadRight(paramLength, ' '));
                parameters.Append("P6", cwbrcParameterTypeEnum.cwbrcInput, 3);
                parameters["P6"].Value = stringConverter.ToBytes(uwDecision.Param6.PadRight(paramLength, ' '));
                parameters.Append("P7", cwbrcParameterTypeEnum.cwbrcInout, 1);
                program.Call(parameters);


                var read = stringConverter.FromBytes(parameters["P7"].Value);

                isValid = read == "1";
                system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll);
15
  • 1
    You should read the one byte and then convert it to the required data type, which in this case seems to be a bool. I bet you can use something like BitConverter.ToBoolean(<your byte>). Commented Oct 2, 2017 at 16:37
  • BitConverter.ToString(read) returns F1. It returns F1 every time. Commented Oct 2, 2017 at 16:40
  • How long it read? Commented Oct 2, 2017 at 16:41
  • @RossBush the byte array is always the same size 241 Commented Oct 2, 2017 at 16:42
  • 1
    @LeonardoTrimarchi I suppose it is Consolas then! Commented Dec 7, 2017 at 15:49

1 Answer 1

0

It appears that the message is using a Extended Binary Coded Decimal Interchange Code. You will need to convert or translate, however, it appears the system is attempting to send 0 and 1, just in it's representation.

EBCDIC Hex              EBCDIC Text        ASCII Translation
------------------    --------------     -----------------
       F1                    1                 241 = 0xF1
       F0                    0                 240 = 0xF0  
Sign up to request clarification or add additional context in comments.

2 Comments

How would i do that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.