Controlling Festo PLC via TCP/IP instead of serial with PHP

P

Thread Starter

Paul

Hi,

I am a photographer and I also program in PHP/MySQL. I need help on the following matter...

How to control a Festo PLC via TCP/IP instead of serial with PHP? I have managed to write a small script in PHP that uses the PHP-serial-class that send values to a Festo PLC (FC20). It works but very slowly (about 100 values per min) and if I go to fast it returns some error.

As the PLC has an ethernet port, I want to communicate via TCP/IP (that's how the Festo software works). And I want to do that from my Mac in PHP. Here is the few lines of code used for the serial communication. What do I have to do to do the same via TCP/IP?

// create serial communication
$serial = new phpSerial;

// set-up serial port
$serial->deviceSet("/dev/cu.usbserial");

// change the baud rate (device must be closed)
$Result = $serial->confBaudRate($BaudRate);

// change the parity (device must be closed)
$Result = $serial->confParity($Parity);

// change the character length (device must be closed)
$Result = $serial->confCharacterLength($CharacterLength);

// change the stop bits (device must be closed)
$Result = $serial->confStopBits($StopBits);

// change the flow control (device must be closed)
$Result = $serial->confFlowControl($FlowControl);

// open serial port
$serial->deviceOpen();

// test PLC read/write
$Result = $serial->sendMessage($CTRL_T);
$Result = $serial->sendMessage("dmw0".$CarLF);
$ReadSerial = $serial->readPort();

// write to serial port (loop)
$Result = $serial->sendMessage("mmw".$j.$CarLF.$PLC_ValueLin[$i].$CarLF,$SendDelay);
$ReadSerial = $serial->readPort();
$Result = $serial->sendMessage("dmw".$j.$CarLF,$SendDelay);
$ReadSerial = $serial->readPort();

// close serial port
$serial->deviceClose();
 
Top