Equipment
v6
To work in SyrveFront, various equipment is often used, starting from order editing and ending with payment. The types of equipment used can vary widely: fiscal registrars, printers, scales, cash drawers, customer screens, etc.
In versions prior to 6.2, the system could only work with certain models of equipment. Typically, these were the most common models of equipment. With the help of the API, support for fiscal registrars and scales of any model can be implemented.
Fiscal Registrar
In the API, fiscal registrars are represented by the ICashRegister type, which contains only the device identifier and its name.
For the most part, ICashRegister represents a set of commands, such as opening/closing a cash shift, payment/refund of an order, depositing/withdrawing cash, etc.
The set of commands is predefined, and the internal implementation will depend on the specific device.
Most often, the commands of the fiscal registrar return the current state in the form of a CashRegisterResult object, which contains information about cash counters, document numbers, tax amounts, etc.
Each fiscal registrar has its own settings, represented by the CashRegisterSettings type.
In the BackOffice interface, when adding or reconfiguring a device, these settings can be viewed and their values set.
CashRegisterSettings includes the following information:
- The name of the fiscal registrar model, for example, “MStar-TK. Protocol AFP” (
Code). - The version of the fiscal data format (
OfdProtocolVersion). - The tax rate table (
FiscalRegisterTaxItems). - The payment type table — defined by type (
FiscalRegisterPaymentTypes). - The number of characters in one line of a receipt printed in standard font (
Font0Width). - A list of settings (
DeviceSetting) — this is an arbitrary set of settings, additional to the above-described set. For example, this can include COM port, TCP/IP address, baud rate, access password, etc.
The connection scheme for equipment to SyrveFront is the same for all types of equipment.
To start using your model of fiscal registrar, it needs to be registered in the equipment list.
To do this, you need to create a class that implements ICashRegisterFactory, which will represent the new model of the fiscal registrar, and add the new model to the equipment list using the RegisterCashRegisterFactory() method.
In ICashRegisterFactory, the name of the equipment model and its settings are specified. Thus, in Syrve Office, the fiscal registrar can be found by the model name, and its settings can be created or edited.
An example of a plugin implementing integration with a fiscal registrar can be found in the project Resto.Front.Api.SampleCashRegisterPlugin.
Scales
In the API, scales are represented by the IScale type. Like any device, scales contain the device identifier and its name. The IScale type consists of one command - weigh (MeasureWeight()).
The result of weighing is an object of type ScaleWeightResult, which includes the weight in kilograms (Weight).
To start using your model of scales, it needs to be registered in the equipment list. To register a model, you need to create a type IScaleFactory, which will represent the new model of scales, and add it to the equipment list using RegisterScaleFactory().
In IScaleFactory, the name of the equipment model and its settings are specified. Thus, in BackOffice, the scales can be found by the model name, and their settings can be created or edited.
An example of a plugin implementing integration with scales can be found in the project Resto.Front.Api.SampleScalePlugin.
Automatic Device Startup
SyrveFront can automatically start devices. If a device is not started, any command execution on it, except for starting, will fail. To avoid manually starting the device through BackOffice (“Equipment Settings”) or SyrveFront (“Tools” -> “Equipment Settings”), you can use the method described below.
In the device settings in BackOffice, check the box “Start automatically.” In the target methods (for example, DoCheque, OpenSession for the fiscal registrar), add a check for the device state and throw an exception DeviceNotStartedException:
private void CheckStarted()
{
if (state != State.Running)
throw new DeviceNotStartedException("Device not started");
}
When such an exception occurs, SyrveFront will attempt to start the device and then execute the target command.