Reading a register value from PLC

Hi ,
I am conducting a study on reading PLC variables remotely for data processing.
I am looking for a way to read register data from a PLC by examining Server and Client examples. How can I read a variable without making any changes on the PLC side. In the example I have added here, myServer.write(val); Since it has a line, the content of the val variable is written on the client side. The PLC side that I want to learn is myServer.write(val); Is there a way to read the registers without using the line?



Server myServer;
int val = 0;

void setup() {
size(200, 200);
// Starts a myServer on port 5204
myServer = new Server(this, 5204);

void draw() {
val = (val + 10) % 255;


Client myClient;
int dataIn;

void setup() {
size(200, 200);
// Connect to the local machine at port 5204.
// This example will not run if you haven’t
// previously started a server on this port.
myClient = new Client(this, “”, 5204);

void draw() {
if (myClient.available() > 0) {
dataIn =;

Hi @herdal, Welcome. You are using Processing to talk to PLC(?) so the PLC is the server? and Processing is the client? Don’t see why you need “//Server Side”. Do you have the PLC handy for testing? Does the PLC talk Modbus-TCP protocol? I’ve written programs to talk Modbus-TCP. I think you need to establish a link (TCP) to the PLC, construct an enquiry message, send it, receive what comes back. You need the PLC’s comms manual, or its Modbus map.

(To make your post easier to read, please edit it and format the code. In turn select each piece of code and click the </>. Thanks.)

Hi @RichardDL,
Thanks for helping out first.

We have 5 machines. Each machine has a different PLC device, Siemens S7 1500 and Beckhoff PC. We are currently monitoring the critical parameters of PLCs with the Kepserver program. However, I am sure that the communication between HMI and Beckhoff PC is Modbus in only one of the machines. I don’t know what the protocol of other machines is. In case of any failure, I can connect with my computer via the ethernet port of each machine and monitor the fault online. When I examine the PLC program, I see that the critical parameters I mentioned are not sent by the PLC, but the KepServer program we are currently using can read these parameters.
I am giving answers to your question:
1-Yes, I want to talk Processing and PLC.
2-How can I understand whether PLC is a server or a client?(When I examine the PLC program, it does not send parameters. There are people who can remotely read any parameter of the running program.)
3-Modbus is used only in one of my machine. (between HMI and PLC)
4-I agree with you. I don’t know how to send a request to read critical variables in PLC.


@herdal, Think you need to read Siemens S7 Comms Manual. Table 3-2 has long list of available protocols. I’ve only glanced through the doc that far. Don’t know if you have to enable each or they are just waiting to be used. PLC is more likely to be server because it’s more convenient that way, ready to give info when asked from any PC(s). Modbus-TCP is there and probably the easiest from Processing. UDP is there, also easy, and Processing has a UDP library. I’ve used OPC a lot and written client programs in VB and AutoIt. Not had to use OPC UA yet. HTTP looks interesting, Processing can do that, I’ve not used.

Ultimately you could use WireShark to see the comms between Kepware etc. and the PLCs.

1 Like


Thank you very much for your valuable contribution.I will continue to research.

Best regards