External Program Selection
Bu içerik henüz dilinizde mevcut değil.
A part arrives at the machine with a label on it. Instead of scrolling the program list and reading a number off a traveller, the operator scans the label and the matching program is selected.
The chain has two halves. The control reads the device and hands the reading, as the device sent it, to the machine’s PLC program. The machine’s program decides what the reading means and asks the control for the program it names. Which part of a label is the program name, whether a checksum has to hold, what to do with the rest: all of that is written in the machine’s program.
Declaring the reader
Section titled “Declaring the reader”A reader on the control’s own port is declared in the machine’s PLC program. Declare a
variable of type ST_PeripheralReader (System library) in any GVL, give it
its configuration, and set Connect:
VAR_GLOBAL Scanner : ST_PeripheralReader := (Connect := TRUE, Cfg := (Kind := PERIPHERAL_SERIAL, Path := '/dev/ttyUSB0'));END_VARThe control finds every variable of this type when the PLC is loaded, opens the device
while Connect is TRUE, closes it when Connect drops, and reopens it when Cfg
changes. Two readers are two variables. A device that is unplugged and plugged back in is
opened again on its own.
Cfg field | What to enter |
|---|---|
Kind | PERIPHERAL_SERIAL for a device on a serial line, PERIPHERAL_HID_KEYBOARD for a scanner that presents itself as a keyboard and types what it reads |
Path | the device node: /dev/ttyUSB0, /dev/input/event3. A keyboard device may leave it empty and be found by its ids instead |
VendorId ProductId | keyboard devices: the USB ids lsusb reports, as numbers (16#1EAB) |
Baudrate | serial only: 4800, 9600, 19200, 38400, 57600 or 115200. Any other value opens the port at 9600 |
Terminator | TERM_CR, TERM_LF or TERM_CRLF, whichever ends one reading. Serial only; a keyboard device sends ENTER |
The control answers on the same variable:
| Field | Meaning |
|---|---|
Opened | the device is open and being read |
Error | it could not be opened |
ErrorId | why: no matching device node, the node could not be opened, exclusive access was refused, or readers are not available on this platform |
A device that will not open also says so in the panel’s Messages, as External reader <name> not started: followed by the reason. Exclusive access
matters for a keyboard device: shared with the panel it would type its readings into
whatever field has focus, so the control refuses to read it at all.
Where a reading arrives
Section titled “Where a reading arrives”| Field | What it carries |
|---|---|
Scanner.Text | the reading, exactly as the device sent it |
Scanner.Valid | rises after Text is written |
Text is written before Valid rises, so a program that acts on Valid never reads half
a label. Clear Valid when you have taken the reading. A reading that arrives before you
clear it replaces the one standing, which is what a reader means by scanning twice.
A reading longer than Text can hold is not delivered: Text keeps what it had and
Valid does not rise.
Asking for a program
Section titled “Asking for a program”The machine asks the way it asks the control for anything else: with a channel function
block. MC_ProgramSelect, in the Motion_Channel library, takes the name and raises the
request; the control looks the name up in the program catalogue, loads the match, and
answers on the block’s own outputs.
| Output | Meaning |
|---|---|
Busy | the request is being served |
Active | the control has taken the request |
Done | the program is in front of the channel. Selecting is not starting: the cycle still needs its own Cycle Start |
Error | the request was refused |
Result | which refusal, as E_ProgramSelectResult |
ErrorID | the channel’s own error code. When the channel itself failed, Result stays PSR_NONE and this is where the reason is |
Done rises only when the kernel has actually loaded the program, not when the request was
accepted. A name that matches nothing, a name two programs share, a channel that is running
a program, a file the kernel cannot parse: each comes back as Error with its reason in
Result. A refusal is also shown in Messages on the panel; a selection that went
through is not.
When the machine should not change programs, a pallet mid-swap or a job it has not
finished, hold Execute low until it may.
The lines that ask
Section titled “The lines that ask”Whatever the shop’s rule is, the shape is the same. Take the reading, clear Valid so the
next scan is not confused with this one, and pulse Execute:
VAR fbSelect : MC_ProgramSelect; bSelect : BOOL;END_VAR
IF Scanner.Valid AND NOT fbSelect.Busy THEN fbSelect.ProgramName := Scanner.Text; (* or the shop's rule on it *) bSelect := TRUE; Scanner.Valid := FALSE;END_IF;
fbSelect(Channel := GVL_Channel.Channel1, Execute := bSelect);
IF fbSelect.Done OR fbSelect.Error THEN bSelect := FALSE;END_IF;A label that is nothing but the program name needs the block exactly as written. One that
carries a serial, a batch or an order number beside it puts the shop’s rule where the
comment is, with the string functions the compiler provides: LEN, LEFT, RIGHT, MID,
FIND, DELETE, REPLACE, CONCAT. Nothing about that rule reaches the control.
Keep one consumer of a device’s Valid. Two programs reading the same scan means whichever
runs first takes it, and the other sees nothing.
The same block serves a machine with no reader at all. An identifier off a fieldbus, a pallet code, or a host system reaches it the same way.
What the name has to be
Section titled “What the name has to be”The name asked for is the name the program is listed under on the panel: the name in the program list, which is also the name you gave it. A program posted from CAM is selected exactly like one written on the panel.
The comparison is forgiving where a label reasonably differs from a list entry, and strict where guessing would be wrong:
- upper and lower case do not decide a match, and blanks around the name are ignored
- the file extension may be on the label, on the stored name, or on neither
- if two programs are listed under one name, the request is refused rather than resolved to one of them. Rename one of them and ask again.
Selecting is not starting
Section titled “Selecting is not starting”A selection loads the program and stops there. Cycle start is still a separate action, and the PLC still decides whether that start is permitted. A label passing in front of a scanner cannot put the machine in motion.
A refused request is shown in the panel’s Messages as External read <label> not selected: followed by the reason. Result on the block carries the same reason:
Result | Shown as | Meaning |
|---|---|---|
PSR_NO_MATCH | no program carries this name | an everyday event, not a fault: a label from another line |
PSR_AMBIGUOUS_PROGRAM | several programs carry this name | two entries share it, so the control refuses to choose |
PSR_CHANNEL_BUSY | the channel is running a program | a cycle is running or held on the channel |
PSR_NO_INTERPRETER | the channel has no interpreter | the channel cannot take a program |
PSR_BUFFER_UNAVAILABLE | the command buffer is unavailable | the channel cannot take a command |
PSR_LOAD_FAILED | the control could not load the program | the file was found and refused |
PSR_NOT_SERVED | the program catalogue did not answer the machine in time. The block reports Error rather than waiting |
On a machine with several channels, a request that names none is shown as the device names no channel and the block sees PSR_NOT_SERVED.
Where to go next
Section titled “Where to go next”- Selecting & Loading a Program: selecting by hand on the panel.
- Cycle Programming: authoring a program a scan can then select.