PLC Communication
- PLC Communication
- Block Tag Overview
- Allen Bradley Tag Structure
- Siemens S7 Block Structure (UDT):
- Siemens S7 Configuration
- Description of Logic
- PLC Override Logic
- Send Message Logic
The I/O block defined in this document will link a PLC to many mobile devices. The application can be configured to talk to several of these data blocks on multiple PLC's. Each block will control a group of mobile devices with all devices in that group receiving a inspection request (trigger) when the PLC sends the command. Each mobile device can only be configured to connect to a single I/O block.
Communication between MVS Server and a PLC takes place via OPC. For more information see KepwareConfiguration
Block Tag Overview
-
Outputs: Data written by the Application Server (these values should be considered read only by the PLC, as the MVS application will only write these values)
Heartbeat
: Heartbeat of the application server (toggled every X seconds)- DataType: Boolean (1bit)
InspectionStatus
: A byte describing the state of the inspection (see Inspection Status)- DataType: Int (16bit)
Inspection_PASS
: true if inspection has passed.- DataType: Boolean (1bit)
Inspection_FAIL
: true if inspection has failed.- DataType: Boolean (1bit)
ErrorCode
: If theInspectionStatus
is inError
this error code will indicate the specific state. (see Error Codes)- DataType: Int (16bit)
Inspection_STRING
: additional field if the inspection is reading any OCR/Barcode data.- DataType: String (recommended length: 32 character)
PartSerial_ECHO
: Echo of thePartSerial
.- DataType: String (controls/kepware defined length, same as
PartSerial
)
- DataType: String (controls/kepware defined length, same as
InspectionPointID_ECHO
: Echo of theInspectionPointID
.- DataType: String (16 char)
TriggerInspection_ECHO
: Echo of theTriggerInspection
bit.- DataType: Boolean (1bit)
ClearResults_ECHO
: Echo of theClearResults
bit.- DataType: Boolean (1bit)
CancelInspection_ECHO
: Echo of theCancelInspection
bit.- DataType: Boolean (1bit)
SendMessage_ECHO
: Echo of theSendMessage
bit.- DataType: Boolean (1bit)
MessageID_ECHO
: Echo of theMessageID
int.- DataType: Word (16bit)
MessageStatus
: The status of the last message.- DataType: Word (16bit)
-
Inputs: Data written by the PLC and read by the app server (these values are considered read only by the MVS application)
InspectionPointID
: A unique key of theInspectionPointDto
the PLC is requesting to run. (user configurable field)- DataType: String (16 char)
TriggerInspection
: The app server will watch for the rising edge of this bit to trigger a inspection (ie. send theInspectionRequest
via the camera status hub). ThePartSerial
andInspectionPointID
fields should be echoed prior to raising this bit.- DataType: Boolean (1bit)
ClearResults
: A signal to tell the application server to clear the results it has written to the PLC.- DataType: Boolean (1bit)
CancelInspection
: A signal to tell the application server to cancel any pending inspections triggered by this plc.-- DataType: Boolean (1bit)
PartSerial
: The serial number /unique identifier of the part. The value in this field does not effect logic, it is saved into the database with the image and the inspection result. It is purely for traceability.- DataType: String (controls/kepware defined length)
MessageID
: The Id of the message (defined in MVS Server) to send to all connected mobile devices.- DataType: Word (16bit)
SendMessage
: A command bit to send theMessageID
to the connected clients. This command will override any previous messages that the user has not responded to.
Inspection Status (look up table)
/// Initialzing state, default until image processing is ready
WaitingForIPM = 0,
/// System is ready for a trigger
Ready=1,
/// Inspection processing is complete and results can be read
Complete=2,
/// Requesting a image from the remote device/camera
Requesting=3,
/// Image has been received and is being processed
Processing = 4,
/// There was a error. see <see cref="PlcErrorCodes"/> for details
Error=5,
/// the inspection was canceled by the PLC
Canceled = 6,
Error Codes (look up table)
NoError = 0,
/// Remote camera is not connected, can't be located, or isn't ready to take images
DeviceNotFound = 1,
/// The specified inspection ID does not exist
InspectionNotFound = 2,
/// There was a error during processing, see IPM Logs for details
ProcessingError = 3,
/// There was a internal error handling the PLC request. See application server logs for details
InternalError = 4,
/// The inspection is not properly configured. This usually means its missing a IPM Workspace.
InspectionConfigurationError = 5,
/// IPM client is not available to process the image
ProcessingNotAvailable = 6,
MessageStatus Codes (Look Up Table)
/// Ready to send a message
Ready = 0,
/// Waiting for the user to respond to the message.
Waiting = 1,
/// Message Not Found. The messageKey does not exist on the server.
MessageNotFound = 2,
/// Message Complete, no clients were available to receive the message
NoAvailableClients = 3,
/// Message Complete, unhandled exception caught in the process.
ApplicationException = 4,
/// The user responded in the Affirmative (`Yes`,`Accept`,`Ok`)
AffirmativeResponse = 5,
/// The user responded in the Negative (`No`,`Reject`,`Cancel`)
NegativeResponse = 6,
Allen Bradley Tag Structure
MVSCAMERA.CANCELINSPECTION | Boolean |
---|---|
MVSCAMERA.CANCELINSPECTION_ECHO | Boolean |
MVSCAMERA.CLEARRESULTS | Boolean |
MVSCAMERA.CLEARRESULTS_ECHO | Boolean |
MVSCAMERA.EMPLOYEEOVERRIDE_ECHO.DATA/32 | String |
MVSCAMERA.ERRORCODE | Short |
MVSCAMERA.HEARTBEAT | Boolean |
MVSCAMERA.INSPECTION_FAIL | Boolean |
MVSCAMERA.INSPECTION_PASS | Boolean |
MVSCAMERA.INSPECTION_STRING.DATA/32 | String |
MVSCAMERA.INSPECTIONPOINTID.DATA/16 | String |
MVSCAMERA.INSPECTIONPOINTID_ECHO.DATA/16 | String |
MVSCAMERA.INSPECTIONSTATUS | Short |
MVSCAMERA.LOGOVERRIDE | Boolean |
MVSCAMERA.LOGOVERRIDE_ECHO | Boolean |
MVSCAMERA.OVERRIDEEMPLOYEEID.DATA/32 | String |
MVSCAMERA.PARTSERIAL.DATA/32 | String |
MVSCAMERA.PARTSERIAL_ECHO.DATA/32 | String |
MVSCAMERA.TRIGGERINSPECTION | Boolean |
MVSCAMERA.TRIGGERINSPECTION_ECHO | Boolean |
MVSCAMERA.MESSAGEID | Short |
MVSCAMERA.MESSAGEID_ECHO | Short |
MVSCAMERA.SENDMESSAGE | Boolean |
MVSCAMERA.SENDMESSAGE_ECHO | Boolean |
MVSCAMERA.MESSAGERESULT.DATA/32 | String |
MVSCAMERA.MESSAGESTATUS | Short |
Siemens S7 Block Structure (UDT):
Total Size 348 bytes
(depending on string length)
Name | DataType | Offset | Notes |
---|---|---|---|
INPUTS | |||
Heartbeat | Bool | 0.0 | |
TriggerInspection_ECHO | Bool | 0.1 | |
ClearResults_ECHO | Bool | 0.2 | |
CancelInspection_ECHO | Bool | 0.3 | |
LogOveride_ECHO | Bool | 0.4 | |
Inspection_PASS | Bool | 0.5 | |
Inspection_FAIL | Bool | 0.6 | |
SendMessage_ECHO | Bool | 0.7 | |
InspectionStatus | Int | 2.0 | |
ErrorCode | Int | 4.0 | |
InspectionPointID_ECHO | String | 6.0 | Fixed Length: 16 |
PartSerial_ECHO | String | 24.0 | Custom Length: 48 |
EmployeeOverride_ECHO | String | 74.0 | Custom Length: 48 |
Inspection_STRING | String | 124.0 | Custom Length: 48 |
MessageId_ECHO | Int | 296.0 | |
MessageStatus | Int | 298.0 | |
MessageResult | String | 300.0 | Custom Length: 48 |
OUTPUTS | |||
TriggerInspection | Bool | 174.0 | |
ClearResults | Bool | 174.1 | |
CancelInspection | Bool | 174.2 | |
LogOveride | Bool | 174.3 | |
SendMessage | Bool | 174.4 | |
InspectionPointID | String | 176.0 | Custom Length: 16 |
PartSerial | String | 194.0 | Custom Length: 48 |
OverrideEmployeeID | String | 244.0 | Custom Length: 48 |
MessageId | Int | 294.0 |
Siemens S7 Configuration
To communicate via Kepware the PLC must allow access from an external systems. Enable in TIA Portal: Device Configuration > Protection & Security > Connection mechanisms > Permit access with PUT/GET communication from remote partner.
Description of Logic
Echo Tags
All Outputs from the plc have a corresponding "TAGNAME
_ECHO" field. This field will be written with the value of the corresponding tag as soon as possible by the software. Its purpose is to confirm to the PLC that the software has read the values prior to executing any logic. This will prevent any race conditions (and unintended behavior) if the PLC updates several values on the same scan.
If the PLC sets the InspectionPointID field and TriggerInspection boolean on the same scan, the software might read and execute its trigger logic before receiving the updated InspectionPointID value - running the wrong inspection. Therefore its best practice to confirm that the ECHO fields match prior to triggering any logic.
This should also be used to confirm that the trigger command was read by the MVS Application. Since the scan rate of the PLC is likely much higher than the polling rate of the OPC server, a one-shot pulse will likely be missed by the application.
Heartbeat Logic
The application will toggle the heartbeat boolean every 5 seconds. If this value does not change within some timeframe, say 10-20 seconds, the PLC can assume that a fault has occurred and the software is unresponsive or shutdown. Once the heartbeat resumes the PLC can assume the software is functional again.
Command Logic
The application can receive several commands from the PLC. Each command takes the form of a boolean value and the application will attempt to execute the command on detecting a rising edge (0
to 1
) transition of the value. They are as follows:
TriggerInspection
: Trigger a inspection using the values in theInspectionPointID
andPartSerial
addresses.ClearResults
: Clear any results/errors in the vision system. Specifically the application will set the following values:Inspection_PASS
:0
Inspection_FAIL
:0
InspectionStatus
:Ready=1
(if initialized) orInitializing = 0
if the system is loadingErrorCode
:NoError = 0
CancelInspection
: Abort and cancel any trigger signals that have not received a response from a mobile device. The intention behind this command it to allow the PLC to timeout if a operator takes too long to respond. If a inspection was canceled theInspectionStatus
will be set toCanceled=6
Trigger Command Logic
Triggering is how the plc will request a image from a mobile camera. The logic is as follows:
-
The plc needs to wait for the
InspectionStatus
to beReady=1
,Complete=2
, orCanceled=6
for the application to accept a trigger command. Otherwise the command will be ignored. Note: If theInspectionPointID
has no IPM workspace assigned theInspectionStatus
can beWaitingForIPM=0
when the trigger is sent. -
The plc will populate the
InspectionPointID
field with a unique value (defined in the MVS software) that identifies the requested inspection. -
[Optional] The PLC will populate the
PartSerial
field with the serial number of the part being inspected. The value entered in this field will be added to the application's database along with the image and results of the inspection. -
The PLC will wait for the
InspectionPointID_ECHO
(and possibly for thePartSerial_ECHO
) values to match theInspectionPointID
value (alsoPartSerial
if set). -
The PLC will set the
TriggerInspection
Boolean from0
to1
. -
The application will do the following:
- Echo the
TriggerInspection
value inTriggerInspection_ECHO
. - Update the
InspectionStatus
toRequesting=3
- Validate the
InspectionPointID
value exists, if not it will set theInspectionStatus
toError=5
, theErrorCode
toInspectionNotFound = 2
, and abort the trigger. - Validate at least one mobile device is connected to the server that is configured to process the
InspectionPointID
, if not it will set theInspectionStatus
toError=5
, theErrorCode
toDeviceNotFound = 1
, and abort the trigger. - If the above conditions are met, it will send the request to the mobile device(s) to acquire a image.
- Echo the
-
Once a mobile device receives the request the I/O state will remain unchanged until the PLC sends a
CancelInspection
command or a image is sent from a mobile device to the application server. If the PLC setsCancelInspection
from0
to1
at this point the application will abort the trigger andInspectionStatus
will be set toCanceled=6
-
Once a image is received from the mobile device the server will update the
InspectionStatus
toProcessing = 4
. -
Once processing the image is complete, the application will write the
Inspection_PASS
andInspection_FAIL
,Inspection_STRING
values with the results generated by the image processing. It will then set theInspectionStatus
toComplete=2
PLC Override Logic
Overrides are when a supervisor on the line will override an inspection, forcing the logic to move to the next step of the process regardless of the vision result. This logic is handled on the PLC, but for traceability reasons its best to also log the override in the database. This is initiated from the PLC via the LogOverride
command, and will log the override along with the value from OverrideEmployeeID
to the database.
-
The plc needs to wait for the
InspectionStatus
to beReady=1
,Complete=2
, orCanceled=6
for the application to accept a override command. Otherwise the command will be ignored. -
The PLC will populate the following fields and wait for their corresponding ECHO to be written by the software:
OverrideEmployeeID
: Identification of the employee who is performing the override (no validation on this value, it will just save to the database)InspectionPointID
: The key value of the inspection point that this override applies to.PartSerial
: The serial number of the part that the override applies to.
-
Once the ECHO fields match, the PLC can set the
LogOverride
Boolean from0
to1
. -
The application will do the following on detecting a rising edge of
LogOverride
:- Echo the
LogOverride
bit toLogOverride_ECHO
. - Update the
InspectionStatus
toProcessing=4
- Lookup the inspection results for the supplied
InspectionPointID
andPartSerial
- If the results are located it will Log the override to the database with the supplied
OverrideEmployeeId
value and set theInspectionStatus
toComplete=2
- If the results can't be located it will set
InspectionStatus
toError=5
, theErrorCode
toInspectionNotFound=2
- If the results are located it will Log the override to the database with the supplied
- Echo the
Its expected that the above process will complete very quickly, possibly on the same scan, so the transition of InspectionStatus
from Ready=1
to Processing=4
and again to Complete=2
might not be observed on the plc.
Send Message Logic
Plc Push Messages are a way for the PLC to push a message dialog to the remote cameras assigned to the PLC. To invoke the message logic, the PLC needs to specify the MessageID
(MessageKey) and set the SendMessage
bit high. The MessageStatus
bit will relay the state and result of the message back to the PLC. If there the message requests a custom text/number/pin the value will be written to the MessageResult
field. If any unhandled exceptions are raised by the server during this sequence, the MessageStatus
will update to ApplicationException
(4), the actual exception will be written to the MVS Server logs.
-
The PLC sets the desired
MessageID
value, which corresponds to a MessageKey in the PLC Push Message configuration and confirms the MVS Server has read the value by waiting forMessageID_ECHO
to properly echo the value. -
The PLC sets
SendMessage
bit high. This signal can be set low once theSendMessage_ECHO
value echos correctly. -
The MVS Software will validate the
MessageID
and connected camera clients. - If there are no connected camera clients the
MessageStatus
will update toNoAvailableClients
(3) and abort the sequence. - If there the
MessageID
is not configured in the system, theMessageStatus
will update toMessageNotFound
(2) and abort the sequence. - If the
MessageID
is valid and there is at least one camera client connected, theMessageStatus
will update toWaiting
(1) and the sequence will continue. If at any point prior to returning a result all clients registered to this PLC Instance disconnect from the server theMessageStatus
will update toNoAvailableClients
(3) and abort the sequence. - The MVS Software will send the message to the camera client and remain in the
Waiting
(1) status until a user submits a response. - The response will be written to the PLC:
- If the user pressed a affirmative response option (Yes,Ok,Accept,Continue, etc) the
MessageStatus
will update toAffirmativeResponse
(5). - If the user pressed a negative response option (Cancel,No,Reject,Abort,etc) the
MessageStatus
will update toNegativeResponse
(6). - If the message requested a custom input (text/password/number), the result of the entry will be written to the
MessageResult
field and theMessageStatus
will be set toAffirmativeResponse
(5).