Beckhoff#Let’ use Keyence SR750 with TwinCAT3 and Profinet!

This article explains the procedure for linking a Beckhoff TwinCAT3 and a Keyence SR750 with Profinet from scratch. (From Youtube Channel Comment request)

Let’s enjoy FA.

Reference Video

Beckhoff.Use Keyence SR750 with TwinCAT3 and Profinet

Beckhoff.Use Keyence SR750 with TwinCAT3 and Etherent/IP

Reference Link

Keyence#Let’s connect SR750 With Beckhoff TwinCAT3 and Etherent/IP

PROFINET?

PROFINET is an open communication standard defined by PI (PROFIBUS & PROFINET International) PROFINET compatible devices can communicate regardless of vendor and PROFINET compatible devices can communicate regardless of vendor. The SR-750 series conforms to Conformance Class A and supports cyclic communication.

Cyclic communication

Cyclic communication enables high-speed control at intervals of several ms to several tens of ms by communicating at update time intervals. Cyclic communication enables high-speed control at intervals of several ms to several tens of ms by communicating at update time intervals.

The SR-750 series can refer to and update variables and devices in the PLC and control them without having to be aware of communications. This simplifies programming on the PLC side.When controlling the SR-750 series, set the update time for cyclic communication to 8 ms or more. The maximum reading length is 246 digits.

Note that the communication settings such as communication cycle and data size for cyclic communication are made on the PLC side,

In networks where a large number of devices including PROFINET devices are connected, delays and packet losses may occur if the load is heavy. Please carry out sufficient verification before operation.

Function Overview

Timing input control Controls 

Timing input can be switched on and off and a parameter bank can be specified for timing input.

Preset data control 

Lead OK data can be set as preset data.

Preset data can also be registered and deleted from the PLC.

Tuning 

Parameter banks can be specified for tuning.

Data handshake 

It can control whether the read data is written to the PLC.

Error handling 

Errors that have occurred in the unit can be checked.

After the error factors have been removed, the SR-750 series can be restored from the error state.

Statistical information acquisition

The number of readings and read data updates can be checked.

Operation status acquisition

Readings data can be retrieved and I/O status and marking verification results can be checked.

Operation flow with PROFINET 

Step1:Check specifications

Check whether the PLC to be connected supports PROFINET connection and the status of input/output data allocation.

Step2:Make the PROFINET communication setting f

Set these items when connecting the SR-750 series to PROFINET.

  • IP address
  • Subnet mask
  • Default gateway
  • Enable/disable PROFINET communication
  • PROFINET device name, data
  • Handshake enable/disable

The PROFINET device name must be set to the same device name in the network, and the temporary IP address set in the SR-750 series cannot be used for PROFINET communication After the PROFINET settings are transferred to the main unit’s OS, the SR-750 series main unit reboots.

Step3:Establish PROFINET communication.

To register SR-750 information to the PLC, use the SR-750 GSDML file.

Step4:Perform necessary tasks.

Start testing the application.

Time chart

Implementation

Keyence Side

Initially, we will configure the Keyence SR750 side.

Communication Setting

Start AutoID Network Navigator and use the Communication2 tab to configure communication settings.

Set Protocol to PROFINET and click Details.

Set the device name of the SR-750.

Send Configuration

Once you have completed the setup of the SR-750, use Transfer>Send Configuration to transfer your project to the device.

Beckhoff Side

The next step is to build the Beckhoff TwinCAT3 side.

Install GSDML

Download the SR-750 GSDML File on the Keyence HP via the link below.

https://www.keyence.co.jp/products/barcode/barcode-readers/sr-750/downloads/?mode=so&modelId=

Store the GSDML File in the following Directory.

/TwinCAT/3.1/Config/Io/Profinet

Add Profinet RT Controller

I/O>Devices>right-click>Add New Item.

Select Profinet I/O Controller (RT) and proceed with OK.

Done!Profinet I/O Controller (RT) has been added.

Configure Adapter

Set the Ethernet Intetface to be used as PROFINET Controller in the Adapter Tab.

Sync Task

Set the PROFINET Task time in Sync Task.

Settings

Finally, set the IP and device name of the PN Controller in the Settings Tab.

Just click on Set IP Settings.

Done!

Add SR-750

Next, to add the Keyence SR-750, go to Profinet Controller>Right click>Add New Item.

Select KEYENCE CORPORTATION>Sensor>Keyence Code Reader and proceed with Ok.

Done!

Term2-10 are input data and Term11-15 are output data.

Device Name

Next, let’s set the device name for the SR-750.

IP Address

Also, Profinet sets the IP address along with the device name, so the IP address should also be set according to the application.

Add PLC

Now that we have finished setting up Fieldbus, the next step is to create a PLC program.

PLC>right click>Add New Item.

Select Standard PLC Project>Add.

DUT

This is a structure created to match the Profinet structure of SR-750.

DUT_SR750_PN_InData_Term2 

こちらはSR-750の結果状態やエラーを示す構造体です。

