IMDTouchKnowledge BaseShop main store

Troubleshooting

Why an HMI cannot initialize an RS232 SMS modem

Industrial networks Published 8 min read By IMDTouch engineering team

Short answer

An HMI cannot initialize an RS232 SMS modem when its AT commands never come back with OK, and two causes cover nearly every case: the cable does not carry each transmitter to the other end's receiver, or the serial settings and initialization string never put the modem into text mode. Ring out the cable, set 9600 baud 8 data bits no parity 1 stop bit with flow control off at both ends, and send ATZ, ATE0, AT+CMGF=1 and the service-center command.

On this page
  1. What initialization failure actually means
  2. Read the modem's counters before touching software
  3. Fix the cable with a meter, not a label
  4. Set the serial parameters once, at both ends
  5. The initialization string that selects text mode
  6. Wire time is never the bottleneck
  7. The fix order
  8. When to skip the serial path
  9. Questions asked

An HMI reports that it cannot initialize an RS232 SMS modem when the modem never returns OK to the HMI's AT commands, and two faults produce almost every field case. First, the cable does not put each transmitter on the other end's receiver, so traffic moves one way and the handshake dies. Second, the serial parameters or the initialization string never put the modem into SMS text mode, so the modem answers with ERROR or with nothing the driver can parse.

The fix runs in three layers: ring the cable out against the two pin tables, apply one matched parameter set — 9600 baud, 8 data bits, no parity, 1 stop bit, flow control off at both ends — and enter a four-command string that resets the modem, silences echo, selects text mode and loads the service-center address. Work the layers in that order and the link initializes.

What initialization failure actually means #

Initialization, in the modem driver's sense, is a fixed handshake. The HMI opens its serial port, sends an initialization string of AT commands and waits for OK after each one. A reply of ERROR means the modem rejected a line as written; silence means the reply never arrived. Either way the driver reports failure and leaves the port closed, and every later send attempt fails with it.

RS232 — the EIA/TIA-232 standard — defines the two roles at the ends of a link: data terminal equipment (DTE), which is what an HMI serial port usually is, and data circuit-terminating equipment (DCE), which is what an RS232 modem or serial gateway is. On a DB9 connector a DTE transmits on pin 3 and receives on pin 2; a DCE swaps the roles and transmits on pin 2. The worked case behind this article is a Red Lion G3 HMI driving a Teltonika TRB142 modem gateway, and every step below applies to any HMI that drives an AT-command modem over RS232.

Read the modem's counters before touching software #

Most modem gateways expose serial byte counters on a status page, and those counters sort the fault before any setting changes. Put the HMI project in a state where it retries initialization, then read the pattern against this table.

What the counters show Where the fault sits
Both counters sit at zero No common ground, or the data conductors meet nothing — ring out the cable
The modem's receive counter climbs but the HMI never sees a reply The modem's transmit line is not reaching the HMI's receive line
Both counters climb but the HMI still reports failure The cable is sound; the fault is a parameter mismatch or a rejected string
Short periodic bursts with nothing configured to send The idle message poll — the link is already healthy

A half link is the classic cable signature: one conductor carries data while the return conductor is open, swapped, or contending with the far end's transmitter. When both ends drive the same conductor, the line sits at a stuck level and neither receiver sees valid data. A link where both counters advance is electrically sound, which moves the fault to the settings or the string.

Fix the cable with a meter, not a label #

Name the cable after its mapping, not its label. Two ends in the same role — two DTE ports or two DCE ports — need a null modem cable that swaps the data lines and behaves as the missing DCE. A DTE talking to a DCE needs the conductors joined pin for pin, which on two DB9 ends is the straight-through arrangement: pin 2 to pin 2, pin 3 to pin 3, pin 5 to pin 5, with no crossover anywhere.

