Detailed Description
To further illustrate the technical means and effects of the present invention adopted to achieve the predetermined objects, the following detailed description will be made on the specific implementation and effects of a communication system between a host computer and a PLC according to the present invention with reference to the accompanying drawings and preferred embodiments.
Before discussing exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart may describe the steps as a sequential process, many of the steps can be performed in parallel, concurrently or simultaneously. A process may be terminated when its operations are completed, but may have additional steps not included in the figure. A process may correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.
The embodiment of the invention provides a communication system of an upper computer and a PLC (programmable logic controller), which comprises the upper computer, at least one PLC, a processor and a memory stored with a computer program, wherein the upper computer can be an industrial personal computer, and the processor and the memory can be directly arranged in the upper computer or independently arranged in other servers. The upper computer is at least connected with one PLC, at least one data interaction channel is arranged in the PLC, each data interaction channel corresponds to a preset data interaction operation, each PLC can execute the data interaction operations of a plurality of data interaction channels in parallel, and each data interaction channel can only process one data interaction operation at the same time. The data interaction channel is provided with a corresponding first signal interaction point M1, a corresponding second signal interaction point M2 and at least one data interaction point, wherein M1, M2 and each data interaction point correspond to an address in the PLC, the state value of M1 is 0 or 1, the state value of M2 is 0 or 1, the data interaction points are used for storing target data of data interaction operation, and it can be understood that the number of the data interaction points corresponding to each data interaction channel is not less than the maximum data amount required by the data interaction operation type corresponding to the data channel. The PLC is configured to allow read-write operation to the M1 of the data interaction channel and read-only operation to the M2 of the data interaction channel; the upper computer is configured to allow read-write operation on M2 and read-only operation on M1. The processor, when executing the computer program, implements the steps of:
and S100, monitoring the state value of M1M2 corresponding to the data interaction channel in real time by the PLC and the upper computer, changing the corresponding M1 value or M2 value based on the data interaction operation process, and finishing the data interaction operation of the PLC and the upper computer.
The communication system of the embodiment of the invention sets the corresponding data interaction channel for each type of data interaction operation, each data interaction channel only executes one data interaction operation each time, so that the mutual influence between different data interaction operations is avoided, the whole data interaction process is monitored based on the state values of M1M2 of two information interaction points of each data interaction channel, the validity and the accuracy of data in the communication process are ensured, and the reliability of the communication between an upper computer and a PLC (programmable logic controller) is improved.
The following detailed description is made of the communication process between the upper computer and the PLC according to two embodiments:
the first embodiment,
In a scene that the PLC acquires target data from the upper computer, the step S100 includes:
step S1, a data interaction channel of the PLC receives a first data interaction request sent by an external device connected with the PLC, whether the state value of M1M2 corresponding to the data interaction channel is 00 or not is judged, if yes, M1 of the data interaction channel is changed into 1, and a first target data acquisition request is sent to an upper computer;
it is understood that the external device may be an electrical device on a specific production line, for example, an electrical device on a vehicle production line, and the specific first target data is also determined according to the electrical device, for example, the first target data may be vehicle assembly parameter information corresponding to a vehicle model id.
S2, the upper computer monitors that the state value of M1M2 of the data interaction channel changes from 00 to 10, acquires first target data from an upper computer database based on a received first target data acquisition request, writes the first target data into the data interaction channel data point, and after the writing is finished, the upper computer changes M2 of the data interaction channel into 1;
step S3, the PLC monitors that the state value of the M1M2 of the data interaction channel is changed from 10 to 11, acquires the first target data from the data points of the data interaction channel and sends the first target data to external equipment, or controls the external equipment to execute corresponding actions according to the first target data and changes the M1 state of the data interaction channel to 0;
and S4, when the upper computer monitors that the state value of the M1M2 of the data interaction channel is changed from 11 to 01, changing the M2 of the data interaction channel to 0, and clearing data in data points of the data interaction channel for data interaction operation of the data interaction channel.
It can be understood that, for a scenario where the uploading of the next first data interaction request is not strictly limited in the same first data interaction operation time period, in the current first data interaction operation process, if the next first data interaction request is acquired, the processing may be resumed when the state value of M1M2 corresponding to the data interaction channel becomes 00, as an embodiment, in the step S1, when the state value of M1M2 corresponding to the data interaction channel is not 00, an alarm operation is directly performed or the following operations are performed: and placing the received first data interaction request in a PLC request queue corresponding to the data interaction channel, and sequentially executing the first data interaction request in the PLC request queue corresponding to the data interaction channel when the state value of M1M2 corresponding to the data interaction channel is changed to 00. It can be understood that, for a scenario that a next first data interaction request is not allowed to be uploaded within the same first data interaction operation time period, in the current first data interaction operation process, when a next first data interaction request is acquired, a corresponding alarm is performed, so that the effectiveness and reliability of acquiring the first target data can be improved.
In order to improve the accuracy of obtaining the target data, as an embodiment, the PLC is further provided with a first data detection mechanism corresponding to each data interaction channel, and when the PLC monitors that the state value of M1M2 of the data interaction channel changes from 10 to 11, the step S3 further includes:
and step S31, the PLC detects the first target data in the data points of the data interaction channel according to a first data detection mechanism corresponding to the data interaction channel, and if the detection is passed, the PLC acquires the first target data from the data points of the data interaction channel and sends the first target data to external equipment, or controls the external equipment to execute corresponding actions according to the first target data, so that the M1 state of the data interaction channel is changed into 0, otherwise, the PLC maintains the state value 11 of the M1M2 of the data interaction channel unchanged.
As an embodiment, the step S100 further includes:
and step S5, when the state value of the M1M2 of the data interaction channel maintains 01, 11 or 10 and exceeds a preset first time threshold value, performing alarm operation.
It is understood that the state value of M1M2 of the data interaction channel may be maintained at 01, 11 or 10 when various abnormal conditions such as device failure, signal failure, data acquisition error and the like occur. And the PLC still can save the current data after power failure, and when the fault is eliminated, the data interaction process can still be continuously executed based on historical operation. The first time threshold may be set according to a time required for normal processing of the corresponding data interaction channel.
Example II,
The PLC is further configured to acquire the connected device state data, store the device state data in a preset data buffer area in the PLC, or store the device state data in a data point of a data interaction channel corresponding to the device state data in real time, and it can be understood that, for a scene where the device state data needs to be accurately acquired in real time, the device state data needs to be directly stored in the data point of the data interaction channel. For application scenarios only used for data backup and the like, the real-time requirement on the device state data is not high, and the device state data can be stored in a data cache region and acquired by an upper computer at intervals. In a scene that the upper computer acquires target data from the PLC, the step S100 includes:
s10, the upper computer sends a second data interaction request to a data interaction channel of the PLC, judges whether the state value of M1M2 corresponding to the data interaction channel is 00, if yes, the upper computer changes M2 of the data interaction channel into 1, sends a second target data acquisition request to the PLC, and then executes the step S20 or the step S30;
step S20, the PLC monitors that the state value of M1M2 of the data interaction channel changes from 00 to 01, based on the received second target data acquisition request, the PLC acquires second target data from the data buffer area and writes the second target data into the data point of the data interaction channel, after the writing is finished, the PLC changes M1 of the data interaction channel into 1, and step S40 is executed;
step S30, the PLC monitors that the state value of the M1M2 of the data interaction channel changes from 00 to 01, judges whether the second target data in the data points of the data interaction channel are completely acquired based on the received second target data acquisition request, if the second target data are completely acquired, the PLC changes the M1 of the data interaction channel to 1, and executes step S40;
s40, the upper computer monitors that the state value of M1M2 of the data interaction channel changes from 01 to 11, obtains second target data from data points of the data interaction channel and stores the second target data in an upper computer database, and then changes the M2 state to 0;
and S50, when the PLC monitors that the state value of the M1M2 of the data interaction channel is changed from 11 to 10, changing the M1 of the data interaction channel to 0, and clearing data in data points of the data interaction channel.
It can be understood that, for a scenario where the uploading of the next second data interaction request is not strictly limited in the same second data interaction operation time period, in the current second data interaction operation process, if the next second data interaction request is acquired, the processing may be resumed after the state value of M1M2 corresponding to the data interaction channel becomes 00, as an embodiment, in the step S10, when the state value of M1M2 corresponding to the data interaction channel is not 00, an alarm operation is directly performed or the following operations are performed: and placing the received second data interaction request in an upper computer request queue corresponding to the data interaction channel, and sequentially executing the second data interaction request in the upper computer request queue corresponding to the data interaction channel when the state value of M1M2 corresponding to the data interaction channel is changed into 00. It can be understood that, for a scenario that a next second data interaction request is not allowed to be uploaded within the same second data interaction operation time period, in the current second data interaction operation process, when a next second data interaction request is acquired, a corresponding alarm is performed, so that the effectiveness and reliability of acquiring the second target data can be improved.
In order to improve the accuracy of obtaining the target data, as an embodiment, a second data detection mechanism corresponding to each data interaction channel is further disposed in the upper computer, and when the upper computer monitors that the state value of M1M2 of the data interaction channel changes from 01 to 11, the step S40 further includes:
and S401, the upper computer detects the second target data in the data interaction channel data points according to a second data detection mechanism corresponding to the data interaction channel, if the second target data pass the detection, the second target data are acquired from the data points of the data interaction channel and stored in an upper computer database, the M2 state of the data interaction channel is changed into 0, and if the second target data pass the detection, the state value 11 of the M1M2 of the data interaction channel is maintained unchanged.
As an embodiment, the step S100 further includes:
and step S60, when the state value of the M1M2 of the data interaction channel maintains 01, 11 or 10 and exceeds a preset second time threshold, performing alarm operation.
It is understood that the state value of M1M2 of the data interaction channel may be maintained at 01, 11 or 10 when various abnormal conditions such as device failure, signal failure, data acquisition error and the like occur. And the PLC still can save the current data after power failure, and when the fault is eliminated, the data interaction process can still be continuously executed based on historical operation. The second time threshold may be set according to a time required for normal processing of the corresponding data interaction channel.
The communication system of the upper computer and the PLC provided by the embodiment of the invention can be applied to communication scenes of a plurality of PLCs and the upper computer, and the application scene of the general assembly line target information acquisition system is taken as an example for further explanation. The embodiment of the invention also provides a general assembly line target information acquisition system, which comprises an upper computer, a PLC, a target information acquisition device, a first information detector and a second information detector, wherein the upper computer is in communication connection with the PLC, the first information detector and the second information detector, and the PLC is connected with the target information acquisition device. The height from the ground to the installation position of the target information collector is a first height h1, the first height h1 is stored in the upper computer and is used for scanning a target information code, as an example, the target information collector can be a code scanner, and the target information code is a bar code, a two-dimensional code and the like. The target information code is installed on a preset installation position of the object to be assembled, and it can be understood that the target information code needs to be installed on a plane of the object to be assembled parallel to the ground and does not block the position of the target information collector. And when the object to be assembled runs to a preset target position, the target information code is positioned in the scanning range of the target information collector. The upper computer further comprises a processor and a memory storing a computer program, and when the processor executes the computer program, the following steps are realized:
step C1, when the first information detector detects that the object to be assembled moves to the target position along a preset track, sending in-place information to the upper computer;
the first information detector can be an in-place switch, the in-place switch is triggered when the object to be assembled moves to the target position along a preset track, and the in-place switch sends in-place information to the upper computer.
Step C2, the upper computer controls the second information detector to acquire a second height h2 from the ground of a target information code of the object to be assembled and sends the second height h2 to the upper computer;
after the upper computer receives the in-place information sent by the in-place switch, the upper computer controls the second information detector to measure a second height h2 of the target information code from the ground, and as an example, the second information detector can specifically adopt a photoelectric sensor. It can be understood that the second height of the target information code from the ground can be measured by directly measuring the second height of the plane where the target information code installation area is located from the ground.
Step C3, the upper computer determines the target focal length h3 of the target information collector from the target information code of the object to be assembled based on h1 and h 2: h3= h 1-h 2;
it can be understood that h3 is the best focal length for the target information collector to scan the target information code corresponding to the current object to be assembled.
Step C4, the PLC communicates with the upper computer to obtain h3, controls the target information collector to adjust the focal length to h3, scans the target information code to obtain target information, and stores the target information in the PLC;
the target information can be quickly and accurately acquired by directly acquiring the optimal focal length of the target information code corresponding to the current object to be assembled scanned by the target information acquisition device and adjusting the focal length to h3 by the target information acquisition device, so that the efficiency and accuracy of acquiring the target information are improved.
And step C5, the upper computer communicates with the PLC to acquire the target information of the object to be assembled.
According to the embodiment of the invention, the general assembly line target information acquisition system is set up, so that when each object to be assembled enters the general assembly line, the target information code can be automatically placed in the scanning range of the target information acquisition device, and the general assembly line target information can be quickly and accurately acquired by the target information acquisition device.
As an embodiment, when the processor executes the computer program, the following steps are also implemented:
step C10, acquiring a cone angle of a formed viewing cone of the target information collector, a maximum value h2max of the height of the target information code from the ground, and a maximum radial distance Lmax of a preset installation position on a plane parallel to the ground, wherein the formed viewing cone of the target information collector is conical;
step C20, cone angle of formed view cone based on the target information collector
Determining the value range of h1 according to the maximum value h2max of the distance between the target information code and the ground height and the maximum radial distance Lmax of the preset installation position on a plane parallel to the ground:
it can be understood that the range of h1 obtained in the steps C10-C20 can ensure that the target information collector can quickly and accurately collect the target information of objects to be assembled of different models.
As an embodiment, the assembly line target information collecting system may be specifically disposed on a vehicle assembly line, and correspondingly, the object to be assembled is a vehicle frame, as shown in fig. 3, and the target information is a vehicle type id. It should be noted that the target information needs to be installed on a plane, which is convenient for the target information collector to collect the target information, and the target information codes generally need to be manually pasted, so as to be a preferred embodiment, the preset installation position is a vehicle front windshield base area, as shown in fig. 3.
As an embodiment, the upper computer includes a MES System (Manufacturing Execution System), and the step C5 is followed by further including:
and step C6, the upper computer acquires assembly information corresponding to the vehicle type from the MES system based on the target information and adds the assembly information into a production queue. And assembling the subsequent assembly based on the assembling information corresponding to the target information.
By adopting the communication system of the upper computer and the PLC, the step C4 specifically comprises the following steps:
step C41, a data interaction channel of the PLC receives a target focal length interaction request sent by a target information collector, whether the state value of M1M2 corresponding to the data interaction channel is 00 or not is judged, if yes, M1 of the data interaction channel is changed into 1, and a target focal length acquisition request is sent to an upper computer;
step C42, the upper computer monitors that the state value of M1M2 of the data interaction channel changes from 00 to 10, based on the received target focal length obtaining request, h3 is obtained from a database, h3 is written into the data point of the data interaction channel, and after the writing is finished, the upper computer changes M2 of the data interaction channel into 1;
step C43, the PLC monitors that the state value of the M1M2 of the data interaction channel is changed from 10 to 11, acquires h3 from the data point of the data interaction channel, controls the target information collector to scan a target information code according to the h3 to acquire target information, and changes the M1 state of the data interaction channel to 0;
and step C44, when the upper computer monitors that the state value of the M1M2 of the data interaction channel is changed from 11 to 01, changing the M2 of the data interaction channel to 0, and clearing data in data points of the data interaction channel.
The step C4 further includes a step C45, when the state value of M1M2 of the data interaction channel maintains 01, 11 or 10 and exceeds a preset first time threshold, or when the state value of M1M2 corresponding to the data interaction channel in the step C41 is not 00, performing an alarm operation.
Based on the communication system between the upper computer and the PLC according to the embodiment of the present invention, the PLC stores the acquired target information in a data cache area preset in the PLC, or stores the acquired target information in a data point of a data interaction channel corresponding to the target information in real time, where the step C5 includes:
step C51, the upper computer sends a target information interaction request to a data interaction channel of the PLC, judges whether the state value of M1M2 corresponding to the data interaction channel is 00, if yes, the upper computer changes M2 of the data interaction channel into 1, and executes step C52 or step C53;
step C52, the PLC monitors that the state value of M1M2 of the data interaction channel changes from 00 to 01, based on the received target information acquisition request, the PLC acquires target information from the data cache region and writes the target information into the data point of the data interaction channel, after the writing is finished, the PLC changes M1 of the data interaction channel into 1, and step C54 is executed;
step C53, the PLC monitors that the state value of the M1M2 of the data interaction channel is changed from 00 to 01, judges whether the target information in the data point of the data interaction channel is completely acquired or not based on the received target information acquisition request, if the target information is completely acquired, the PLC changes the M1 of the data interaction channel to 1, and executes step C54;
step C54, the upper computer monitors that the state value of M1M2 of the data interaction channel changes from 01 to 11, the target information is obtained from the data points of the data interaction channel and stored in an upper computer database, and then the M2 state is changed to 0;
and step C55, when the PLC monitors that the state value of the M1M2 of the data interaction channel is changed from 11 to 10, changing the M1 of the data interaction channel to 0, and clearing data in data points of the data interaction channel.
Wherein the step C5 further comprises:
and step C56, when the state value of the M1M2 of the data interaction channel maintains 01, 11 or 10 and exceeds a preset second time threshold, or when the state value of the M1M2 corresponding to the data interaction channel is not 00 in the step C51, performing alarm operation.
It should be noted that other exception handling in steps C4 and C5 can be handled by using the processing details of the communication system between the upper computer and the PLC according to the embodiment of the present invention, and will not be described again here.
Although the present invention has been described with reference to a preferred embodiment, it should be understood that various changes, substitutions and alterations can be made herein without departing from the spirit and scope of the invention as defined by the appended claims.