Skip to content

TN5250

The tn5250 package is the IBM 5250 data stream for the library. With it, a program shows the same ibmterm screens on a 5250 (an IBM i or AS/400 terminal) as on a 3270. Clients are 5250 emulators, for example tn5250, tn5250j and IBM i Access Client Solutions.

Connect a client

Use tn5250.NegotiateTelnet() on a new connection. It returns a tn5250.DevInfo, which is an ibmterm.Terminal:

dev, err := tn5250.NegotiateTelnet(conn)
if err != nil {
    return err
}
resp, err := ibmterm.ShowScreenOpts(screen, nil, conn,
    ibmterm.ScreenOpts{Terminal: dev})

The negotiation (RFC 1205, RFC 2877) does these steps:

  1. The server asks for TERMINAL-TYPE and NEW-ENVIRON.
  2. If the client agrees to NEW-ENVIRON, the server asks for all the variables. The client can send DEVNAME, KBDTYPE, CODEPAGE, CHARSET, USER and other variables. DevInfo.Environ() returns them.
  3. The server asks for the terminal type. If the type is not a 5250 type, NegotiateTelnet() returns ErrUnknownTerminal.
  4. The server asks for END-OF-RECORD and BINARY in the two directions. If the client refuses one of them, NegotiateTelnet() returns ErrNo5250.

A server that serves 3270 and 5250 clients on one port must read the terminal type first. Then it sends DONT TERMINAL-TYPE, and gives the connection to tn3270.NegotiateTelnet() or to tn5250.NegotiateTelnet(). tn5250.Is5250() tells if a terminal type is a 5250 type.

Terminal types and screen sizes

The terminal type sets the screen size and the colors.

Terminal type Size (rows x columns) Colors
IBM-5251-11, IBM-5291-1, IBM-3196-A1, IBM-5555-B01, IBM-3486-BA, IBM-3487-HA 24 x 80 No
IBM-5292-2, IBM-3179-2, IBM-5555-C01, IBM-3487-HC 24 x 80 Yes
IBM-3180-2, IBM-3477-FG 27 x 132 No
IBM-3477-FC 27 x 132 Yes

Terminal.Size() returns the size. A screen on a 24x80 terminal starts with Clear Unit. A screen on a 27x132 terminal starts with Clear Unit Alternate.

How a screen becomes a 5250 data stream

WriteScreen sends one record for each screen. The record has a GDS header (record type 0x12A0) and these commands:

  1. Clear Unit or Clear Unit Alternate, unless ScreenOpts.NoClear is true.
  2. Write To Display. Each field has a Set Buffer Address (SBA) order. Then:
    • A field that the user cannot change has an attribute and its text.
    • An input field (Write) has a Start of Field (SF) order with a field format word, the attribute and the length. The field ends at the next attribute on the screen, or at the end of the row. The modified data tag is set, so the client always sends the value back.
    • A PositionOnly or AttributeOnly field has only its text.
    • An Insert Cursor (IC) order puts the cursor at CursorRow and CursorCol.
  3. Read MDT Fields, unless ScreenOpts.NoResponse is true. The record then has the Put/Get operation code. With NoResponse, it has the Output Only operation code.

The attribute takes one position on the screen, as on a 3270. Thus a screen has the same layout on the two terminal types.

Colors and highlights

The package changes the colors of ibmterm to 5250 attributes:

ibmterm 5250 attribute on a color terminal
DefaultColor, Green 0x20 green
White, or Intense with no color 0x22 white
Red 0x28 red
Turquoise 0x30 turquoise, with column separators
Yellow 0x32 yellow, with column separators
Pink 0x38 pink
Blue 0x3A blue

ReverseVideo adds 0x01 and Underscore adds 0x04. Blink operates on red fields only. Hidden is the non-display attribute 0x27. On a terminal with no colors, a color other than green, or Intense, gives high intensity.

The 5250 has no programmed symbols, no graphic escape and no Set Attribute order. The package does not write Raw content, and it ignores CharSet.

Keys

The package changes the 5250 AID bytes to ibmterm.Key values:

5250 key AID ibmterm
Enter, Field Exit at the end of an Auto Enter field 0xF1, 0x3F KeyEnter
F1 to F12 0x31 to 0x3C KeyF1 to KeyF12
F13 to F24 0xB1 to 0xBC KeyF13 to KeyF24
Roll Down (Page Up) 0xF4 KeyPageUp
Roll Up (Page Down) 0xF5 KeyPageDown
Clear 0xBD KeyClear
Help 0xF3 KeyHelp
Print 0xF6 KeyPrint
Record Backspace 0xF8 KeyRecordBackspace
Attention (header flag) KeyAttn
System Request (header flag) KeySysReq

On IBM i, F3 is Exit, F5 is Refresh and F12 is Cancel. Use these keys on a 5250 if you can.

Try it

cmd/tn5250test is a small server with a test form. It shows the terminal type, the size, the colors and the code page:

go run ./cmd/tn5250test -listen :2323 -debug
tn5250 env.TERM=IBM-3477-FC localhost:2323

Limits

  • The package does not do 5250 printer sessions, the Write Error Code command (the message line), Save Screen, Restore Screen or DBCS fields.
  • The package does not do the auto sign-on of RFC 4777 (the USER and IBMRSEED variables). It gives the variables to the program in DevInfo.Environ().