Homemade adapters between a DB9 and an RJ12 serial port are where this fails. The conductor order on an RJ12 port is model-specific, some HMI ports are pre-crossed internally, and a cable crimped to the name crossover can be exactly one swap wrong. Ring it out:

  • With both ends unplugged, check continuity from the modem's transmit pin to the HMI's receive pin.
  • Check the modem's receive pin to the HMI's transmit pin.
  • Check signal ground end to end.
  • Confirm there is no continuity between the two data conductors, and none from either data conductor to ground.
  • Accept the cable only when the mapping matches both pin tables, not the name printed on the jacket.

In the worked case, the whole physical-layer fix was to swap two conductors at the RJ12 plug; both counters began to accumulate at once, which moved the fault to the string. When a port's own documentation calls for a straight-through cable instead of a null modem, the same meter check settles it — the page on a 20-pin serial port wired straight-through rather than null modem is one worked example. The crossover question reaches industrial buses too: straight-through versus crossover wiring for a DH-485 cable on an SLC 5/02 walks the same decision.

Set the serial parameters once, at both ends #

A parameter mismatch fails quietly: the modem hears garbage or answers at a speed the driver cannot parse, and the handshake dies without an ERROR to read. Choose one set and enter it at both ends — the gateway's serial service settings in its web interface and the modem settings in the HMI programming software.

Parameter Value
Baud rate 9600
Data bits 8
Parity None
Stop bits 1
Flow control None (no RTS/CTS, no XON/XOFF)

Use the listed speed first and raise it only after the link initializes cleanly, and change both ends together whenever anything changes. Flow control deserves its own check: hardware handshake enabled at one end and disabled at the other stalls the exchange without an error, because the modem waits for a clear-to-send the HMI never asserts or the driver waits for a carrier the modem never raises. For an SMS-only link, set flow control to none at both ends.

The initialization string that selects text mode #

The driver sends its string once, at session start, and it has to do four things: reset the modem, silence the echo, select text mode and load the service-center address. The commands, joined with semicolons into one line:

  • ATZ — reset to the saved power-on profile; the modem answers OK.
  • ATE0 — command echo off, so the driver parses clean replies instead of seeing its own commands; the modem answers OK.
  • AT+CMGF=1 — SMS text mode, where 1 selects text and 0 selects PDU; the modem answers OK.
  • AT+CSCA with the service-center address in quotation marks and a numbering-plan suffix; the modem answers OK.

So the driver's single line is ATZ;ATE0;AT+CMGF=1 followed by a semicolon and the service-center command. The address comes from the SIM's carrier, and the suffix is 145 for an international-format number or 129 for a national one. Some modems read the service-center address from the SIM on their own, but writing it in the string is the reliable path, which is why it closes the line.

The send itself uses AT+CMGS with the destination number in quotation marks: the modem answers with a greater-than prompt, the message text follows, and the control character 0x1A — Ctrl+Z — sends it. The modem then reports a message reference and OK. If any line in the string draws ERROR, the driver keeps the port closed, and that is the initialization failure the HMI reports.

Wire time is never the bottleneck #

With 8N1 framing, one character costs ten bit times: one start, eight data, one stop. At 9600 bits per second each character therefore takes 10 / 9600 = 1.04 ms. The full string with the service-center command stays under 50 characters: 50 × 10 = 500 bits, and 500 / 9600 = 52 ms of wire time. Even counting the four OK replies, the whole handshake occupies well under a tenth of a second, and the modem's own processing time between commands is longer than that. A failed initialization is a missing OK, never a speed problem.

Once the link is up, expect small traffic anyway. Red Lion's modem documentation for its G3 HMI sets a five-second cycle: once SMS messaging is enabled, the HMI tells the modem to look for new messages, incoming or outgoing, on that cycle, so a healthy link shows a short burst at that cadence even with nothing to send.

The fix order #

  1. Ring out the cable against both pin tables and correct the mapping before touching any setting.
  2. Enter the parameter set from the table at both ends, flow control included, and change both ends together on any later change.
  3. In the HMI project, select the modem driver — the generic Hayes-compatible (AT command) driver or the vendor's closest template; with no driver selected the port never opens.
  4. Enter the four-command initialization string, closing with the service-center command for the SIM's carrier.
  5. Initialize, then send a test message to a phone held in the other hand while watching the modem's counters move in both directions.
  6. If initialization succeeds but sends fail with a message-service error, check the SIM: no PIN active, registered on the network, and a service-center address that belongs to the carrier.

Treat the SMS path as notification, not a safety function: machine stop logic never depends on a delivered text, and the design should treat an undelivered message as an expected event rather than a silent failure.

When to skip the serial path #

When the modem offers a network interface and the traffic is outbound only, the serial route is optional: an HTTP GET against the modem's own interface needs no cable, no AT driver and no initialization string. The walkthrough in sending SMS from an HMI through an HTTP GET modem covers that route end to end. Keep the serial route for modems without a network interface, or when the application already reads inbound messages on the same port.

Questions asked

How long can the RS232 cable between HMI and modem be?

Design to the EIA-232 limit of about 15 m of cable at the standard's data rates. A 9600 baud link with short shielded cable sits comfortably inside that limit; when the modem must sit further away, attach it over USB or Ethernet instead of extending the serial run.

Do the modem cable's handshake lines need to be wired?

Not for outbound SMS. With flow control set to none at both ends, neither side watches the request-to-send or clear-to-send lines, so only the two data conductors and signal ground need continuity; the handshake pins can stay unconnected. It is mismatched flow control, hardware on one end and none on the other, that stalls an otherwise correct cable without an error.

Can the same modem receive inbound messages for the HMI?

Yes. Text mode handles inbound messages as well as outbound, and a G3 HMI checks with the modem for new incoming or outgoing messages on a five-second cycle once messaging is enabled. The HMI project still needs an inbound handler that stores or acts on each message; on an alarms-only panel, keep the link outbound-only so unhandled traffic cannot fill the SIM.

Why does the modem answer ERROR to a documented command?

An ERROR reply means the modem rejected the line as written: wrong syntax, a command it does not support in its current mode, or the next command sent before the modem finished resetting after the profile reset. Sending the commands one at a time from a terminal program isolates it: the first line that answers ERROR instead of OK is the one to fix.

How is the serial route different from sending SMS over HTTP?

Over HTTP the HMI acts as a web client and calls the modem's HTTP interface with a GET request, so there is no serial cable, no AT driver and no initialization string to maintain. The serial route fits modems without a network interface, or applications that already read inbound messages on the same port, but it inherits every cable and parameter mismatch described in this article.

Keep reading

  • Troubleshooting

    Building the RS-232 Modbus cable between an HMI and a controller

    Map the pins by signal name, not by number: the HMI's transmit on 25-pin pin 2 goes to the controller's receive, the HMI's receive on pin 3 comes from the controller's transmit, and signal common runs end to end. The jumper between pins 8 and 12 stays at the HMI connector. Generic straight-through and null-modem cables cause silence because the 25-pin and 9-pin standards number the data lines differently.

    Industrial networks

  • Troubleshooting

    Choosing the RS-485 protocol for one HMI and multiple PLCs

    Count the conductors before you open the HMI driver. On a 2-wire RS-485 DL-06 Port 2, Modbus RTU is the only protocol the port runs; rewire as 4-wire and K-sequence, DirectNET and Modbus RTU all open up, Modbus RTU fastest of the three. Give every PLC a unique station address, match baud and framing at both ends, and bring PLCs onto the bus one at a time.

    Industrial networks

  • How-to

    How to Share One RS-485 PLC Port Between Multiple HMIs

    Yes: several HMIs can share one RS-485 PLC port when the protocol coordinates who transmits — DH-485 token passing is the classic case — and every node holds a unique address. RS-485 itself only sets the electrical layer: 32 unit loads per segment, up to 1,200 m (4,000 ft) at low speed. Prove one panel, then add the rest one at a time and retest together.

    Industrial networks