Package: rpi2casterd
rpi2casterdHardware driver and web API for rpi2casterThis is a machine control daemon for therpi2castertypesetting and casting software.
It is supposed to run on a Raspberry Pi (any model) with an output expander based on two
MCP23017 chips to provide 32 additional outputs. These are connected to solenoid valves,
which in turn send the pneumatic signals to a Monotype composition caster or tape punch.The program usesFlaskto provide a rudimentary JSON API for caster control.gpiozerolibrary is used for GPIO control, with RPi.GPIO as a preferable backend.There are several available MCP23017 control backends:SMBus (viasmbus-cffiorsmbus2package),WiringPilibrary.The daemon also controls several GPIO pins:ready LED (green)- when lit, the control device and software is ready to use.working LED (green)anderror LED (red), typically a dual-color common cathode LED, indicates the machine state -
green when the machine is working, red when the machine is stopping the pump, and orange when the machine is starting.motor startandmotor stop- pulse outputs for start/stop relays, connected with the original AllenWest motor starter
(their use is optional, more of a convenience).airandwater- for controlling air solenoid valve (prevents unnecessary air use when the machine is not working)
and cooling water valve/pump (ditto with water). Like motor control, this is more of a ‘deluxe’ feature and is not
necessary for caster operation.sensor(photocell, e.g. TCST2103) input for getting the information about the machine cycle phase. When the sensor is
going ON, the air is fed into the machine; when the sensor is going OFF, the air is cut off and the control daemon
ends the signals sending sequence. This sensor is necessary for caster operation. Punching is timer-driven
and no sensor is needed.mode senseinput - when grounded, the interface works in the casting mode; when lifted (pulled up to 3V3),
the interface works in the punching mode. This input is typically connected with a 9-pin D-sub connector for the sensor,
with a jumper to the ground in the plug.shutdownandreboot buttons- after one of these is held for 2 seconds, the LED flashes and the shutdown or reboot
procedure begins.emergency stop button- stops the machine as soon as possible and marks the emergency stop as activated; when that happens,
the client software has to clear the emergency stop first in order to be able to use the machine.The program usesFlaskto provide a rudimentary JSON API for caster control.StartingThe interface needs to be started up in order to work. The startup procedure ensures that:the interface is not busy, not stopping and not starting - has not been claimed by any other client,air and (for casting only) water and motor is turned on, if the hardware supports this,(for casting) the machine is actually turning; during this phase, the state LED lights up orange,after the starting sequence is successfully finished, the state LED lights up green,the interface will stay busy until released by thestopmethod.Machine is started with a request from the client software. See the API section for details.StoppingStopping the interface ensures that:if the pump is working, it is stopped (see the pump control section); during this phase the state LED lights up red,air and (for casting) water and motor is turned off, if hardware supports this,the state  LED is turned off, if hardware supports this,thetesting_modeflag is set to False,the interface is released for the future clients to claim.Machine is stopped when called by the client software, when the machine has been stalling (waiting for the signal
from the cycle sensor for too long), or when emergency stop happens because of button press or client software request.Pump controlThe software turns the pump on (sendingNKS 0075+ current 0075 justifying wedge position) or off.
Pump switch-off is done whenever the machine stops and the pump is marked as working. This ensures that after re-start,
the pump will stay stopped.During the pump switch-off procedure, an “alarm” LED (red) is lit to prompt the operator to turh the
machine’s main shaft a few times. The interface will then send aNJS 0005+ current 0005 justifying wedge position.
This way, stopping the pump does not change the wedge position.Motor controlWhen starting in the casting mode, the software activates themotor_startGPIO for a fraction of a second.
The GPIO can be coupled with a NO SPST relay connected with the original AllenWest electromagnetic starter.
Use a relay rated for at least 400V AC if your caster is wired for three-phase power (common in continental Europe).
The relay should be connected to the contacts marked “1” and “2” on the motor starter.Similarly, when stopping in the casting mode, the software activates themotor_stopGPIO. This can be coupled
with a NC SPST relay that breaks the current flow through the starter’s coil. The relay should be connected instead
of a jumper between one of the live wires and the contact marked as “2”.Air and water controlThe daemon can also control a solenoid valve to enable or disable air flow when the machine is working or stopped.
Air control works in all operation modes (casting, punching and testing).Water control can be used in the casting mode for controlling a pump or solenoid valve for cooling water flow.Sending signalsBased on the caster’s current operation mode, signals are modified or not:testing mode ensures that signals 1…14, A…N, 0075, S, 0005, O15 are sent to the machine as they are receivedpunching mode ensures that a combined signal O+15 is present only when less than 2 signals are receivedcasting mode ensures that the O15 signal is ommittedSending the signals can take place only when the interface has been previously started and claimed as busy;
otherwise,InterfaceNotStartedis raised in the casting mode, and the startup is done automatically
in the punching and testing modes.The daemon behaves differently depending on the operation mode:castingwait for a machine cycle sensor to turn ON,activate the valves for specified signals,wait until the cycle sensor goes OFF,turn all the valves off,check the pump state and justifying wedge positions, and update the current state,return a reply to the request, allowing the client to cast the next combination.However, a machine sometimes stops during casting (e.g. when the operator sees a lead squirt
and has to stop immediately to prevent damage). In case of emergency stop, the machine is stopped immediately
and the client software gets an error reply to the send request.punchingThis mode is fully automatic and driven by a configureble timer:turn the valves on,wait time_on for punches to go up,turn the valves off,wait time_off for punches to come back down,check the pump state and justifying wedge positions, and update the current state,return a success reply to the request.testingThe software just turns off the valves, then turns them on, sending the specified signal combination.REST API documentationThe API is typically accessed athttp://[address]:[port](typically23017, as in MCP23017).
Several endpoints are available:/- status:GET: reads andPOSTchanges the status, which is used mostly for setting the temporarytesting_modeflag./config- configuration:GETreads andPOSTchanges the configuration/machine- machine start/stop/state:GETreads the state,PUTturns the machine on,DELETEturns the machine off, andPOSTturns it on or off
depending on the JSON data in the request ({state: true}for starting,{state: false}for stopping).
The reply can either be{success: true, active: [true/false]}if successful, or{success: false, error_code: [EC], error_name: [EN]}if exception was raised. Error codes and names:0: The machine was abnormally stopped.in case of emergency stop or machine stalling,3: This interface was started and is already in use. If this is not the case, restart the interface.if the interface has already
been claimed as busy,/motor,/air,/water,/pump,valves- motor, air, water, pump and solenoid valves checking/control. The verbs work as above./emergency_stop:GETgets the current state,PUT(orPOSTwith{state: true}JSON data) activates the emergency stop,DELETE(orPOSTwith{state: false}JSON data) clears the emergency stop state, allowing the machine to start.
When emergency stop is activated, the server replies with{success: false, error_code: 0, message: 'The machine was abnormallystopped.'}/signals:GET: gets the last signals sent (unless the machine was stopped, which clears the signals),POSTorPUTwith{signals: [sig1,sig2...],timeout: x}(timeout is optional and overrides the default machine stalling timeout)
sends the specified signals, andDELETEturns off the valves. Emergency stop events are tracked and whenever the emergency stop was triggered,
the server will reply with an error message.Possible error replies:0: The machine was abnormally stopped.in case of emergency stop or machine stalling,4: Trying to cast or punch with an interface that is not started.(only in casting mode, as punching/testing starts the interface automatically)