Drugstore Control System Design and Realization Based on Programmable Logic Controller (PLC)

This paper proposes an intelligent storage and automatic drug delivery system based on PLC. This system can be applied to dispensing work for all type of medicines. Firstly, the essentials of intelligent control system are discussed and then overall scheme of the system design is presented. Secondly, introduction to the software and hardware design of control system, including the selection of PLC and motion control system are described. Lastly, by analysis of E-R diagram, the date is established and communication protocol between systems is customized. This paper also gives the implementations of the multi-threaded system and communication method.


Introduction
Population growth has boosted the pharmaceutical market and it will continue to maintain the growth for a period of time in the future [1].The traditional pharmaceutical dispensary has been unable to meet the growing medical needs of the people.Under the strong support of the government policy, the automatic transformation of traditional pharmacies is the inclination of times; the new type of intelligent pharmacy system will continue to promote the development of the pharmaceutical industry.Since 1990s, the study of pharmacy automation started and developed a variety of automated hospital pharmacy applications to enhance the level of pharmacy management [2,3].The system is composed of host and lower computer control systems.It will analyze the requirement of lower computer control system and gives the design scheme of hardware and software.According to the data flow of host computer software management system, each function module is compiled and the whole system is assembled and linked to the main system [4,5].Firstly, from the analysis of control object, we selected the appropriate hardware design and controller model.Then allocated the PLC input / output resources and programmed them to monitor the state change of each sensor.Secondly, according to PC software requirements, the automatic pharmacy management system is divided into different modules.In accordance with the specification of database design flow it establishes the data dictionary suitable for pharmacy management system.To customize the communication protocol between each subsystem we used multi thread technology to design and implement the client side of host computer management system.Lastly, each module of the lower computer control system is tested separately and after setting up the software testing environment, the function test of host computer management system is completed.

A. System Architecture
The rotary container is arranged in layers, each layer is driven by an independent step system, and each layer has a plurality of containers.When an item needs to be accessed, the step system drives the container chain so that the container to be accessed runs in a certain order to the port, by the manual completion of access operations.The structure of revolving container is shown in figure 1.Because the container used for small package access for traditional medicine, so the container volume will not be too large, in each layer of the sorting operation does not need to lift with manual operation, the rotating container is discussed in this paper adopts the three layer structure of artificial can be completed in three operations between the upper and lower layer goods outlet.Each layer has a series of container chains; each chain consists of 50 containers and the container size is equal.
Step system can drive container chain to complete the positive and negative action, whenever you need to pick the container to the port, there is a corresponding mechanism prompts the personnel selection to operate.

B. Work Flow
In the automated pharmacy system, the main task of the machine control system is to receive the host computer instruction and complete self-test, medicine, tonic etc...According to the function, the lower computer control system mainly has the self-inspection process, the electric motor search process and the drug delivery process, the specific flow chart shown in Figure 2 Fig. 2 drug delivery processe

Hardware Design
According to analysis of demand results, host computer control system should realize the function of drug control, medicine and drug export control function.The whole hardware system is made by the controller, power supply, proximity switch, screen, driver, motor and encoder, touch screen and other components, the system hardware block diagram as shown in Figure 3 Fig. 3 Hardware system overall block diagram Among them, the controller is a core part of hardware system; it receives electrical signals from other hardware devices and drives the implementation of action.Proximity switches are respectively arranged on the top of cabinet and medicine taking port, and the bottom end is used to detect taking medicine platform position; the screen is provided in medicine fetching opening position to prevent arm injury in drug motion platform, to enhance the security system; touch screen and status lights are placed on the top of medicine taking plat form to display the running state of lower computer in real-time.Hardware design is a foundation of the system, and system needs to complete the set of functions and needs to have a stable and reliable software program.The lower computer control system based on PLC software program, which is responsible for the lower computer system control, data acquisition, data processing, logic operation and status display, output signal, motor control, a parameter storage, assumed the inter task and main control system, touch screen.PLC program is mainly divided into three modules: serial communication module, system self-test module and treatment module.One of function block model is shown in Figure 4, according to the input parameters the function block execute different programs

Software Design
From the logical structure, the relationship model is a collection of multiple relational patterns, and E-R diagram is composed of three elements, which are entity, entity attribute and entity.Therefore, we only need to convert the three elements of E-R graph into relational schema, and then determine the attribute and code of the relational model, and then we can get the relation model of E-R diagram.For example, the prescription entity can be converted into a relational model, the prescription ID as a recipe for the relationship between the codes, marked with underline.The properties of prescription relationships are as follows: Prescription (prescription ID, patient name, sex, patient age, physician's name, list of drugs, prescription amount).The list of drugs in prescription management is an m:n link.It can be transformed into an independent relational model; you can get the properties of the drug as follows: Drug (drug ID, drug name, drug bar code, drug specifications, name of producer) other conversions are similar.

Results and Discussion
The software management system of upper computer and the lower computer control system are all tested, and then the system will be combined to carry out the final system alignment.The overall test results of the host computer part of the main control system as an example to illustrate, figure 6 for the overall test of the main control system running state: As can be seen from the figure, each button and text color and status are displayed normal, the test edit box constraints are also in line with the set requirements, the form of response is in timely response.We can see the system is running, status display normal, electrical cabinet and touch screen operation in good condition; medicine taking platform accurately parked in the vicinity of medicine, the design of the whole control system to achieve the desired requirements   Fig. 6 Running state of the main control system

Conclusion
Based on the background of the modernization of pharmacy, design a pharmacy automation control system based on PLC, this system is suitable for Chinese herbal medicine and Western medicine package boxed medicine work, completed the work mainly includes the following several aspects: From the working process, the automatic pharmacy control system needs analysis, and gives the overall design of the system software and hardware design, the system has been designed to generate a data dictionary.Each module of the lower computer control system is tested separately, and the function of each module of the host computer is built.On this basis, the whole system is tested, and the control system can run normally and efficiently.

Fig. 5
Fig. 5 Prescription management basic E-R chart

Table
Table of contents of the whole test