Connecting Omron PLC to printer with TCP/IP


In this post I will outline how I was able to connect a ZD420 printer to an Omron NJ series PLC. This task took me a considerable amount of time and manual reading, so hopefully this will help speed up the process for someone out there!

The first trick was to define a structure in Sysmac Studio that matched the Input Assembly from the Network Connect for Automation Developers Guide:…

I used a UINT counter to increase the Sequence Number, set the Format Number to 01, and left every field, except Raw Parser Data, as null. In the Raw Parser Data I could write up to 320 bytes ZPL code as a string. If your ZPL code is longer than the 320 bytes, two messages can be sent with another instance of the Input Assembly Structure with ^XA starting the first message, and ^XZ terminating the second message. Using UINT to BYTE and StringToAry the data was placed in a sending array of 496 bytes with offsets defined by the Input Assembly to account for the two null bytes required at the beginning of each section.

The TCP/IP port for the printer can be found by connecting to the printers IP address (when on the same network as the printer, type the printer's IP address into web browser search bar), and going into the TCP/IP settings (default username is admin and password is 1234). Use that port number as the destination port for the SktTCPConnect. The source port for this command should be set to 0. In Sysmac this will make the PLC find a new available port number for each connection, allowing connections to be made as often as needed. Use the structure outlined in the Sysmac instruction help manual to complete the sending and receiving of messages to and from the printer.

I was able to use the ~HSEQ  ZPL command to receive errors back from the printer. The errors are returned in a string, but are formatted so that the error bytes are in the same index position each time. The programming guide for ZPL 2 says that the ~HS command is not compatible with the ZD420 printer, I think this is because it does not have a display, not because the printer doesn't recognize the command / return anything (can someone from Zebra confirm this?). The return size of this array is 144 bytes, which will be placed in the RcvDat array of the SktTCPRcv command in Sysmac.

Good luck,