TYPE DUT_SR750_PN_InData_Term2 :
STRUCT
Error:BIT;
Result_Data_Available:BIT;
Result_Data_Strobe:BIT;
Buffer_Overflow_Error:BIT;
General_Error:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term3 

Here is a structure showing the Busy state of SR-750.

TYPE DUT_SR750_PN_InData_Term3 :
STRUCT
Busy:BIT;
Try_Busy:BIT;
Lock_Busy:BIT;
Mode_Busy:BIT;
Err_Busy:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term4 

This is a structure that indicates the operation completion status of SR-750.

TYPE DUT_SR750_PN_InData_Term4 :
STRUCT
Read_Complete
,Preset_Complete
,Register_Present_Data_Complete
,Tune_Complete
,EXT_Request_Complete
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term5 

This is a structure that indicates the error status of SR-750.

TYPE DUT_SR750_PN_InData_Term5 :
STRUCT
Read_Failure
,Preset_Failure
,Register_Preset_Data_Failure
,Tune_Failure
,EXT_Request_Failure
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term6 

This structure shows the input/output terminal status of the SR-750.

TYPE DUT_SR750_PN_InData_Term6 :
STRUCT
IN1_Status
,IN2_Status
,OUT1_Status
,OUT2_Status
,OUT3_Status
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term7 

This is a structure that shows the environmental status of SR-750.

TYPE DUT_SR750_PN_InData_Term7 :
STRUCT
Unstable
,Matching_Level_Unstable
,ISO_IEC_15415_Unstable
,ISO_IECTR_29158_AIM_DPM_1_2006_Unstable
,SAE_AS9132_Unstable
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term8 

This is another structure that indicates the environmental status of the SR-750.

TYPE DUT_SR750_PN_InData_Term8 :
STRUCT
MatchingLevel
,ISO_IEC15415_Grade
,ISO_IEC_TR29158_Grade
:UINT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term9 

This is a structure that shows the results of SR-750 operations and error codes.

TYPE DUT_SR750_PN_InData_Term9 :
STRUCT
ReadResultCode
,PresetResultCode
,RegisterPresetDataResultCode
,TuneResultCode
,RXTRequestResultCode
,GeneralErrorCode
:UINT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term10 

This is a structure that shows the result of reading the SR-750’s Barcode.

TYPE DUT_SR750_PN_InData_Term10 :
STRUCT
ResultDataReadyCount
,ResultDataUpdateCount
,ResultDataSize
:UINT;
ResultDat:ARRAY [0..127] OF BYTE;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term11 

This is a structure that clears errors against SR-750.

TYPE DUT_SR750_PN_InData_Term11 :
STRUCT
Result_Data_Latch
,ErrorClear
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term12 

This is a structure that makes an operation request to the SR-750.

TYPE DUT_SR750_PN_InData_Term12 :
STRUCT
Read_Request
,Preset_Request
,Register_Preset_Data_Request
,Tune_Request
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term13 

This is the structure that clears the operation results for the SR-750.

TYPE DUT_SR750_PN_InData_Term13 :
STRUCT
Read_Complete_Clear
,Preset_Complete_Clear
,Register_Preset_Data_Compleite_Clera
,Tune_Comlete_Clear
,EXT_Request_Complete_Clear
:BIT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term14 

This is the structure of the Bank number to be sent to SR-750.

TYPE DUT_SR750_PN_InData_Term14 :
STRUCT
BankNumberRegister:UINT;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData_Term15 

This is the structure of User Data to be sent to SR-750.

TYPE DUT_SR750_PN_InData_Term15 :
STRUCT
UserDataSize:UINT;
UserData:ARRAY[0..127]OF BYTE;
END_STRUCT
END_TYPE
DUT_SR750_PN_InData 

This is a summary of the structure to be received from the SR-750 defined earlier.

TYPE DUT_SR750_PN_InData :
STRUCT
Term2:DUT_SR750_PN_InData_Term2;
Term3:DUT_SR750_PN_InData_Term3;
Term4:DUT_SR750_PN_InData_Term4;
Term5:DUT_SR750_PN_InData_Term5;
Term6:DUT_SR750_PN_InData_Term6;
Term7:DUT_SR750_PN_InData_Term7;
Term8:DUT_SR750_PN_InData_Term8;
Term9:DUT_SR750_PN_InData_Term9;
Term10:DUT_SR750_PN_InData_Term10;
END_STRUCT
END_TYPE
DUT_SR750_PN_OutData 

This is a summary of the structure to be sent to the SR-750 defined earlier.

TYPE DUT_SR750_PN_OutData :
STRUCT
Term11:DUT_SR750_PN_InData_Term11;
Term12:DUT_SR750_PN_InData_Term12;
Term13:DUT_SR750_PN_InData_Term13;
Term14:DUT_SR750_PN_InData_Term14;
Term15:DUT_SR750_PN_InData_Term15;
END_STRUCT
END_TYPE
DUT_SR750_PN 

