İçeriğe geç
İletişim Başlayın

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.

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_VAR

The 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 fieldWhat to enter
KindPERIPHERAL_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
Paththe device node: /dev/ttyUSB0, /dev/input/event3. A keyboard device may leave it empty and be found by its ids instead
VendorId ProductIdkeyboard devices: the USB ids lsusb reports, as numbers (16#1EAB)
Baudrateserial only: 4800, 9600, 19200, 38400, 57600 or 115200. Any other value opens the port at 9600
TerminatorTERM_CR, TERM_LF or TERM_CRLF, whichever ends one reading. Serial only; a keyboard device sends ENTER

The control answers on the same variable:

FieldMeaning
Openedthe device is open and being read
Errorit could not be opened
ErrorIdwhy: 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.

FieldWhat it carries
Scanner.Textthe reading, exactly as the device sent it
Scanner.Validrises 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.

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.

OutputMeaning
Busythe request is being served
Activethe control has taken the request
Donethe program is in front of the channel. Selecting is not starting: the cycle still needs its own Cycle Start
Errorthe request was refused
Resultwhich refusal, as E_ProgramSelectResult
ErrorIDthe 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.

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.

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.

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:

ResultShown asMeaning
PSR_NO_MATCHno program carries this namean everyday event, not a fault: a label from another line
PSR_AMBIGUOUS_PROGRAMseveral programs carry this nametwo entries share it, so the control refuses to choose
PSR_CHANNEL_BUSYthe channel is running a programa cycle is running or held on the channel
PSR_NO_INTERPRETERthe channel has no interpreterthe channel cannot take a program
PSR_BUFFER_UNAVAILABLEthe command buffer is unavailablethe channel cannot take a command
PSR_LOAD_FAILEDthe control could not load the programthe file was found and refused
PSR_NOT_SERVEDthe 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.