Question

I used Trx ISO 8583 library. This library sends message length in HEX. But I need to send 4 bytes of Ascii chars as message header. How to do that?

Was it helpful?

Solution

To change message header you should change NboFrameLengthSink class is in Trx=>Communication=>Sinks=>NboFrameLengthSink.cs

Change in public void Send(PipelineContext context) function below code

buffer.Write(true, _bytesInHeader == 2
                ? new[] {(byte) (length >> 8), (byte) length}
                : new[] {(byte) (length >> 24), (byte) (length >> 16), (byte) (length >> 8), (byte) (length)});

to

string ls_length;

ls_length = length.ToString("####").PadLeft(4,'0');

byte[] ascii = System.Text.Encoding.ASCII.GetBytes(ls_length);

buffer.Write(true, _bytesInHeader == 2
 ? new[] { (byte)(length >> 8), (byte)length }
 : ascii);

and

in function public bool Receive(PipelineContext context)

Code

context.ExpectedBytes = ( header[0] << 24 ) | ( header[1] << 16 ) | ( header[2] << 8 ) | header[3];

chage to

context.ExpectedBytes = header[0] | header[1] | header[2] | header[3];

If you need to send message in Ascii but bitmap as HEX do below:

IN Iso8583Ascii1987.xml congif file change

<!-- Add first bitmap -->
<Invoke Name="Add">
  <Parameter Type="BitMapFieldFormatterFactory">
    <Property Name="FieldNumber" Value="0" />
    <Property Name="Description" Value="Primary bitmap" />
    <Property Name="Encoder" Reference="DataEncoderFactory" />
    <Property Name="LowerFieldNumber" Value="1" />
    <Property Name="UpperFieldNumber" Value="64" />
  </Parameter>
</Invoke>

<!-- Add secondary bitmap (field number 1) -->
<Invoke Name="Add">
  <Parameter Type="BitMapFieldFormatterFactory">
    <Property Name="FieldNumber" Value="1" />
    <Property Name="Description" Value="Secondary bitmap" />
    <Property Name="Encoder" Reference="DataEncoderFactory" />
    <Property Name="LowerFieldNumber" Value="65" />
    <Property Name="UpperFieldNumber" Value="128" />
  </Parameter>
</Invoke>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top