PLC communication method, device, equipment and storage medium
The proposed PLC communication method simplifies the programming language conversion between the PLC device and the host computer, solves the difficult and time-consuming problems in the existing technology, and improves the user experience and communication efficiency.
Patent Information
- Application Number
- CN202410765285.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-06-14
AI Technical Summary
Existing PLC communication methods are difficult to understand, time-consuming, and have poor user experience. Users need to have an in-depth understanding of the communication protocols of different devices to achieve effective communication between host computer instructions and PLC devices.
A PLC communication method is proposed. By detecting that the preset communication conditions are met, the target communication message sent by the host computer is obtained, the message is parsed to obtain the target PLC code, and the code is converted based on the preset coding rules to generate the target instruction set and send it to the PLC. Devices that simplify conversion between programming languages.
It reduces the difficulty of PLC communication and improves user experience, eliminating the need for users to have an in-depth understanding of the communication protocols of each device to achieve fast and efficient communication.
Smart Images

Figure CN118353973B
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic communication technology, and in particular to a PLC communication method, device, equipment and storage medium. Background Art
[0002] PLC devices have been widely used in the industrial field. Users can perform logic programming through the host computer and then control the operation of the PLC device through programming instructions.
[0003] However, the instructions written by the user in the host computer and the machine code that the PLC device can recognize and understand do not belong to the same programming language. The two need to be converted in order for the PLC to complete the functions that the programming instructions need to achieve. However, different devices correspond to different communication protocols, and users need to have a better understanding of the communication protocols of the devices in order to effectively realize the conversion between the programming instructions of the host computer and the machine language recognizable by the PLC device and realize the communication between the two. Therefore, the existing PLC communication method is difficult to understand, time-consuming, and has a poor user experience.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide a PLC communication method, device, equipment and storage medium, aiming to solve the technical problems that the existing PLC communication method is difficult to understand, time-consuming and has a poor user experience.
[0006] To achieve the above purpose, the present application proposes a PLC communication method, which includes:
[0007] When it is detected that the preset communication conditions are met, the target communication message sent by the host computer is obtained;
[0008] Parsing the target communication message to obtain the target PLC code;
[0009] The target PLC code is converted based on a preset coding rule to obtain a target instruction set, and the target instruction set is sent to a target PLC device.
[0010] In one embodiment, the step of converting the target PLC code based on a preset coding rule to obtain a target instruction set, and sending the target instruction set to a target PLC device includes:
[0011] Performing a match detection on a preset code set and the target PLC code;
[0012] The target PLC code is converted based on a preset coding rule corresponding to the matching detection result.
[0013] In one embodiment, the preset encoding set includes basic instruction encoding; the preset encoding rules include basic encoding rules;
[0014] The step of converting the target PLC code based on the preset coding rule corresponding to the matching detection result includes:
[0015] If the matching detection result is that the target PLC code has a first code that matches the basic instruction code, the first code is converted according to the basic coding rule corresponding to the basic instruction code.
[0016] In one embodiment, the step of converting the first code according to the basic coding rule corresponding to the basic instruction code includes:
[0017] Obtaining a target register type corresponding to the first encoding;
[0018] The first encoding is converted according to the target register type and the basic encoding rule.
[0019] In one embodiment, the preset coding set includes extended instruction coding; the preset coding rule includes extended coding rule;
[0020] The step of converting the target PLC code based on the preset coding rule corresponding to the matching detection result includes:
[0021] If the matching detection result is that there is a second code matching the extended instruction code in the target PLC code, the second code is converted according to the extended coding rule corresponding to the extended instruction code.
[0022] In one embodiment, the step of converting the second code according to the extended coding rule corresponding to the extended instruction code includes:
[0023] Traversing the second code to obtain matching instructions contained in the second code;
[0024] Determine a target instruction corresponding to the second code according to the matching instruction;
[0025] The second encoding is converted based on an extended encoding rule corresponding to the target instruction.
[0026] In one embodiment, the step of converting the second encoding based on the extended encoding rule corresponding to the target instruction includes:
[0027] Obtaining target parameter information corresponding to the target instruction;
[0028] The second code is converted according to the extended coding rule corresponding to the target parameter information.
[0029] In addition, to achieve the above purpose, the present application also proposes a PLC communication device, the PLC communication device comprising:
[0030] The message acquisition module is used to acquire the target communication message sent by the host computer when it is detected that the preset communication conditions are met;
[0031] A parsing module, used for parsing the target communication message to obtain a target PLC code;
[0032] The encoding conversion module is used to perform encoding conversion on the target PLC encoding based on a preset encoding rule, obtain a target instruction set, and send the target instruction set to a target PLC device.
[0033] In addition, to achieve the above objectives, the present application also proposes a PLC communication device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the PLC communication method as described above.
[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the PLC communication method as described above are implemented.
[0035] The present application provides a PLC communication method, device, equipment and storage medium, the method comprising: when it is detected that the preset communication conditions are met, obtaining the target communication message sent by the host computer; parsing the target communication message to obtain the target instruction set; encoding and converting the target instruction set based on the preset encoding rules to obtain the target PLC code, and sending the target PLC code to the target PLC device. Compared with the existing communication methods, the present application can parse the communication message transmitted by the host computer to obtain the target PLC code, and then directly map and convert the target PLC code according to the pre-configured preset encoding rules, and finally realize the communication between the PLC device and the host computer based on the target instruction set obtained after the conversion, thereby reducing the communication difficulty and improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0038] Figure 1 This is a first flow chart of the first embodiment of the PLC communication method of the present application;
[0039] Figure 2 This is a second flow chart of the first embodiment of the PLC communication method of the present application;
[0040] Figure 3 This is a schematic diagram of the first encoding conversion process of the first embodiment of the PLC communication method of the present application;
[0041] Figure 4 This is a first flow chart of the second embodiment of the PLC communication method of the present application;
[0042] Figure 5 This is a second flow chart of the second embodiment of the PLC communication method of the present application;
[0043] Figure 6 This is a schematic diagram of the first process of second code matching detection of the second embodiment of the PLC communication method of the present application;
[0044] Figure 7 This is a third flow chart of the second embodiment of the PLC communication method of the present application;
[0045] Figure 8 This is a schematic diagram of the second process of the second encoding matching detection of the second embodiment of the PLC communication method of the present application;
[0046] Fig. 9 This is a schematic diagram of the third process of second code matching detection of the second embodiment of the PLC communication method of the present application;
[0047] Fig.10 This is a structural block diagram of an embodiment of a PLC communication device of the present application;
[0048] Fig.11 Schematic diagram of the device structure of the hardware operating environment involved in the PLC communication method in the embodiment of the present application.
[0049] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0050] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0051] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0052] The main solution of this application is to propose a new PLC coding rule, and then based on the new PLC coding rule, the conversion between the host computer operation instructions and the PLC device machine language can be easily and quickly realized, thereby reducing the difficulty of PLC communication and improving user experience.
[0053] Specifically, in the new PLC coding rules proposed in this application, the operation instructions of the host computer can correspond to two bytes (0x0000~0xFFFF) of PLC machine language. Therefore, in theory, the solution proposed in this application can recognize up to 65535 operation instructions, which can meet all PLC application scenarios; the parameters in the operation instructions support registers with bit type parameters such as X, Y, M, T, C, D, and integer or long integer type parameter registers such as D, C, V, Z, R; the parameters in the operation instructions can correspond to one or more registers, or a combination of one or more registers of different types; the operation instructions can be classified into basic instructions and application instructions according to their purpose and usage scenarios. Among them, the basic instructions LD, LDI, AND, ANI, OR, ORI, OUT, SET, RST are the core of PLC, mainly used for logic control, and can be directly mapped to PLC coding.
[0054] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, etc., or a PLC communication device (referred to as a communication device) capable of realizing the above functions, and this embodiment does not specifically limit this. The following takes the communication device as the execution subject as an example to illustrate this embodiment and the following embodiments.
[0055] Based on this, the embodiment of the present application provides a PLC communication method, referring to Figure 1 , Figure 1 This is a first flow chart of the first embodiment of the PLC communication method of the present application.
[0056] In this embodiment, the PLC communication method includes steps S10 to S30:
[0057] Step S10, when it is detected that the preset communication condition is met, the target communication message sent by the host computer is obtained;
[0058] Step S20, parsing the target communication message to obtain the target PLC code;
[0059] Step S30, converting the target PLC code based on a preset coding rule to obtain a target instruction set, and sending the target instruction set to a target PLC device.
[0060] It is easy to understand that the above-mentioned host computer can be a device loaded with configuration software corresponding to the target PLC device, and the user can generate programming instructions through logic programming in the host computer through various types of code languages such as ladder diagrams, STL languages, and C languages, so as to control the PLC device based on the programming instructions. The host computer and the target PLC device can communicate and transmit based on the serial port. Therefore, in this embodiment, the communication device can obtain the PLC code in the machine language format about the operation status of the target PLC device based on the target communication message sent by the host computer, that is, the above-mentioned target PLC code.
[0061] It should be understood that the above preset communication conditions can indicate that the hardware configuration and software initialization of the PLC device are complete. When the communication device detects that the preset communication conditions are met, it means that the serial port communication between the target PLC device and the host computer is successfully established. Among them, hardware configuration can refer to the completion of PLC I / O port configuration, the lighting of the PLC operation indicator light, etc.; software initialization can refer to setting program addresses, RTC initialization, PLC data area initialization, CAN initialization, ADC input initialization, DAC output initialization, PWM initialization, pulse coding initialization, interrupt initialization, PLC power-off data recovery, serial port initialization and BSP initialization, etc.
[0062] It is understandable that the target communication message may include fields such as start character, slave station address, command code, data, check code and end character, and the target PLC code may be stored in the data field of the target communication message. Therefore, the communication device may parse the target communication message based on the communication message format to obtain the target PLC code.
[0063] Among them, the above-mentioned preset coding rules can be code coding rules set by the test personnel in advance based on the operation instructions and the PLC device machine language. In the preset coding rules, the operation instructions can be converted into two bytes (0x0000~0xFFFF) of PLC machine language, so theoretically the communication device can recognize up to 65535 PLC codes based on the preset coding rules, which can meet all the application scenarios of existing PLC applications. Among them, the parameters in the operation instructions can support registers of bit type parameters such as X, Y, M, T, C, D, and integer or long integer type parameter registers such as D, C, V, Z, R; the parameters in the operation instructions can correspond to one or more registers, or a combination of one or more registers of different types.
[0064] It is understandable that after the preset coding rules are set in advance, the communication device can first obtain the target PLC code in the PLC machine language format transmitted by the host computer through the communication message, and then directly perform code mapping conversion on the target PLC code based on the preset coding rules to obtain the operation instructions that can control the operation of the target PLC device, that is, the target instruction set. Then the communication device can determine the target PLC device to be controlled based on the slave address in the target communication message, and send the target instruction set to the target PLC device, thereby realizing the operation control of the target PLC device based on the target PLC code.
[0065] To sum up, compared with the existing communication methods, this embodiment can parse the communication message transmitted by the host computer to obtain the target PLC code, and then directly map and convert the target PLC code according to the pre-configured preset coding rules, and finally realize the communication between the PLC device and the host computer based on the target instruction set obtained after the conversion, thereby reducing the communication difficulty and improving the user experience.
[0066] As an implementable method, refer to Figure 2 , Figure 2 This is a second flow chart of the first embodiment of the PLC communication method of the present application. In this embodiment, step S30 includes: steps A1-A2:
[0067] Step A1, performing a match detection between a preset code set and the target PLC code;
[0068] Step A2: converting the target PLC code based on a preset coding rule corresponding to the matching detection result.
[0069] It should be noted that the codes in the above-mentioned preset code set can also be encoded using two bytes, so that all PLC application scenarios can be satisfied. In this embodiment, the preset coding rule can be a coding rule for classification mapping based on different types of codes. Therefore, the communication device can directly traverse and match the target PLC code based on the preset code set, and determine which type of code in the preset code set matches the target PLC code, obtain the matching detection result, and then perform mapping code conversion on the target instruction set based on the preset coding rule corresponding to the matching detection result.
[0070] It is understandable that the operation instructions of the target PLC device can be classified into basic instructions and application instructions according to the purpose and usage scenario. As an implementable method, in this embodiment, the preset coding set includes basic instruction coding; the preset coding rules include basic coding rules; step A2 includes:
[0071] Step A21: If the matching detection result is that the target PLC code has a first code that matches the basic instruction code, the first code is converted according to the basic coding rule corresponding to the basic instruction code.
[0072] It is easy to understand that the basic instruction codes in the preset code set can be converted into LD, LDI, AND, ANI, OR, ORI, OUT and SET as the basic instructions of the PLC communication core, which are mainly used for logic control. In this embodiment, it can be directly mapped and converted with the PLC code 0x2000 ~ 0xCFFF. Specifically, as an implementable method, in this embodiment, step A2 includes: Steps B1~B2:
[0073] Step B1, obtaining a target register type corresponding to the first code;
[0074] Step B2: converting the first encoding according to the target register type and the basic encoding rule.
[0075] It should be understood that, although the parameters in the PLC encoding in this embodiment can support registers of bit type parameters such as X, Y, M, T, C, D, and integer or long integer type parameter registers such as D, C, V, Z, R, etc., the types of registers that can be converted to different types of basic instructions are not the same. For example, in this embodiment, the basic instructions LD, LDI, AND, ANI, OR, ORI can correspond to conversion registers S, X, Y, T, M, and C; the basic instruction OUT can correspond to conversion registers S, Y, T, and M.
[0076] Therefore, in this embodiment, the register type that the corresponding basic instruction in the first encoding can convert, that is, the above-mentioned target register type, can be determined first, and then the first encoding is converted in sequence based on the determined target register type. At the same time, in this embodiment, each of the above-mentioned basic instructions has corresponding encoding rules for different registers, that is, the above-mentioned basic encoding rules.
[0077] For example, in this embodiment, when it is detected that the first code contains the code corresponding to the basic instruction LD, that is, 0x2xxx, the first code can be converted according to the basic coding rules shown in the following Table 1. Taking the PLC code 0x20xx~0x23xx as an example, the communication device can map and convert it into the operation instructions of the S register S0~S1023 according to the basic coding rules.
[0078] Table 1
[0079]
[0080] For ease of understanding, Figure 3Take this as an example to illustrate: Figure 3 This is a schematic diagram of the first encoding conversion process of the first embodiment of the PLC communication method of the present application, as shown in FIG. Figure 3 As shown, when it is detected that there is a first code that matches the code 0x2xxx and / or 0xCxxx in the target PLC code, this embodiment can determine that the first code contains the PLC code corresponding to the basic instruction LD and / or OUT, and determine that the target register type to be converted corresponding to the LD instruction is S, X, Y, T, M and C; the target register type to be converted corresponding to the OUT instruction is S, Y, T and M, and then the communication device can Figure 2 The process sequentially discriminates and converts the first code.
[0081] In summary, this embodiment can directly map and convert the first code included in the target PLC code into basic instructions based on the basic coding rules and register types, thereby achieving simple and efficient code conversion.
[0082] The present embodiment provides a PLC communication method, which includes: when it is detected that the preset communication conditions are met, obtaining the target communication message sent by the host computer; parsing the target communication message to obtain the target PLC code; matching detection of the preset code set and the target PLC code; the preset code set includes the basic instruction code; the preset coding rule includes the basic coding rule; if the matching detection result is that the target PLC code has a first code that matches the basic instruction code, then obtaining the target register type corresponding to the first code; encoding conversion of the first code according to the target register type and the basic coding rule, obtaining the target instruction set, and sending the target instruction set to the target PLC device. Compared with the existing communication method, the present embodiment can parse the target communication message transmitted by the host computer to obtain the target PLC code, and then directly map and convert the target PLC code according to the pre-configured preset coding rule to obtain the target instruction set for controlling the operation of the target PLC, thereby reducing the difficulty of PLC communication and improving the user experience. At the same time, the present embodiment can directly map the code conversion of the basic instructions transmitted by the host computer based on the basic coding rules and the register type, thereby realizing simple and efficient code conversion.
[0083] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction and will not be repeated later.
[0084] On this basis, please refer to Figure 4 , Figure 4 This is a first flow chart of the second embodiment of the PLC communication method of the present application. In this embodiment, the preset coding set includes an extended instruction coding; the preset coding rule includes an extended coding rule; and step A2 further includes:
[0085] Step A22: If the matching detection result is that there is a second code in the target PLC code that matches the extended instruction code, the second code is converted according to the extended coding rule corresponding to the extended instruction code.
[0086] It is easy to understand that the above-mentioned extended instruction codes in the preset code set can include application instructions such as MOV, ZCP, MTR, PID, and basic instructions RST. This embodiment can directly map them to PLC codes 0x0000 ~ 0x0FFF according to certain rules. Theoretically, 4096 application instructions can be recognized, which can fully meet the current and future extended instruction uses required by all PLC programming. Specifically, in this embodiment, the extended instruction code + variable (1 or more) can form an extended application instruction of a complete PLC instruction and parameter.
[0087] Therefore, if the communication device detects that there is a second code matching the extended instruction code in the target PLC code, the second code included in the target PLC code can be converted according to the extended coding rule corresponding to the extended instruction code. Figure 5 , Figure 5 This is a second flow chart of the second embodiment of the PLC communication method of the present application, step A22 includes steps C1 to C3:
[0088] Step C1, traverse the second code to obtain the matching instruction contained in the second code;
[0089] Step C2, determining a target instruction corresponding to the second code according to the matching instruction;
[0090] Step C3, performing encoding conversion on the second encoding based on the extended encoding rule corresponding to the target instruction.
[0091] It is understandable that, as described above, in this embodiment, the extended instruction encoding may include the basic instruction RST and multiple application instructions, namely the target instruction, and the extended encoding rules may also perform different mapping conversions based on different instruction types. Therefore, in this embodiment, the second encoding may be traversed again to detect the target instruction therein, and the second encoding may be converted based on the extended encoding rules corresponding to the target instruction.
[0092] Specifically, in this embodiment, different target instructions may also correspond to different matching instructions, and the matching instruction may be a PLC code with a fixed value, which can be used to quickly match the target instruction in the traversal process of the second code, and determine the target instruction in the second code based on the matching result, and then determine the corresponding coding processing process. Figure 6 Take this as an example to illustrate: Figure 6This is a schematic diagram of the first process of the second encoding matching detection of the second embodiment of the PLC communication method of the present application, as shown in FIG. Figure 6 As shown, the matching code 0x0026 can correspond to the ZCP interval comparison instruction; the PLC matching code 0x0028 can correspond to the MOV movement instruction; 0x01d3 corresponds to the double word LD greater than or equal to instruction; the matching code 0x00C0 corresponds to the PID instruction processing instruction, etc. Figure 6 In addition to the content shown in, the matching code 0x0078 may correspond to the MTR matrix input instruction; the matching code 0x0054 may correspond to the bit right shift SFTR instruction; the matching code 0x0056 may correspond to the bit left shift SFTL instruction; the matching code 0x0058 may correspond to the word right shift SFTL instruction; 0x005A may correspond to the word left shift SFTL instruction; and 0x0096 may correspond to the RAMP instruction. Therefore, this embodiment may quickly determine the encoding process corresponding to the second encoding based on the matching code, and then perform encoding conversion based on the encoding rule corresponding to the encoding process.
[0093] As an implementation method, in this embodiment, refer to Figure 7 , Figure 7 This is a third flow chart of the second embodiment of the PLC communication method of the present application, step C3 includes steps C31-C32:
[0094] Step C31, obtaining target parameter information corresponding to the target instruction;
[0095] Step C32: performing code conversion on the second code according to the extended coding rule corresponding to the target parameter information.
[0096] It should be understood that the parameters of each target instruction in the extended instruction encoding may correspond to one or more registers, or may correspond to a combination of one or more registers of different types. Therefore, in this embodiment, the parameter type to be processed corresponding to the target instruction, i.e., the above-mentioned target parameter information, may be first obtained, and then the target instruction may be sequentially converted into code based on the determined target parameter information.
[0097] In the extended coding rules proposed in this embodiment, the extended instruction coding defined by the extended instruction type may include: extended instruction code (2 bytes) + variable (1 or more, consisting of type + number), thereby forming an extended application instruction of a complete PLC instruction and parameter. Among them, the variable (register) type and variable (register) number type in the parameter can be identified using a 4-byte and 8-byte combination. Therefore, the variable type of this embodiment may include 4-byte parameters, 8-byte parameters, and combined parameters. For ease of understanding, Figure 8 Take the example to illustrate the matching conversion process based on parameter information. Figure 8 This is a schematic diagram of the second process of the second encoding matching detection of the second embodiment of the PLC communication method of the present application, as shown in FIG. Figure 8 As shown, if the communication device is based on Figure 6 The method shown in the figure, after determining that the target instruction is a MOV move instruction by matching instruction 0x0028, can be further based on the parameter type, such as Figure 8 The second encoding is converted in sequence using the 4-byte parameters, 8-byte parameters and combined parameters.
[0098] It should be understood that in the above extended encoding rules, the encoding rules corresponding to different parameter types can be as follows:
[0099] 1) 4-byte parameter: The variable in the extended instruction adopts 4-byte single variable definition and value encoding. The 4-byte variable address format can be expressed as: (AA00+xx)_(BB00+yy). AABB can be combined with a high 16-bit data, which is composed of the first and third bytes to define the variable (register) type; xxyy can be combined with a low 16-bit data, which is composed of the second byte + the fourth byte to define the variable (register) number or constant value. The specific details are as follows:
[0100] Constant K (decimal): AA=80, BB=80, xxyy=register number;
[0101] Constant H (hexadecimal): AA=80, BB=82, xxyy=register number;
[0102] T register: AA=82, BB=86, xx=01; xxyy=register number*2;
[0103] D register: AA=86, BB=86, xxyy=register number*2; D maximum value <11999;
[0104] C register: AA=84, BB=86, xxyy=register number*2;
[0105] X register: AA=80, BB=84, xx=04, yy=register number;
[0106] Y register: AA=80, BB=84, xx=05, yy=register number;
[0107] M register: AA=80, BB=84, xxyy=set value; (M0-1535: set value = register number + 0x0800; M1536-4095: set value = register number + 0x0A00).
[0108] 2) 8-byte parameters: The register type and number in the extended instruction are encoded in 8 bytes, including the encoding of the variable definition and value. The address format is: AA00+xx+CC00+yy+8000+zz+8000+nn.
[0109] Among them, AACC: the first byte (AA) + the third byte (CC), constitute the identification variable type;
[0110] Xxyy: The second byte (xx) + the fourth byte (yy) combine to define the variable value;
[0111] 8080: The fifth byte (80) + the seventh byte (80) combination identifies the variable type;
[0112] zznn: The combination of the 6th byte (zz) + the 8th byte (nn) defines the variable value.
[0113] The upper 4 bytes 00800080 represent a double-byte variable; the lower 4 bytes define the register type and register number. The details can be shown as follows:
[0114] Constant K (decimal): AA=80BB=80xxyy=register number;
[0115] Constant H (hexadecimal): AA=80BB=82xxyy=register number;
[0116] T register: AA=82, BB=86, xx=01; xxyy=register number*2;
[0117] D register: AA=86, BB=86, xxyy=register number*2; D maximum value <11999;
[0118] C register: AA=84, BB=86, xxyy=register number*2;
[0119] X register: AA=80, BB=84, xx=04, yy=register number;
[0120] Y register: AA=80, BB=84, xx=05, yy=register number;
[0121] M register: AA=80, BB=84, xxyy=setting value, (M0-1535: setting value = register number + 0x0800; M1536-4095: setting value = register number + 0x0A00)
[0122] 3) Combined parameters: If the extended instructions need to combine the bit register parameters KnY, KnM, KnS, KnT, KnX, the 4-byte variable definition and value encoding can be used, and the format can be: AAxxBByy.
[0123] Among them, the combination parameter type definition: AA=0x80+Kn*2; Kn, n=1~8; BB=84; parameter setting value=xxyy, which can be specifically shown as follows:
[0124] S register: xxyy=register number&0x03FF;
[0125] X register: xxyy = register number & 0x04FF;
[0126] Y register: xxyy=register number & 0x05FF;
[0127] M register: xxyy = register number + 0x0800 (Mx = 0-1535);
[0128] xxyy = register number + 0x0A00 (Mx = 1536-4095).
[0129] It is easy to understand that the extended encoding rules can also perform mapping encoding of the V / Z register variable address (V / Z) variable definition and value, and the combined register variable DxxV / Zn variable format as the above process, which will not be repeated here.
[0130] In the specific implementation, based on the above extended encoding rules, Fig. 9 Take the conversion process of 4-byte variables as an example to illustrate. Fig. 9 This is a schematic diagram of the third process of the second encoding matching detection of the second embodiment of the PLC communication method of the present application, as shown in FIG. Fig. 9 As shown, if the communication device determines that the target parameter information corresponding to the target instruction is a 4-byte parameter, the second encoding can be converted in sequence based on the variable address format corresponding to the 4-byte parameter in the extended encoding rule, that is, (AA00+xx)_(BB00+yy), and the specific mapping conversion rules. The matching process is the same as Figure 8 Similar, no further description is given here.
[0131] To sum up, this embodiment can realize code conversion of different bit registers and different data register types based on extended coding rules, provide an expandable and universally programmable code conversion method, support general PLC devices to provide more than 64,000 external operation instructions, and expand the scope of application of the PLC communication method proposed in this application.
[0132] It is easy to understand that in a specific implementation, if the target PLC code in the PLC machine language format transmitted by the host computer received by the communication device is represented as follows:
[0133] 0175000000070E0024 00C0 0028 02C5 0324 05C8 0F009F;
[0134] Accordingly, the communication device can convert the target instruction set according to the above preset coding rules, which is expressed as follows:
[0135] LD X0;
[0136] OUT S0;
[0137] LD M0;
[0138] OUT Y2;
[0139] LD X3;
[0140] OUT M5.
[0141] In this embodiment, the preset coding set includes an extended instruction coding; the preset coding rules include extended coding rules; if the matching detection result is that there is a second coding matching the extended instruction coding in the target PLC coding, the second coding is traversed to obtain the matching instruction contained in the second coding; the target instruction corresponding to the second coding is determined according to the matching instruction; the target parameter information corresponding to the target instruction is obtained; and the second coding is converted according to the extended coding rules corresponding to the target parameter information. This embodiment can realize code conversion of different bit registers and different data register types based on the extended coding rules, and provide an expandable and universally programmable code conversion method, which can support universal PLC devices to provide external operation instructions exceeding 64000+, and expand the scope of application of the PLC communication method proposed in this application.
[0142] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the PLC communication method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0143] This application also provides a PLC communication device, please refer to Fig.10 , Fig.10 This is a structural block diagram of an embodiment of a PLC communication device of the present application, such as Fig.10 As shown, in this embodiment, the PLC communication device includes:
[0144] The message acquisition module T1 is used to acquire the target communication message sent by the host computer when it is detected that the preset communication conditions are met;
[0145] The parsing module T2 is used to parse the target communication message to obtain the target PLC code;
[0146] The encoding conversion module T3 is used to perform encoding conversion on the target PLC encoding based on a preset encoding rule, obtain a target instruction set, and send the target instruction set to a target PLC device.
[0147] Optionally, the code conversion module T3 is further used to perform a match detection between the preset code set and the target PLC code;
[0148] The encoding conversion module T3 is further used to perform encoding conversion on the target PLC encoding based on a preset encoding rule corresponding to the matching detection result.
[0149] Optionally, the preset coding set includes basic instruction coding; the preset coding rules include basic coding rules; the coding conversion module T3 is also used to convert the first coding according to the basic coding rules corresponding to the basic instruction coding if the matching detection result is that the target PLC coding has a first coding that matches the basic instruction coding.
[0150] Optionally, the encoding conversion module T3 is further used to obtain a target register type corresponding to the first encoding;
[0151] The encoding conversion module T3 is further used to perform encoding conversion on the first encoding according to the target register type and the basic encoding rule.
[0152] Optionally, the encoding conversion module T3 is also used for the preset encoding set including extended instruction encoding; the preset encoding rules include extended encoding rules; the encoding conversion module T3 is also used for, if the matching detection result is that there is a second encoding in the target PLC encoding that matches the extended instruction encoding, then the second encoding is converted according to the extended encoding rule corresponding to the extended instruction encoding.
[0153] Optionally, the encoding conversion module T3 is further used to traverse the second encoding to obtain a matching instruction included in the second encoding;
[0154] The encoding conversion module T3 is further used to determine the target instruction corresponding to the second encoding according to the matching instruction;
[0155] The encoding conversion module T3 is further used to perform encoding conversion on the second encoding based on the extended encoding rule corresponding to the target instruction.
[0156] Optionally, the encoding conversion module T3 is further used to obtain target parameter information corresponding to the target instruction;
[0157] The encoding conversion module T3 is further used to perform encoding conversion on the second encoding according to the extended encoding rule corresponding to the target parameter information.
[0158] The PLC communication device provided by the present application adopts the PLC communication method in the above embodiment, which can solve the technical problems of PLC communication. Compared with the prior art, the beneficial effects of the PLC communication device provided by the present application are the same as the beneficial effects of the PLC communication method provided by the above embodiment, and other technical features in the PLC communication device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0159] The present application provides a PLC communication device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the PLC communication method in the above-mentioned embodiment one.
[0160] Reference below Fig.11 , which shows a schematic diagram of the structure of a PLC communication device suitable for implementing an embodiment of the present application. The PLC communication device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The PLC communication device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0161] like Fig.11As shown, the PLC communication device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the PLC communication device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the PLC communication device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a PLC communication device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided alternatively.
[0162] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0163] The PLC communication device provided by the present application adopts the PLC communication method in the above embodiment to solve the technical problems of PLC communication. Compared with the prior art, the beneficial effects of the PLC communication device provided by the present application are the same as the beneficial effects of the PLC communication method provided by the above embodiment, and other technical features in the PLC communication device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0164] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0165] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0166] The present application provides a storage medium having computer-readable program instructions (ie, computer programs) stored thereon, the computer-readable program instructions being used to execute the PLC communication method in the above-mentioned embodiment.
[0167] The storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: RandomAccess Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0168] The above storage medium may be included in the PLC communication device; or may exist independently without being assembled into the PLC communication device.
[0169] The storage medium carries one or more programs. When the one or more programs are executed by the PLC communication device, the PLC communication device can realize PLC communication between the host computer and the PLC device.
[0170] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0171] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0172] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0173] The readable storage medium provided by the present application is a storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned PLC communication method, and can solve the technical problems of PLC communication. Compared with the prior art, the beneficial effects of the storage medium provided by the present application are the same as the beneficial effects of the PLC communication method provided by the above-mentioned embodiment, and will not be described in detail here.
[0174] The above are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A PLC communication method, characterized in that: The method comprises: When it is detected that the preset communication conditions are met, the target communication message sent by the host computer is obtained; Parsing the target communication message to obtain the target PLC code; Performing encoding conversion on the target PLC encoding based on a preset encoding rule to obtain a target instruction set, and sending the target instruction set to a target PLC device; The step of converting the target PLC code based on a preset coding rule to obtain a target instruction set and sending the target instruction set to a target PLC device comprises: Performing a match detection on a preset code set and the target PLC code; the preset code set includes a basic instruction code and an extended instruction code; Performing encoding conversion on the target PLC encoding based on a preset encoding rule corresponding to the matching detection result; the preset encoding rule includes a basic encoding rule and an extended encoding rule; The step of converting the target PLC code based on the preset coding rule corresponding to the matching detection result includes: If the match detection result is that the target PLC code has a first code that matches the basic instruction code, then obtaining the target register type corresponding to the first code; The first encoding is converted according to the target register type and the basic encoding rule.
2. The PLC communication method according to claim 1, characterized in that: The step of converting the target PLC code based on the preset coding rule corresponding to the matching detection result includes: If the matching detection result is that there is a second code matching the extended instruction code in the target PLC code, the second code is converted according to the extended coding rule corresponding to the extended instruction code.
3. The PLC communication method according to claim 2, characterized in that: The step of converting the second code according to the extended coding rule corresponding to the extended instruction code comprises: Traversing the second code to obtain matching instructions contained in the second code; Determine a target instruction corresponding to the second code according to the matching instruction; The second encoding is converted based on an extended encoding rule corresponding to the target instruction.
4. The PLC communication method according to claim 3, characterized in that: The step of converting the second encoding based on the extended encoding rule corresponding to the target instruction includes: Obtaining target parameter information corresponding to the target instruction; The second code is converted according to the extended coding rule corresponding to the target parameter information.
5. A PLC communication device, characterized in that: The PLC communication device comprises: The message acquisition module is used to acquire the target communication message sent by the host computer when it is detected that the preset communication conditions are met; A parsing module, used for parsing the target communication message to obtain a target PLC code; A code conversion module, used for performing code conversion on the target PLC code based on a preset code rule, obtaining a target instruction set, and sending the target instruction set to a target PLC device; The encoding conversion module is further used to perform matching detection on a preset encoding set and the target PLC encoding; the preset encoding set includes a basic instruction encoding and an extended instruction encoding; the target PLC encoding is encoded based on a preset encoding rule corresponding to the matching detection result; the preset encoding rule includes a basic encoding rule and an extended encoding rule; The encoding conversion module is also used to obtain the target register type corresponding to the first encoding if the matching detection result is that the target PLC encoding has a first encoding that matches the basic instruction encoding; and to perform encoding conversion on the first encoding according to the target register type and the basic encoding rule.
6. A PLC communication device, characterized in that: The device comprises: a memory, a processor and a PLC communication program stored in the memory and executable on the processor, wherein the PLC communication program is configured to implement the steps of the PLC communication method according to any one of claims 1 to 4.
7. A storage medium, characterized in that: The storage medium stores a PLC communication program, which, when executed by the processor, implements the steps of the PLC communication method according to any one of claims 1 to 4.