The final step is to put together the inputs and outputs.

TYPE DUT_SR750_PN :
STRUCT
in AT %I*:DUT_SR750_PN_InData;
Out AT %Q*:DUT_SR750_PN_OutData;
PnIoBoxState,PnIoBoxDiag AT %I*:UINT;
END_STRUCT
END_TYPE

GVL

Define variables to communicate with Keyence SR-750 in the Global Variable List.

{attribute ‘qualified_only’}
VAR_GLOBAL
SR750_PN:DUT_SR750_PN;
END_VAR

Program

This is the program for this article, which initializes the Function Block, reads the Bar Code, and if there is no completed Flag from the SR-750, retries 3 times, and if not, goes to Error Step. If there is a completion flag from SR-750, it transfers the result to a variable.

PROGRAM MAIN
VAR
Result:STRING;
bRead:BOOL;
CommStatus:BOOL;
RetryCount:USINT:=3;
CurrentCount:USINT:=0;
CameraNotFailure:BOOL;
iState:UINT;
TON:TON;
bReset:BOOL;
ReadingTime:TIME:=T#1S;
Error:BOOL;
END_VAR


CommStatus:=
GVL.SR750_PN.PnIoBoxDiag=2  AND GVL.SR750_PN.PnIoBoxState=0;

CameraNotFailure:=
NOT GVL.SR750_PN.in.Term5.EXT_Request_Failure
AND NOT GVL.SR750_PN.in.Term5.Preset_Failure
AND NOT GVL.SR750_PN.in.Term5.Read_Failure
AND NOT GVL.SR750_PN.in.Term5.Register_Preset_Data_Failure
AND NOT GVL.SR750_PN.in.Term5.Tune_Failure
AND NOT GVL.SR750_PN.in.Term2.General_Error
;

CASE iState OF

0:
CurrentCount:=0;
TON(IN:=FALSE,PT:=ReadingTime);
GVL.SR750_PN.Out.Term13.Read_Complete_Clear:=TRUE;
Error:=FALSE;
IF bRead AND CommStatus THEN
iState:=5;
END_IF
5:
Result:=”;
bReset:=FALSE;
GVL.SR750_PN.Out.Term13.Read_Complete_Clear:=FALSE;
iState:=10;
10:
IF CameraNotFailure THEN
iState:=20;
ELSE
iState:=990;
END_IF

20:
GVL.SR750_PN.Out.Term12.Read_Request:=TRUE;
TON(IN:=TRUE);
IF TON.Q THEN
IF GVL.SR750_PN.in.Term4.Read_Complete AND
NOT GVL.SR750_PN.in.Term5.Read_Failure THEN
iState:=30;
ELSIF GVL.SR750_PN.in.Term5.Read_Failure THEN
iState:=200;
END_IF
TON(IN:=FALSE);
GVL.SR750_PN.Out.Term12.Read_Request:=FALSE;
END_IF
30:
MEMMOVE(
destAddr:=ADR(Result)
,srcAddr:=ADR(GVL.SR750_PN.in.Term10.ResultDat)
,n:=GVL.SR750_PN.in.Term10.ResultDataSize
);
iState:=40;
40:
GVL.SR750_PN.Out.Term13.Read_Complete_Clear:=TRUE;
IF NOT GVL.SR750_PN.in.Term4.Read_Complete THEN
GVL.SR750_PN.Out.Term13.Read_Complete_Clear:=FALSE;
iState:=0;
bRead:=FALSE;
END_IF;
200:
CurrentCount:=CurrentCount+1;
IF CurrentCount > RetryCount THEN
iState:=991;
ELSE
iState:=20;
END_IF;
990,991:
Error:=TRUE;
bRead:=FALSE;
IF bReset THEN
iState:=0;
END_IF;

END_CASE

GVL.SR750_PN.Out.Term11.ErrorClear:=bReset OR (iState=200);

Link Input/Output

Remember to link the Process Input/Output of each Slot with the variables of the User Program.

Download

The last step is to Download the project to Runtime in Activate Configuration.

OK to proceed.

Switch TwinCAT to Run Mode.

Start

Finally, click the Start button to start Runtime.

Result

I see that the SR-750 can read 2D codes.

With PnIoBoxState=2, we also confirmed that Profinet communication between TwinCAT3 and SR750 was established.

With PnIoBoxDiag=0, we also confirmed that Profinet communication between TwinCAT3 and SR750 was established.

This video shows what SR750 does in the event of a read failure.

Beckhoff.Using Profinet to communicate with Profinet SR-750(Error Case)

This video shows the process when SR750 fails to read and then retries and succeeds.

Beckhoff.Using Profinet to communicate with Keyence SR-750(Retry and OK)

You can see the process when SR750 is successfully read from this video.

Beckhoff.Using Profinet to communicate with Profinet SR-750(Normal)

Download Project

You can download the project for this article at this Link.

https://github.com/soup01Threes/TwinCAT3/blob/main/TwinCATWithSR750_PN.tnzip

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする