CN112260914B - Virtual Modbus ID generation method and device and gateway - Google Patents

Virtual Modbus ID generation method and device and gateway Download PDF

Info

Publication number
CN112260914B
CN112260914B CN202010918803.0A CN202010918803A CN112260914B CN 112260914 B CN112260914 B CN 112260914B CN 202010918803 A CN202010918803 A CN 202010918803A CN 112260914 B CN112260914 B CN 112260914B
Authority
CN
China
Prior art keywords
modbus
virtual
equipment
real
serial port
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010918803.0A
Other languages
Chinese (zh)
Other versions
CN112260914A (en
Inventor
张朋飞
周厚明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Maiwei Communications Co ltd
Original Assignee
Wuhan Maiwei Communications Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Maiwei Communications Co ltd filed Critical Wuhan Maiwei Communications Co ltd
Priority to CN202010918803.0A priority Critical patent/CN112260914B/en
Publication of CN112260914A publication Critical patent/CN112260914A/en
Application granted granted Critical
Publication of CN112260914B publication Critical patent/CN112260914B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/40006Architecture of a communication node
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/30Managing network names, e.g. use of aliases or nicknames
    • H04L61/3015Name registration, generation or assignment
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/02Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Small-Scale Networks (AREA)
  • Information Transfer Systems (AREA)

Abstract

The embodiment of the invention provides a method and a device for generating a virtual Modbus ID, wherein components with the same Modbus ID are required to be butted on different RS485 buses of a Modbus gateway; that is, the interface is connected with different physical serial ports; the function of resetting Modbus ID is supported without Modbus slave setting; a virtual Modbus ID conversion algorithm of the Modbus gateway is adopted; virtualizing Modbus RTU equipment positioned on a plurality of Modbus buses into the Modbus RTU equipment positioned on the same virtual Modbus; the Modbus TCP master device cannot sense that the Modbus slave device is connected to different RS485 buses; the Modbus TCP master device considers the slave devices to be on the same Modbus bus.

Description

Virtual Modbus ID generation method and device and gateway
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a virtual Modbus ID generation method and device.
Background
The Modbus protocol is a bus protocol used in industrial fields and is divided into modbusRTU and Modbus ASCII which are applied to serial port (such as RS232 and RS 485) transmission and Modbus TCP which is operated on a TCP/IP network.
modbus is a master-slave protocol in which one side of a master device issues commands to one side of a slave device, and one side of the slave device responds to the commands and replies to the master device, which may have multiple slave devices. Specifically, the staff computer may be considered a master, and the specific device, such as a PLC, is a slave. Each device has its own code, and the master device finds a corresponding device by the code, or a broadcast mode may be used, where the code 0 is a broadcast.
At present, the industry has a lot of bus devices using ModbusRTU and Modbus ASCII, and because the transmission distances of serial port protocols such as RS485/RS232/RS422 and the like are relatively limited, a TCP/IP network is ubiquitous at present; in order to quickly access the serial devices to a TCP/IP network, a Modbus gateway is often used in a factory site, and the Modbus gateway realizes data conversion and transparent transmission between Modbus TCP, modbusRTU and Modbus ASCII;
1) Modbus IDs of commercially available Modbus RTU devices are typically not modifiable, and the Modbus ID of each such device is the same; for example, modbus meters purchased from Taobao, modbus IDs of meters of the same type from the same manufacturer cannot be modified and are the same.
2) The Modbus TCP master device can be a computer generally, and generally, one Modbus TCP master device needs to communicate with a plurality of slave devices at the same time; if a Modbus TCP master device connects and controls a plurality of Modbus RTU slave devices with the same Modbus ID through a Modbus gateway, a method for distinguishing the Modbus RTU slave devices is needed.
Patent document CN105323328A discloses a method for automatically identifying addresses on RS-485 using the Modbus communication protocol. In the method, when a component with the same Modbus ID exists on one bus, the conflict is solved by resetting the Modbus ID; the patent requires that the Modbus slave device must support the reset Modbus ID function; in practice, however, many devices do not support resetting the Modbus ID function.
Disclosure of Invention
The embodiment of the invention provides a virtual Modbus ID generation method and device, and solves the problem that in the prior art, as equipment does not support the function of resetting Modbus ID, when Modbus TCP master equipment connects and controls a plurality of Modbus RTU slave equipment with the same Modbus ID by means of a Modbus gateway, the automatic address identification of a Modbus communication protocol fails.
In a first aspect, an embodiment of the present invention provides a virtual Modbus ID generating method, including:
step 101, distributing a plurality of virtual Modbus IDs to N serial ports of a Modbus gateway;
and 102, acquiring a real device Modbus ID and a physically connected serial port ID of Modbus RTU equipment, physically connecting the Modbus RTU equipment to any serial port, and allocating a unique virtual Modbus ID to the Modbus RTU equipment, wherein the Modbus RTU equipment with the same Modbus ID of the real device is not accessed in the same serial port.
Preferably, in step 102, assigning a unique virtual Modbus ID to the Modbus RTU device includes:
sequencing Modbus RTU equipment added under the same serial port based on the Modbus ID of real equipment to obtain a Modbus ID sequencing serial number of the real equipment of each Modbus RTU equipment;
and carrying out virtual Modbus ID distribution on the Modbus RTU equipment based on the maximum value and the minimum value of the virtual Modbus ID:
Virtual_Modbus_id=min_mod_id+dev_id
or the like, or, alternatively,
Virtual_Modbus_id=max_mod_id-dev_id;
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to the Modbus RTU equipment, max _ mod _ ID is the maximum value of the Virtual Modbus ID, min _ mod _ ID is the minimum value of the Virtual Modbus ID, and dev _ ID is a real equipment Modbus ID sorting serial number of the Modbus RTU equipment.
Preferably, in step 102, assigning a unique virtual Modbus ID to the Modbus RTU device includes:
and carrying out virtual Modbus ID distribution on Modbus RTU equipment added under the same serial port:
Virtual_Modbus_id=com_id*com_modbus_cnt+dev_real_modbus_id%p
h(k)=k%p
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to Modbus RTU equipment, the com _ ID is a physically connected serial port ID, the com _ Modbus _ cnt is the number of the Virtual Modbus IDs available for each serial port, the dev _ real _ Modbus _ ID is a real equipment Modbus ID, h (k) is a hash function, p is the maximum prime number not greater than com _ Modbus _ cnt, and% represents modulo p remainder operation.
Preferably, the method further comprises the following steps:
and when the Modbus RTU equipment is deleted, modifying the real equipment Modbus ID corresponding to the virtual Modbus ID of the Modbus RTU equipment into an illegal value.
Preferably, the method further comprises the following steps:
and newly adding Modbus RTU equipment, finding out the item of which the Modbus ID of the first real equipment is an illegal value, and taking the serial number as the dev _ ID of the newly added Modbus RTU equipment.
Preferably, the method further comprises the following steps:
if the fact that the real equipment Modbus ID corresponding to the Virtual _ Modbus _ ID is not an illegal value is judged and known, the fact that the hash function conflicts is represented;
sequentially searching the item of which the Modbus ID of the first real equipment is an illegal value in a virtual modbusid range corresponding to the serial port, and assuming that the serial number is new _ ID;
the virtual Modbus ID corresponding to the device is:
Virtual_Modbus_id=com_id*com_modbus_cnt+new_id。
in a second aspect, an embodiment of the present invention provides a virtual Modbus ID generating apparatus, including:
the serial port distribution module is used for uniformly distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the virtual Modbus ID generation module acquires a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connects the Modbus RTU equipment to any serial port, and allocates an unique virtual Modbus ID for the Modbus RTU equipment, wherein the Modbus RTU equipment with the same Modbus ID of the real device is not accessed in the same serial port.
In a third aspect, an embodiment of the present invention provides a Modbus gateway, including N serial ports, where each serial port may configure a virtual Modbus ID, and further including:
the serial port distribution module is used for uniformly distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the virtual Modbus ID generation module acquires a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connects the Modbus RTU equipment to any serial port, and allocates an unique virtual Modbus ID for the Modbus RTU equipment, wherein the Modbus RTU equipment with the same Modbus ID of the real device is not accessed in the same serial port.
In a fourth aspect, an embodiment of the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the steps of the virtual Modbus ID generation method according to the first aspect of the present invention.
In a fifth aspect, an embodiment of the present invention provides a non-transitory computer readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of the virtual Modbus ID generation method according to the embodiment of the first aspect of the present invention.
According to the method and the device for generating the virtual Modbus ID, provided by the embodiment of the invention, components with the same Modbus ID are required to be butted on different RS485 buses of a Modbus gateway; that is, the interface is connected with different physical serial ports; the function of resetting Modbus ID is supported without Modbus slave setting; a virtual Modbus ID conversion algorithm of the Modbus gateway is adopted; virtualizing Modbus RTU equipment on a plurality of Modbus buses to be positioned on the same virtual Modbus; the Modbus TCP master device cannot sense that the Modbus slave device is connected to different RS485 buses; the Modbus TCP master device considers the slave devices to be on the same Modbus bus.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a flow chart of a virtual Modbus ID generation method according to an embodiment of the invention;
FIG. 2 is a schematic application diagram of a virtual Modbus ID generation method according to an embodiment of the invention;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first", "second" in the embodiments of the present application are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or as implying any indication of the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the feature. In the description of the present application, the terms "comprise" and "have", as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a system, product or apparatus that comprises a list of elements or components is not limited to only those elements or components but may alternatively include other elements or components not expressly listed or inherent to such product or apparatus. In the description of the present application, "plurality" means at least two, e.g., two, three, etc., unless explicitly specifically limited otherwise.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein may be combined with other embodiments.
Patent document CN105323328A discloses a method for automatically identifying an address on RS-485 using Modbus communication protocol. Because the devices hung on the RS-485 bus only have 1-byte Modbus addresses, and in production, for the convenience of detection or other reasons, the possible addresses of the devices leaving the factory are the same, so that the phenomenon that the Modbus addresses are the same when a user receives the devices is difficult to avoid. During installation, only one byte of the MODBUS address exists, at most 256 addresses can exist, a user is required to check one address by one address, errors cannot occur, and certain difficulty exists. Therefore, the patent document provides a method for automatically detecting devices with the same Modbus address and automatically setting the devices to be different, so as to provide convenience for users and ensure normal communication. The patent requires that the Modbus slave device must support the reset Modbus ID function; in practice, however, many devices do not support resetting the Modbus ID function.
Therefore, the embodiment of the invention provides a method and a device for generating a virtual Modbus ID, wherein components with the same Modbus ID need to be butted on different RS485 buses of a Modbus gateway; that is, the interface is connected with different physical serial ports; the function of resetting Modbus ID is supported without Modbus slave setting; a virtual Modbus ID conversion algorithm of the Modbus gateway is adopted; and virtualizing Modbus RTU equipment on a plurality of Modbus buses to be on the same virtual Modbus bus. The following description and description will proceed with reference being made to various embodiments.
Fig. 1 provides a virtual Modbus ID generating method according to an embodiment of the present invention, where an applied gateway is shown in fig. 2, and the method includes:
step 101, distributing a plurality of virtual Modbus IDs to N serial ports of a Modbus gateway;
and 102, acquiring a real device Modbus ID of the Modbus RTU device and a physically connected serial port ID, physically connecting the Modbus RTU device to any serial port, and allocating a unique virtual Modbus ID to the Modbus RTU device, wherein the Modbus RTU devices with the same Modbus ID of the real device are not accessed in the same serial port.
Specifically, in this embodiment, a plurality of virtual Modbus IDs are all distributed to N serial ports of the Modbus gateway, and components with the same Modbus ID are required to be docked on different RS485 buses of the Modbus gateway; that is, the interface is connected with different physical serial ports; one RS485 serial port corresponds to one RS458 bus, namely the RS485 serial port A provides an RS485 bus A action space; the RS485 serial port B provides an RS485 bus B action space; in different "RS485 bus active spaces", the slave devices cannot directly interfere with each other, allowing the same Modbus ID to exist.
On one RS485 bus (namely, on the same RS485 serial port of the master device), components with the same Modbus ID are not allowed to exist, so that the Modbus slave device does not need to support resetting of the Modbus ID function.
A virtual Modbus ID conversion algorithm of the Modbus gateway is adopted; and virtualizing Modbus RTU equipment positioned on a plurality of Modbus buses to be positioned on the same virtual Modbus.
The Modbus TCP master device cannot sense that the Modbus slave devices are connected to different RS485 buses; the Modbus TCP master devices consider the slave devices to be on the same Modbus.
In one embodiment, in step 102, assigning a unique virtual Modbus ID to the Modbus RTU device specifically includes:
sequencing Modbus RTU equipment added under the same serial port based on the Modbus ID of real equipment to obtain a Modbus ID sequencing serial number of the real equipment of each Modbus RTU equipment;
and carrying out virtual Modbus ID distribution on the Modbus RTU equipment based on the maximum value and the minimum value of the virtual Modbus ID:
Virtual_Modbus_id=min_mod_id+dev_id
or the like, or, alternatively,
Virtual_Modbus_id=max_mod_id-dev_id;
virtual _ Modbus _ ID is a Virtual Modbus ID allocated to the Modbus RTU equipment, max _ mod _ ID is the maximum value of the Virtual Modbus ID, min _ mod _ ID is the minimum value of the Virtual Modbus ID, and dev _ ID is a real equipment Modbus ID sorting serial number of the Modbus RTU equipment.
Specifically, in this embodiment, as a preferred embodiment, assuming that "Modbus gateway has n serial ports", 220 virtual Modbus ids (11-230) are equally distributed to each serial port; for example, if there are 4 serial ports, the number of virtual modbusids allocated to each serial port is 220/4= 55; then the
The virtual Modbus ID range of the serial port 1 is [11,65]
The virtual Modbus ID range of the serial port 2 is [66,120]
The virtual Modbus ID range of the serial port 3 is [121,175]
The virtual Modbus ID range of the serial port 4 is [176,230]
When the equipment is added for the first time, the user fills the following information of the Modbus RTU equipment through the configuration page:
real device Modbus ID
Serial ID of physical connection
The devices with the same true device Modbus ID cannot be physically connected to the same serial port;
after all the devices are added, clicking to finish the addition;
the system sorts the equipment added under the same serial port according to the size of real equipment Modbus ID of the equipment, and the serial number starts from 0;
assuming that the minimum value of the virtual Modbus ID corresponding to the serial port is min _ mod _ ID and the maximum value is max _ mod _ ID; the sequence number of certain Modbus RTU equipment is dev _ id;
the virtual Modbus ID corresponding to the equipment can be obtained according to the following two algorithms:
Virtual_Modbus_id=min_mod_id+dev_id
or the like, or, alternatively,
Virtual_Modbus_id=max_mod_id-dev_id。
in one embodiment, in step 102, assigning a unique virtual Modbus ID to the Modbus RTU device includes:
and carrying out virtual Modbus ID distribution on Modbus RTU equipment added under the same serial port:
Virtual_Modbus_id=com_id*com_modbus_cnt+dev_real_modbus_id%p
h(k)=k%p
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to Modbus RTU equipment, the com _ ID is a physically connected serial port ID, the com _ Modbus _ cnt is the number of the Virtual Modbus IDs available for each serial port, the dev _ real _ Modbus _ ID is a real equipment Modbus ID, h (k) is a hash function, p is the maximum prime number not greater than com _ Modbus _ cnt, and% represents modulo p remainder operation.
Specifically, in the present embodiment, as another preferred embodiment, it is assumed that:
the Modbus gateway is provided with n serial ports;
the number of available virtual Modbus IDs is Modbus _ ID _ total _ cnt;
the initial available virtual Modbus ID is start _ Modbus _ ID;
equally dividing the available virtual Modbus IDs (11-230) to each serial port, wherein the number of the available virtual Modbus IDs of each serial port is com _ Modbus _ cnt;
com_modbus_cnt=modbus_id_total_cnt/n
the serial port ID is com _ ID and ranges from 0 to (n-1);
modbus _ id _ total _ cnt =220, for example; start _ modbus _ id =11; equally dividing 220 virtual Modbus IDs (11-230) to each serial port; if 4 serial ports exist, the number of the virtual modules allocated to each serial port is 220/4= 55; then
The virtual Modbus ID range of the serial port 1 is [11,65]
The virtual Modbus ID range of the serial port 2 is [66,120]
The virtual Modbus ID range of the serial port 3 is [121,175]
The virtual Modbus ID range of the serial port 4 is [176,230]
Adding equipment;
1) The user fills in the following information of the Modbus RTU equipment through the configuration page:
true Modbus ID; assume dev _ real _ modbus _ id;
the serial ID of the physical connection; assume com _ id;
the equipment with the same real Modbus ID can not access the same serial port physically;
the hash table is long, the number of available virtual Modbus IDs for each serial port is com _ Modbus _ cnt,
p is the maximum prime number less than or equal to com _ modbus _ cnt, the hash function is:
h(k)=k%p
where% is the modulo p remainder operation.
The virtual modbusid corresponding to the device can be obtained according to the following formula:
Virtual_Modbus_id=com_id*com_modbus_cnt+dev_real_modbus_id%p。
in an embodiment, the method for generating a virtual Modbus ID provided in the embodiment of the present invention further includes:
and when the Modbus RTU equipment is deleted, modifying the real equipment Modbus ID corresponding to the virtual Modbus ID of the Modbus RTU equipment into an illegal value.
Specifically, in the configuration information of the device, "real device modbus" corresponding to the deleted device "virtual _ modbus _ id" is modified to an illegal value; e.g., 0 or 0xFF, etc.; the "virtual _ modbus _ id" of the other devices is not changed at all.
In one embodiment, the method for generating a virtual Modbus ID provided in the embodiment of the present invention further includes:
newly-added Modbus RTU equipment finds out the item of which the Modbus ID of the first real equipment is an illegal value, and takes the serial number as the dev _ ID of the newly-added Modbus RTU equipment.
In one embodiment, the virtual Modbus ID generation method further includes:
if the fact that the real equipment Modbus ID corresponding to the Virtual _ Modbus _ ID is not an illegal value is judged and known, the hash function is in conflict;
sequentially searching the item of which the Modbus ID of the first real device is an illegal value in a virtual modbusid range corresponding to the serial port, and assuming that the serial number is new _ ID;
the virtual Modbus ID corresponding to the equipment is as follows:
Virtual_Modbus_id=com_id*com_modbus_cnt+new_id。
an embodiment of the present invention further provides a virtual Modbus ID generation device, based on the virtual Modbus ID generation method in each embodiment, including:
the serial port distribution module is used for uniformly distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the virtual Modbus ID generation module is used for acquiring a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connecting the Modbus RTU equipment to any serial port, and distributing a unique virtual Modbus ID for the Modbus RTU equipment, wherein the Modbus RTU equipment with the same real device Modbus ID is not accessed in the same serial port.
The embodiment of the present invention further provides a Modbus gateway, based on the virtual Modbus ID generation method in the above embodiments, including N serial ports, where each serial port can configure a virtual Modbus ID, and further including:
the serial port distribution module is used for uniformly distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the virtual Modbus ID generation module acquires a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connects the Modbus RTU equipment to any serial port, and allocates an unique virtual Modbus ID for the Modbus RTU equipment, wherein the Modbus RTU equipment with the same Modbus ID of the real device is not accessed in the same serial port.
Based on the same concept, an embodiment of the present invention further provides an entity structure schematic diagram of an electronic device, and as shown in fig. 3, the server may include: a processor (processor) 301, a communication Interface (communication Interface) 302, a memory (memory) 303 and a communication bus 304, wherein the processor 301, the communication Interface 302 and the memory 303 complete communication with each other through the communication bus 304. The processor 301 may call logic instructions in the memory 303 to perform the steps of the virtual Modbus ID generation method according to the above embodiments. Examples include:
distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the method comprises the steps of obtaining a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connecting the Modbus RTU equipment to any serial port, distributing an unique virtual Modbus ID for the Modbus RTU equipment, and not accessing the Modbus RTU equipment with the same Modbus ID of the real device in the same serial port.
Based on the same concept, embodiments of the present invention further provide a non-transitory computer-readable storage medium storing a computer program, where the computer program includes at least one code segment, and the at least one code segment is executable by a master control device to control the master control device to implement the steps of the virtual Modbus ID generation method according to the embodiments. Examples include:
distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the method comprises the steps of obtaining a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connecting the Modbus RTU equipment to any serial port, distributing an unique virtual Modbus ID for the Modbus RTU equipment, and not accessing the Modbus RTU equipment with the same Modbus ID of the real device in the same serial port.
Based on the same technical concept, the embodiment of the present application further provides a computer program, which is executed by the main control device to implement the method embodiment.
The program may be stored in whole or in part on a storage medium packaged with the processor, or in part or in whole on a memory not packaged with the processor.
Based on the same technical concept, the embodiment of the present application further provides a processor, which is configured to implement the foregoing method embodiment. The processor may be a chip.
In summary, according to the method and the device for generating the virtual Modbus ID provided by the embodiment of the present invention, it is required that components with the same Modbus ID must be docked on different RS485 buses of the Modbus gateway; namely, the interfaces are connected to different physical serial ports; the function of resetting Modbus ID is supported without Modbus slave setting; a virtual Modbus ID conversion algorithm of the Modbus gateway is adopted; virtualizing Modbus RTU equipment positioned on a plurality of Modbus buses into the Modbus RTU equipment positioned on the same virtual Modbus; the Modbus TCP master device cannot sense that the Modbus slave device is connected to different RS485 buses; the Modbus TCP master device considers the slave devices to be on the same Modbus bus.
The embodiments of the present invention can be arbitrarily combined to achieve different technical effects.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the procedures or functions described in accordance with the present application are generated, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (e.g., coaxial cable, fiber optic, digital subscriber line) or wirelessly (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that includes one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk), among others.
Those skilled in the art can understand that all or part of the processes in the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer readable storage medium and can include the processes of the method embodiments described above when executed. And the aforementioned storage medium includes: various media capable of storing program codes, such as ROM or RAM, magnetic or optical disks, etc.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, and not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (6)

1. A virtual Modbus ID generation method is characterized by comprising the following steps:
step 101, distributing a plurality of virtual Modbus IDs to N serial ports of a Modbus gateway;
102, acquiring a real device Modbus ID and a physically connected serial port ID of Modbus RTU equipment, physically connecting the Modbus RTU equipment to any serial port, and allocating a unique virtual Modbus ID to the Modbus RTU equipment, wherein the same Modbus RTU equipment with the same Modbus ID of the real device is not accessed in the same serial port;
sequencing Modbus RTU equipment added under the same serial port based on the Modbus ID of real equipment to obtain a Modbus ID sequencing serial number of the real equipment of each Modbus RTU equipment;
and virtual Modbus ID allocation is carried out on the Modbus RTU equipment based on the maximum value and the minimum value of the virtual Modbus ID:
Virtual_Modbus_id=min_mod_id+dev_id
or the like, or, alternatively,
Virtual_Modbus_id=max_mod_id-dev_id;
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to the Modbus RTU equipment, max _ mod _ ID is the maximum value of the Virtual Modbus ID, min _ mod _ ID is the minimum value of the Virtual Modbus ID, and dev _ ID is a real equipment Modbus ID sorting serial number of the Modbus RTU equipment;
modifying a real device Modbus ID corresponding to a virtual Modbus ID of the Modbus RTU device into an illegal value when the Modbus RTU device is deleted;
or, in step 102, assigning a unique virtual Modbus ID to the Modbus RTU device, specifically including: and carrying out virtual Modbus ID distribution on Modbus RTU equipment added under the same serial port:
Virtual_Modbus_id=com_id*com_modbus_cnt+dev_real_modbus_id%p
h(k)=k%p
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to Modbus RTU equipment, com _ ID is a physically connected serial port ID, com _ Modbus _ cnt is the number of available Virtual Modbus IDs of each serial port, dev _ real _ Modbus _ ID is a real equipment Modbus ID, h (k) is a hash function, p is the maximum prime number not greater than com _ Modbus _ cnt, and% represents modulo p remainder operation;
modbus RTU equipment with the same Modbus ID as real equipment is not accessed to the same serial port;
if the fact that the real equipment Modbus ID corresponding to the Virtual _ Modbus _ ID is not an illegal value is judged and known, the fact that the hash function conflicts is represented;
sequentially searching the item of which the Modbus ID of the first real equipment is an illegal value in a virtual Modbus ID range corresponding to the serial port, and assuming that the serial number is new _ ID;
the virtual Modbus ID corresponding to the device is:
Virtual_Modbus_id=com_id*com_modbus_cnt+new_id。
2. the virtual Modbus ID generation method of claim 1, further comprising:
newly-added Modbus RTU equipment finds out the item of which the Modbus ID of the first real equipment is an illegal value, and takes the serial number as the dev _ ID of the newly-added Modbus RTU equipment.
3. A virtual Modbus ID generation device, comprising:
the serial port distribution module is used for uniformly distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the virtual Modbus ID generation module is used for acquiring a Modbus ID of real equipment of Modbus RTU equipment and a physically connected serial port ID, physically connecting the Modbus RTU equipment to any serial port, and distributing a unique virtual Modbus ID for the Modbus RTU equipment, wherein the Modbus RTU equipment with the same Modbus ID of the real equipment is not accessed in the same serial port; sequencing Modbus RTU equipment added under the same serial port based on the Modbus ID of real equipment to obtain a Modbus ID sequencing serial number of the real equipment of each Modbus RTU equipment;
and carrying out virtual Modbus ID distribution on the Modbus RTU equipment based on the maximum value and the minimum value of the virtual Modbus ID:
Virtual_Modbus_id=min_mod_id+dev_id
or the like, or, alternatively,
Virtual_Modbus_id=max_mod_id-dev_id;
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to the Modbus RTU equipment, max _ mod _ ID is the maximum value of the Virtual Modbus ID, min _ mod _ ID is the minimum value of the Virtual Modbus ID, and dev _ ID is a real equipment Modbus ID sorting serial number of the Modbus RTU equipment;
modifying a real device Modbus ID corresponding to a virtual Modbus ID of the Modbus RTU device into an illegal value when the Modbus RTU device is deleted; the same serial port is not accessed with Modbus RTU equipment with the same Modbus ID of real equipment;
or, a unique virtual Modbus ID is allocated to the Modbus RTU device, which specifically includes: and carrying out virtual Modbus ID distribution on Modbus RTU equipment added under the same serial port:
Virtual_Modbus_id=com_id*com_modbus_cnt+dev_real_modbus_id%p
h(k)=k%p
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to Modbus RTU equipment, com _ ID is a physically connected serial port ID, com _ Modbus _ cnt is the number of the Virtual Modbus IDs available for each serial port, dev _ real _ Modbus _ ID is a real equipment Modbus ID, h (k) is a hash function, p is the maximum prime number not greater than com _ Modbus _ cnt, and% represents modulo p remainder operation;
the same serial port is not accessed with Modbus RTU equipment with the same Modbus ID of real equipment;
if the fact that the real equipment Modbus ID corresponding to the Virtual _ Modbus _ ID is not an illegal value is judged and known, the fact that the hash function conflicts is represented;
sequentially searching the item of which the Modbus ID of the first real equipment is an illegal value in a virtual Modbus ID range corresponding to the serial port, and assuming that the serial number is new _ ID;
the virtual Modbus ID corresponding to the equipment is as follows:
Virtual_Modbus_id=com_id*com_modbus_cnt+new_id。
4. the utility model provides a Modbus gateway which characterized in that includes N serial ports, and every serial port can dispose virtual Modbus ID, still includes:
the serial port distribution module is used for distributing the virtual Modbus IDs to N serial ports of the Modbus gateway;
the virtual Modbus ID generation module is used for acquiring a real device Modbus ID of Modbus RTU equipment and a physically connected serial port ID, physically connecting the Modbus RTU equipment to any serial port, and allocating a unique virtual Modbus ID to the Modbus RTU equipment, wherein the same Modbus RTU equipment with the same Modbus ID of the real device is not accessed in the same serial port; sequencing Modbus RTU equipment added under the same serial port based on the Modbus ID of real equipment to obtain a Modbus ID sequencing serial number of the real equipment of each Modbus RTU equipment;
and carrying out virtual Modbus ID distribution on the Modbus RTU equipment based on the maximum value and the minimum value of the virtual Modbus ID:
Virtual_Modbus_id=min_mod_id+dev_id
or the like, or, alternatively,
Virtual_Modbus_id=max_mod_id-dev_id;
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to the Modbus RTU equipment, max _ mod _ ID is the maximum value of the Virtual Modbus ID, min _ mod _ ID is the minimum value of the Virtual Modbus ID, and dev _ ID is a real equipment Modbus ID sorting serial number of the Modbus RTU equipment;
modifying a real device Modbus ID corresponding to a virtual Modbus ID of the Modbus RTU device into an illegal value when the Modbus RTU device is deleted; the same serial port is not accessed with Modbus RTU equipment with the same Modbus ID of real equipment;
or, a unique virtual Modbus ID is allocated to the Modbus RTU device, which specifically includes: and carrying out virtual Modbus ID distribution on Modbus RTU equipment added under the same serial port:
Virtual_Modbus_id=com_id*com_modbus_cnt+dev_real_modbus_id%p
h(k)=k%p
the Virtual _ Modbus _ ID is a Virtual Modbus ID allocated to Modbus RTU equipment, com _ ID is a physically connected serial port ID, com _ Modbus _ cnt is the number of available Virtual Modbus IDs of each serial port, dev _ real _ Modbus _ ID is a real equipment Modbus ID, h (k) is a hash function, p is the maximum prime number not greater than com _ Modbus _ cnt, and% represents modulo p remainder operation;
the same serial port is not accessed with Modbus RTU equipment with the same Modbus ID of real equipment;
if the fact that the real equipment Modbus ID corresponding to the Virtual _ Modbus _ ID is not an illegal value is judged and known, the fact that the hash function conflicts is represented;
sequentially searching the item of which the Modbus ID of the first real equipment is an illegal value in a virtual Modbus ID range corresponding to the serial port, and assuming that the serial number is new _ ID;
the virtual Modbus ID corresponding to the equipment is as follows:
Virtual_Modbus_id=com_id*com_modbus_cnt+new_id。
5. an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor when executing the program performs the steps of the virtual Modbus ID generation method of any of claims 1 to 2.
6. A non-transitory computer readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, performs the steps of the virtual Modbus ID generation method of any of claims 1-2.
CN202010918803.0A 2020-09-04 2020-09-04 Virtual Modbus ID generation method and device and gateway Active CN112260914B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010918803.0A CN112260914B (en) 2020-09-04 2020-09-04 Virtual Modbus ID generation method and device and gateway

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010918803.0A CN112260914B (en) 2020-09-04 2020-09-04 Virtual Modbus ID generation method and device and gateway

Publications (2)

Publication Number Publication Date
CN112260914A CN112260914A (en) 2021-01-22
CN112260914B true CN112260914B (en) 2023-04-07

Family

ID=74224800

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010918803.0A Active CN112260914B (en) 2020-09-04 2020-09-04 Virtual Modbus ID generation method and device and gateway

Country Status (1)

Country Link
CN (1) CN112260914B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103716420A (en) * 2014-01-03 2014-04-09 西南大学 Automatic station address obtaining method of Modbus ASCII slave station and slave station
CN105323328A (en) * 2014-07-11 2016-02-10 北海市深蓝科技发展有限责任公司 Automatic address identification method by utilizing MODBUS communication protocol on RS-485

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7016981B2 (en) * 2002-09-09 2006-03-21 Sun Microsystems, Inc. Switching apparatus and method for increasing the total number of addressable electronic devices beyond limits imposed by device address sizes
CN204517854U (en) * 2015-03-17 2015-07-29 上海纳宇电气有限公司 A kind of fieldbus node circuit based on Modbus agreement
CN108123860A (en) * 2017-01-19 2018-06-05 山西智舒智能科技有限公司 The ID of intelligent domestic system node device based on CAN bus is distributed automatically and management method
CN107205063A (en) * 2017-07-28 2017-09-26 杭州聪普智能科技有限公司 A kind of device conflict solution of Intelligent housing bus
CN109150680B (en) * 2018-08-30 2020-10-16 青岛科技大学 Self-adaptive address-determining networking circuit and method suitable for RS485 bus
CN111221765A (en) * 2019-12-31 2020-06-02 苏州浪潮智能科技有限公司 Communication method and communication system for preventing I2C bus address conflict

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103716420A (en) * 2014-01-03 2014-04-09 西南大学 Automatic station address obtaining method of Modbus ASCII slave station and slave station
CN105323328A (en) * 2014-07-11 2016-02-10 北海市深蓝科技发展有限责任公司 Automatic address identification method by utilizing MODBUS communication protocol on RS-485

Also Published As

Publication number Publication date
CN112260914A (en) 2021-01-22

Similar Documents

Publication Publication Date Title
CN108256002B (en) Cross-machine-room data synchronization method, device, system and server
US11689907B2 (en) Internet of things device hierarchies
EP2892212B1 (en) Micro server and method of allocating a mac address
CN108243407B (en) Method for managing network interfaces of multiple wireless module devices and terminal device
CN114338594B (en) ARP (Address resolution protocol) response-substituting method, device, equipment and storage medium in Kubernetes environment
CN109644522A (en) For passing through the method and system of wireless network secure loading equipemtn
CN112637371B (en) Node address determination method and device, electronic equipment and storage medium
EP3032752B1 (en) Apparatus, system and method for allocating identifiers to components of a control system
CN112954088A (en) Equipment address allocation method and equipment of CAN network and electronic equipment
CN112235175A (en) Access method and access device of network bridge equipment and network bridge equipment
CN110730244A (en) Networking method and system of DHT (distributed hash table) system, network equipment and storage medium
CN112260914B (en) Virtual Modbus ID generation method and device and gateway
CN110554905A (en) Starting method and device of container
CN113630300B (en) Method and node for message transmission
CN113114571A (en) Data packet processing method and device, electronic equipment and storage medium
CN112511441A (en) Message processing method and device
CN112069113A (en) I2C equipment configuration method and system
CN106453680B (en) IP address allocation method and device
CN112765076B (en) MODBUS data processing method, device, equipment and computer readable storage medium
CN109542622A (en) A kind of data processing method and device
CN110099121A (en) Public cloud service processing method, computer installation and storage medium
CN216216967U (en) Communication device
CN113157433B (en) Resource allocation method, electronic device, and computer-readable medium
CN117749563A (en) PLC module ad hoc network method, system and equipment
CN116232889A (en) Data processing method and device based on network topology structure

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant