Controller with enhanced reliability
09824229 · 2017-11-21
Assignee
Inventors
- Kotaro Okamura (Shiga, JP)
- Yoshihide Nishiyama (Kanagawa, JP)
- Masanori Ota (Shiga, JP)
- Koji Yaoita (Kyoto, JP)
Cpc classification
G06F11/3055
PHYSICS
G06F21/6218
PHYSICS
G06F11/3024
PHYSICS
International classification
G06F7/00
PHYSICS
G05B19/05
PHYSICS
Abstract
A controller with enhanced reliability of access to a database system. A programmable logic controller (PLC) accessible to a database accesses a database (DB) server in response to an event in which a user program calls a DB access processing program. The DB access processing program stores status information indicating a status of accesses to the DB server in a nonvolatile memory, in accordance with an instruction of the user program. When a power interruption occurs, the PLC can obtain a status of accesses to the DB server at the timing of the occurrence of the power interruption by referring to the status information. Then, the PLC, for example, re-sends a structured query language (SQL) sentence, depending on the access status.
Claims
1. A controller comprising: a communication interface configured to connect with a database; a processor; and a memory including instructions that, when executed by the processor, cause the processor to perform operations including: generating a structured query language (SQL) instruction sentence in accordance with an access instruction for accessing the database, the access instruction having a plurality of steps, in response to execution of a user program containing the access instruction, and controlling an access to the database on the basis of the generated instruction sentence, wherein the instruction sentence is stored in a nonvolatile memory until a process based on the instruction sentence is completed; and generating and storing status information that indicates an execution status of the access instruction, from a start of the access instruction to a completion of the access instruction, wherein the status information is obtained at an occurrence of an interrupting event affecting the access to the database, wherein the status information comprises one of five designated statuses including an initial status in which the processor accesses the database, an unsent status in which the processor has not yet sent the SQL instruction sentence to the database, a sending status in which the processor is sending the SQL instruction sentence to the database, a spooling status in which the processor spools the SQL instruction sentence and a spooled SQL instruction sentence is stored in the memory, and a complete status in which the processor completes sending of the SQL instruction sentence to the database, wherein when the interrupting event affecting access to the database occurs during the unsent status, the processor re-sends the SQL instruction sentence to the database; when the interrupting event affecting access to the database occurs during the sending status, the processor re-sends the SQL instruction sentence to the database; when the interrupting event affecting access to the database occurs during the spooling status, the processor sends the spooled SQL instruction sentence to the database; and when the interrupting event affecting access to the database occurs during the complete status, the processor takes no action to re-send the SQL instruction sentence.
2. The controller according to claim 1, wherein the interrupting event affecting access to the database occurs during a period in which an acknowledgement response is being received from the database.
3. The controller according to claim 1, wherein the status information contains information that indicates the sending status of the structured query language (SQL) sentence for accessing the database.
4. The controller according to claim 1, wherein the status information contains information that indicates whether to save the structured query language (SQL) sentence for accessing the database to a storage.
5. The controller according to claim 1, the operations further comprising storing a recovery program that refers to the status information and that recovers a process of the access to the database, depending on an access status indicated by the status information, the recovery program being executed in a predetermined operating status.
6. The controller according to claim 5, wherein the recovery program performs the recovery, depending on a sending status of the structured query language (SQL) sentence that the controller sends to the database.
7. The controller according to claim 1, the operations further comprising: receiving first data from a sensor external to the controller and sending the first data to the database; and receiving second data from a second controller and sending the second data to the database.
8. The controller according to claim 1, wherein the interrupting event comprises a power interruption, and wherein a recovery of the access to the database is based upon a respective one of the five designated statuses.
9. A non-transitory computer readable storage medium that stores a set of executable instructions for controlling an operation of a controller, the executable instructions, when executed by a processor, causing the controller to: generate a structured query language (SQL) instruction sentence in accordance with an access instruction for accessing a database, the access instruction having a plurality of steps, in response to execution of a user program containing the access instruction, and control the access to the database on the basis of the generated instruction sentence, wherein the instruction sentence is stored in a nonvolatile memory until a process based on the instruction sentence is completed; and generate and hold status information that indicates an execution status of the access instruction, from a start of the access instruction to a completion of the access instruction, wherein the status information is obtained in response to an occurrence of an interrupting event affecting the access to the database, wherein the status information comprises one of five designated statuses including an initial status in which the processor accesses the database, an unsent status in which the processor has not yet sent the SQL instruction sentence to the database, a sending status in which the processor is sending the SQL instruction sentence to the database, a spooling status in which the processor spools the SQL instruction sentence and a spooled SQL instruction sentence is stored in memory, and a complete status in which the processor completes sending of the SQL instruction sentence to the database, wherein when the interrupting event affecting access to the database occurs during the unsent status, the processor re-sends the SQL instruction sentence to the database; when the interrupting event affecting access to the database occurs during the sending status, the processor re-sends the SQL instruction sentence to the database; when the interrupting event affecting access to the database occurs during the spooling status, the processor sends the spooled SQL instruction sentence to the database; and when the interrupting event affecting access to the database occurs during the complete status, the processor takes no action to re-send the SQL instruction sentence.
10. The non-transitory computer readable storage medium of claim 9, wherein the interrupting event comprises a power interruption, and wherein a recovery of the access to the database is based upon a respective one of the five designated statuses.
11. The non-transitory computer readable storage medium of claim 9, the executable instructions, when executed by the processor, further causing the controller to: determine whether the interrupting event has occurred during a period in which the structured query language (SQL) sentence is being sent to the database or whether the interrupting event has occurred during the receipt of an acknowledgement response from the database.
12. The non-transitory computer readable storage medium of claim 11, wherein if a determination has been made that the interrupting event has occurred during a period in which the structured query language (SQL) sentence was being sent to the database, the executable instructions, when executed by the processor, further causing the controller to: determine whether a record is present in the database, and if no records are present in the database, instruct that the structured query language (SQL) sentence be resent to the database.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
DETAILED DESCRIPTION
(12) Hereinafter, an embodiment of the present invention will be described with reference to the drawings. In the following description, the same reference characters are assigned to the same constitute elements. Constitute elements having the same reference character have the same name and function. Accordingly, a detailed description about the same reference character will not be repeated.
First Embodiment
(13)
(14) The outline of the embodiment will first be described. Referring to FIG. 1, a control system includes a personal computer (PC) 10, a database (DB) server 20, and programmable logic controllers (PLCs) 30 and 40. The PC 10 is an information processing device by which a user creates a user program that will operate in the PLC 30. The DB server 20 functions as a database management system (DBMS) that manages a database.
(15) The PLC 30 is connected to the PC 10, the DB server 20, and the PLC 40. The PLC 30 holds setting for connecting with the DB server 20, and accesses the DB server 20 in accordance with this setting.
(16) The PLC 30 receives data from the exterior, such as the output from a sensor, and accumulates the data. Then, the PLC 30 sends to the DB server 20 the accumulated data in accordance with a DB access processing program 35 that will be described below. The PLC 30 receives data that another PLC (the PLC 40 in the example of
(17) [Detailed Configurations of Individual Instruments]
(18) Detailed configurations of individual instruments will be described.
(19)
(20) The PC 10 is a computer system (the information processing device) that includes a micro control unit (MCU), a read only memory (ROM), and a random access memory (RAM). Referring to
(21) The instruction execution status obtaining unit 14 is software that instructs the PLC 30 to send to the PC 10 the content of status information 51 held in a memory of the PLC 30.
(22) The programming function 16 is software that supports a user in creating pieces of program. When the pieces of software are executed in the PC 10, the instruction execution status obtaining unit 14, the programming function 16, and the like fulfill their functions.
(23)
(24) The DB server 20 functions as a database management system (DBMS) 22 that manages read and write operations in a database. The DBMS 22 controls read and write operations in a DB 24 that functions as a database. The DB 24 is a storage region that holds a plurality of data records and, for example, holds data under the control of the DBMS 22.
(25)
(26) Referring to
(27) The OS 31 manages the resources of the PLC 30, and allows the PLC 30 to function to, for example, schedule tasks and handle accesses to the DB server 20.
(28) The system program 33 is a software group that provides primary functions of the PLC 30. More specifically, the system program 33 contains a sequence instruction program 34, a DB access processing program 35, an I/O processing program 36, a tool interface processing program 37, and a scheduler 38.
(29) The sequence instruction program 34 allows the PLC 30 to function to sequentially execute instructions in the user program 32 while reading/writing information from or in the memory region in the PLC 30.
(30) The DB access processing program 35 is called in response to the execution of the user program 32 by the PLC 30 in accordance with the sequence instruction program 34. In addition, the DB access processing program 35 allows the PLC 30 to function to perform a process in which the user program 32 accesses the DB server 20, such as a process of generating SQL sentences.
(31) The I/O processing program 36 allows the PLC 30 to function to control data input and output to and from the PLC 30 via the plurality of I/O functions included in the PLC 30. The I/O functions are allocated to addresses of the memory. Data held in the memory regions corresponding to the I/O functions are replaced collectively and periodically by external data. The tool interface processing program 37 receives an instruction reported from the PC 10 to the PLC 30 by the function of the programming tool 12 operating in the PC 10. In response to this instruction, the tool interface processing program 37 allows the PLC 30 to function to pass a process to the DB access processing program 35 or the like and to send to the PC 10 the process result or the like. The scheduler 38 allows the PLC 30 to function to schedule tasks that the PLC 30 will perform, on the basis the priorities of the tasks.
(32) The user program 32 is created by the PC 10 and is held in the memory of the PLC 30. Referring to
(33) The status information 51 is output from the DB access processing program 35, and holds a status in which the DB access processing program 35 accesses the DB server 20. The detail thereof will be described below.
(34)
(35)
(36) [Data]
(37) Data used in this embodiment will be described.
(38)
(39) In this embodiment, when the user program 32 designates the output of an output variable State, the PLC 30 outputs the output variable State from the DB access processing program 35, and holds it in the nonvolatile memory. The status information 51 holds one of five statuses which are indicated by the output variable State that is output from the DB access processing program 35. The output variable State has an enumerated type of data, and its enumerators are as illustrated in
(40) “_DBC_SEND_INIT” (initial status) indicates an initial status in which the DB access processing program 35 accesses the DB server 20.
(41) “_DBC_SEND_UNSENT” (unsent SQL sentence) indicates a (unsent) status in which the DB access processing program 35 has not yet sent to the DB server 20 a SQL sentence. “_DBC_SEND_SENDING” (SQL sentence being sending) indicates a status in which the DB access processing program 35 is sending to the DB server 20 a SQL sentence and has not yet completed it.
“_DBC_SEND_SPOOLED” (spooling of SQL sentence) indicates a status in which the DB access processing program 35 spools a SQL sentence to be sent to the DB server 20 and the SQL sentence is held in the nonvolatile memory.
“_DBC_SEND_COMPLETE” (completion of sending of SQL sentence) indicates a status in which the DB access processing program 35 completes sending of a SQL sentence to the DB server 20.
[Operation]
(42) An operation of the PLC 30 in this embodiment will be described in detail with reference to the drawings. The outline of the operation in the embodiment is as follows. The PC 10 creates a user program 32 to be executed in the PLC 30, in accordance with a user's input operation. The PLC 30 receives the user program 32 from the PC 10, and stores the received user program. The PLC 30 calls the DB access processing program 35 in response to the execution of the user program 32 by the sequence instruction program 34. The PLC 30 performs a process in which the user program 32 accesses the DB server 20, such as a process of generating and sending a SQL sentence, by the DB access processing program 35.
(43)
(44) In Step S11, the PLC 30 reads a value for accessing the DB server 20 (which is a current value of data to be written to the DB server 20 and accumulated in the memory) by the DB access processing program 35. In this case, the output of the output variable State is “_DBC_SEND_UNSENT” indicating that a SQL sentence has not been sent.
(45) In Step S13, the PLC 30 generates a SQL sentence for accessing the DB server 20 by the DB access processing program 35, and sends the SQL sentence to the DB server 20. In this case, the output of the output variable State becomes “_DBC_SEND_SENDING” indicating that a SQL sentence is being sent.
(46) In Step S15, the PLC 30 waits for an Ack response (sent Ack) from the DB server 20, in response to the SQL sentence sent to the DB server 20 by the access processing program 35, until a time-out occurs. In this case, the output of the output variable State is “_DBC_SEND_SENDING” indicating that a SQL sentence is being sent.
(47) In Step S17, the PLC 30 determines whether or not it has received an error during the communication with the DB server 20 by the DB access processing program 35 and/or whether or not the time-out has occurred during the process of receiving the Ack response. In this case, the output of the output variable State is “_DBC_SEND_SENDING” indicating that a SQL sentence is being sent. If the positive determination is made in Step S17, the PLC 30 performs a process of Step S21 by the DB access processing program 35. Otherwise, if the negative determination is made in Step S17, the PLC 30 performs a process of Step S19 by the DB access processing program 35.
(48) In Step S19 (sending of the SQL sentence to the DB server 20 by the DB access processing program 35 has successfully been completed), the PLC 30 outputs a response to the program that has called the DB access processing program 35, by the DB access processing program 35, this response indicating that the access to the DB server 20 has been completed. In this case, the output of the output variable State becomes “_DBC_SEND_COMPLETE” indicating that sending of a SQL sentence has been completed.
(49) In Step S21, the PLC 30 spools, to the nonvolatile memory, the SQL sentence which has not been successfully sent to the DB server 20 by the DB access processing program 35. Until the completion of the spooling, the output of the output variable State has been “_DBC_SEND_SENDING” indicating that a SQL sentence is being sent.
(50) In Step S23, the PLC 30 outputs a response to the program that has called the DB access processing program 35, by DB access processing program 35, this response indicating that the access to the DB server 20 has been completed. In this case, the output of the output variable State becomes “_DBC_SEND_SPOOLED” indicating that a SQL sentence has been spooled.
(51)
(52) (1) Start
(53) A DB instruction 60 contained in the user program 32 calls the DB access processing program 35 in order to access the DB server 20. The DB instruction 60 contains DB_Connect instruction 61 that instructs the connection with the DB server 20, and DB_Insert instruction 62 that inserts data into the DB server 20. In response to the execution of the DB instruction 60 that contains an instruction of outputting an output variable State from the DB access processing program 35, the PLC 30 calls the DB access processing program 35, and starts outputting an output variable State.
(54) (2) Reading of Current Value
(55) The PLC 30 performs the process of Step S11 by the DB access processing program 35.
(56) (3) Sending
(57) The PLC 30 performs the process of Step S13 by the DB access processing program 35.
(58) (4) Sent Ack
(59) The PLC 30 performs the processes of Step S15 and Step S17 by the DB access processing program 35.
(60) (5-1) Occurrence of Failure
(61) (5-2) Occurrence of Time-Out of Instruction
(62) The PLC 30 spools a SQL sentence to a nonvolatile memory 66 by performing the process of Step S21 by the DB access processing program 35.
(63) (6-1) Completion
(64) (6-2) Completion (of Spooling)
(65) The PLC 30 performs the process of Step S19 or Step S23 by the DB access processing program 35.
(66)
(67)
(68) When a power interruption occurs at the timing of “(3) Sending,” “(4) Sent Ack,” “(5-1) Occurrence of failure,” or “(5-2) Occurrence of time-out of instruction,” a SQL sentence has been sent to the DB server 20 by the DB access processing program 35. Therefore, a measure taken against the power interruption is to check whether or not a record is present in the DB server 20, and re-send the SQL sentence to the DB server 20 if no records are created therein.
(69) When a power interruption occurs at the timing of “(6-1) Completion,” the sending of a SQL sentence to the DB server 20 by the DB access processing program 35 has been completed. Therefore, no special measures are required against the power interruption.
(70) When a power interruption occurs at the timing of “(6-2) Completion (of spooling),” a SQL sentence has been spooled. Therefore, a measure taken against the power interruption is to re-send the spooled SQL sentence by the DB access processing program 35.
(71) [Exemplary User Program]
(72) Up to this point, the operation has been described, in which when the PLC 30 accesses the DB server 20 by the DB access processing program 35, the DB access processing program 35 outputs an access status to the status information 51. Next, a description will be given of an exemplary user program for allowing the DB access processing program 35 to output the status information 51, and another exemplary user program for carrying out a recovery even in a case of a power interruption.
(73)
(74) Referring to
(75)
(76) It will be appreciated that the embodiments described above may be carried out in combination. The present invention contemplated by the present inventor has been concretely described based on the embodiments; however, this invention is not limited to these embodiments, and various modifications thereof can be made without departing from the spirit of the invention.
(77) It is understood that the embodiments disclosed herein are exemplary and explanatory in all respects, and are not restrictive. The foregoing description, therefore, is not to be taken in a limiting sense, and the scope of the invention is defined by the appended claims; the meaning of equivalents to the claims and all possible modifications are intended to fall within the scope of the invention.