Support Portal

PS30: Read the Current Format Length via PLC

PS30: Read the Current Format Length via PLC
Related Products
PS30
Attachments
20190401_PS30.rar
PS30_FormatlengthData.xlsx

Table of Contents

*Attention: PS30 is discontinued and not available anymore. There is no direct replacement product. Please contact us if you need further support*

You are familiar to the format length and Q output diagram of PS30 from the webserver (SOPAS air). 

 

Each Q and each length information after a Q have a time stamp in ms.

Method "getFormatLength"

This information is retrieved from the method "getFormatLength".
It delivers you the state of the switching output and the detected format length at a certain time stamp. The method should be called cyclically. It will then always transfer as many data sets as switching events happened since the last call (maximum 100).

The details about this method are found in the interface description if PS30 (see downloads section on website):
https://cdn.sick.com/media/docs/5/75/875/Technical_information_PS30_en_IM0078875.PDF

 

Unfortunately this sensor method is not in the scope of operation of the provided function block.
But the function block has the "FreeCommand" option. Using this we can retrieve the needed information.
More information about the "FreeCommand" can be found here:   Integration of PS30 - Part3: Function block and usage of FreeCommand 

In this Blog I use Siemens TiA Portal to read the format length:

1. First step is the creation of the needed data structure (FormatLengthStruct)

2. Create the data field where the data will be copied to

3. To get the result of the method "getFormatLength" we need to send the command "sMI 31" via the FreeCommand of the PS30 function block.

The answer from the device is then found in the "ResultData" array of the PS30 data structure of the function block.

In the attached excel file you can find some more details on the coding of the answer from the device: PS30_FormatlengthData.xlsx

 

4. Unfortunately there is a restriction of maximum 299Bytes for the receive array built in into the function block. This is not enough for the "getFormatLenth" method since the result of the method call could deliver up to 101 Q / format length / timestamp data sets. This is more than 900 Bytes.
Because of this we need to increase the size of the receive array inside the PS30 function block to 920Bytes:

There is also a test against the size of the array size in step 23 of the function block which needs to be increased:

5. After this the size of the FreeCommand array in the data structure of "ST_SICK_PS30" provided from the function block needs to be increased as well.

6. Now everything should be fine to read the format length data. In my case I had to restart the PLC to establish a new TCP connection. Maybe you have this effect as well...
 

7. My code to read the format length data cyclically is attached.
Roughly what is done:

  • Function block "PS30_Comm" is called in OB1 (in OB1 additionally the cycle time of the PS30_Comm function block is measured)
  • Inside "PS30_Comm" the program is controlled with the variable "istep".
    • Step 1: Starts the program by opening the TCP connection
    • Step 2: Write the necessary command for the free command of the PS30 function block
    • Step 3: Start the request. The request to the sensor is triggered by a 1Hz clock.
    • Step 4: Read values are copied into the new data structure.
    • Step 99: Is called in case of error.

 

One question may be left: How often do I need to call the method "getFormatLength" to get all the information?

Here is how to calculate the number of events per second:

Needed parameters:

  • Maximum speed: Vmax (in m/s)
  • Expected minimum format length: Lmin (in mm)

Formula:

Events/s = 1000 / Lmin * Vmax * 2


Example:

Vmax = 7,5m/s
Lmin = 155mm

Events/s = 1000mm / 155mm * 7,5m/s * 2 = ~97 Events/s

==> In this example the update rate of 1 second is just enough.

 

Example project in the attachments: 20190401_PS30.rar

 

Keywords:
functionblock, integration, plc, ps30