CN110858183A - 2-in 1-out RS-232/RS-485 self-adaptive module and method - Google Patents

2-in 1-out RS-232/RS-485 self-adaptive module and method Download PDF

Info

Publication number
CN110858183A
CN110858183A CN201810977174.1A CN201810977174A CN110858183A CN 110858183 A CN110858183 A CN 110858183A CN 201810977174 A CN201810977174 A CN 201810977174A CN 110858183 A CN110858183 A CN 110858183A
Authority
CN
China
Prior art keywords
input
interface
output end
module
protocol
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.)
Pending
Application number
CN201810977174.1A
Other languages
Chinese (zh)
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.)
Shanghai Zontec Information Technology Co Ltd
Original Assignee
Shanghai Zontec Information Technology 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 Shanghai Zontec Information Technology Co Ltd filed Critical Shanghai Zontec Information Technology Co Ltd
Priority to CN201810977174.1A priority Critical patent/CN110858183A/en
Publication of CN110858183A publication Critical patent/CN110858183A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • G06F13/385Information transfer, e.g. on bus using universal interface adapter for adaptation of a particular data processing system to different peripheral devices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/0002Serial port, e.g. RS232C

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Power Sources (AREA)
  • Information Transfer Systems (AREA)
  • Communication Control (AREA)

Abstract

The invention discloses a 2-in 1-out RS-232/RS-485 self-adaptive module and a method, comprising a singlechip and a peripheral input and output circuit; the peripheral input and output circuit comprises two input ends, one output end and two isolating devices; the two input ends and one output end are provided with RS-232 and RS-485 interfaces, the RS-232 and RS-485 interfaces of each input end and each output end can be used at will, two kinds of signals which are accessed can be selected from two or not at the same time, the two input ends are respectively connected with the single chip microcomputer through the isolating devices, and the output ends are not required to be isolated from the single chip microcomputer. The invention realizes that two computers or instruments simultaneously read data in one instrument, and the instrument has only a single serial port, realizes double reading of a single RS-232 interface or RS-485 interface instrument with low cost, avoids huge waste generated by instrument replacement for realizing data acquisition, and simultaneously strives for time for project development.

Description

2-in 1-out RS-232/RS-485 self-adaptive module and method
Technical Field
The invention belongs to the technical field of computer technology and communication, and particularly relates to a 2-in 1-out RS-232/RS-485 data interface conversion device and a self-adaptive interface conversion method.
Background
Nowadays, the computer technology is rapidly developed, RS-232 interfaces are cancelled in computers, but in the industry, most of RS-232 interfaces have communication functions and are still provided with RS-232 interfaces for historical reasons. Meanwhile, a large number of old devices still rely on RS-232 to communicate with the outside, and RS-485 interfaces are widely applied due to the long transmission distance. However, the following problems are often encountered during data acquisition: one instrument only has one interface RS-232 or RS-485, and the original system is occupied. It is not easy to read the data from the instrument.
It is known that only one master can be present on either the RS-232 or RS-485 bus, and the others are slaves (RS-232 is mostly one-to-one transmission, occasionally 1-to-many), and that multi-to-1 transmission cannot be achieved. However, as industrial technologies develop, quality monitoring of products becomes more and more important, if new devices are designed, the above-mentioned problems exist if data are extracted from old devices, and once a port is occupied, the quality monitoring becomes unsound. The market has 1 to many hardware, that is, 1 serial port of the main device is converted into a plurality of serial ports, which can solve the problem of 1 to many, but can not solve the problem of more than 1 to 1, that is, the problem that data in one instrument can be read by two computers or instruments at the same time can not be solved, and the instrument has only a single serial port (RS-232/RS-485).
Disclosure of Invention
Aiming at the problems, the invention provides a 2-in 1-out RS-232/RS-485 self-adaptive module and a method, which solve the problem that the existing equipment in the industry acquires data and only the RS-232/RS-485 interface of an instrument is occupied, and realize that two computers or instruments can read data in one instrument at the same time, and the instrument has the condition of only a single serial port (RS-232/RS-485).
In order to achieve the purpose, the invention provides the following technical scheme:
one of the technical schemes of the invention is as follows: a2-in 1-out RS-232/RS-485 self-adaptive module comprises a singlechip and a peripheral input and output circuit; the peripheral input and output circuit comprises two input ends, one output end and two isolating devices; the first input end comprises an RS-232 interface, an RS-485 interface, a USB interface and an AND gate, when in input, the low level of the RS-232 interface, the RS-485 interface and the USB interface effectively transmits an input signal to the singlechip through the AND gate, and the USB interface can be directly connected with the USB port of a computer and supplies power to the self-adaptive module; the second input end comprises an RS-232 interface, an RS-485 interface and an AND gate, and when the input is input, the low level of the RS-232 interface and the RS-485 interface effectively transmits an input signal to the singlechip through the AND gate; the output end comprises an RS-232 interface, an RS-485 interface and an AND gate; the first input end adopts 5V power supply, the self-adaptive module respectively supplies power to the second input end and the output end through 2 DC/DC modules, and the output end and the singlechip share a power supply; the two input ends are connected with the single chip microcomputer through isolating devices respectively, and the output end is not required to be isolated from the single chip microcomputer.
According to one aspect of the invention, the isolation device is a high-speed dedicated three-channel isolation device, and the transmission rate is not lower than 115200 bps.
The second technical scheme of the invention is as follows: a2-in 1-out RS-232/RS-485 self-adaptive method is provided with a single chip microcomputer, two input ends and an output end, wherein the two input ends and the output end are both provided with RS-232 and RS-485 interfaces, the RS-232 and RS-485 interfaces of each input end and output end can be used at will, and two accessed signals can be transmitted only by one of two or not at the same time; the single chip microcomputer circularly detects which input end has an input signal, which input signal has a complete data frame to be received, and sends the frame information to the output end as it is, and records the source of the command, at the same time, if another input end also receives the signal, the received data frame is stored in the buffer area, waits for the data return of the output end, and when the data return of the output end completes one frame, the returned information is returned as it is according to the source of the command; if a new command arrives at the moment, the new command is sent out, and the recording command source is repeated.
According to one aspect of the invention, all inputs are connected to the single-chip via isolation devices.
In accordance with one aspect of the invention, the data frame length is no greater than 255 bytes.
According to one aspect of the invention, the single chip microcomputer judges the end of a frame, and the system transmission rate is set by a system and is set by a setting program through a designated port; the set content comprises: system transmission rate: 115200 to 300 (12 in total); time-out time: 10-2000 ms; command protocol: modbus protocol (RTU), Modbus protocol (ASCII), end of line change with carriage return, others; if the command protocol is otherwise, a frame is considered to be over when no characters are received within the time required to wait for a four byte transmission.
According to one aspect of the invention, the single chip microcomputer comprises three interrupt response modules, a timing module, a communication organization module and a protocol analysis module; the three interrupt response modules have the same structure and send data to be sent in the buffer area until the sending is finished; receiving the incoming data, judging that a frame is finished according to a protocol if the protocol exists, and then informing the main module, namely the communication organization module; the timing module is responsible for judging timeout, and judging that a frame is ended when no protocol exists; the communication organization module is a main module and sends the commands received by the inlet to the outlets in sequence, and simultaneously sends the data frames received by the outlets to the inlet for sending the commands; and the protocol analysis module is responsible for analyzing the end of one frame when a protocol exists.
Due to the adoption of the scheme, the invention has the beneficial effects that:
the invention fills the blank of the product, realizes double reading of a single RS-232 interface or RS-485 interface instrument with low cost, avoids huge waste caused by replacing the instrument for realizing data acquisition, and simultaneously strives for time for project development.
Drawings
Fig. 1 is a logical block diagram of the circuit configuration of the present invention.
Detailed Description
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 only a part of the embodiments of the present invention, and not all of the embodiments. 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.
Referring to fig. 1, the circuit structure of the adaptive module of the present invention is:
the power supply part directly supplies power to the inlet 1 (the port can be directly supplied by a USB) because the device adopts 5V power supply, and the system respectively supplies power to the inlet 2 and the outlet through 2 DC/DC modules (a singlechip and the outlet share a power supply).
Inlet 1: port 1 supports three modes, RS-232/RS-485/USB (USB to 232), wherein the signal is sent to MCU through an AND gate because the input is active low, and USB to 232 determines whether to send the signal or not through a SUSPEND signal.
An inlet 2: the entry 2 supports two modes, RS-232/RS-485, and the signal is effectively sent to the MCU through an and gate at the input because of the low level.
All the inlet signals are connected with the MCU through a high-speed digital isolation chip.
And (4) outlet: the outlet and the MCU share a set of power supply, so that isolation is not needed, and the interface form is the same as that of the inlet 2.
The input and output are isolated, the mutual interference is reduced, and the isolation device adopts a high-speed special three-channel isolation device, so that the transmission rate is not lower than 115200 bps.
The inlet 1, the inlet 2 and the outlet are all provided with RS-232 and RS-485 ports, two interfaces of each inlet and outlet can be used at will, what signals are accessed to realize what signal transmission (signals can be selected alternatively and cannot be simultaneously), the inlet 1 is also provided with a USB-to-serial port function, can be directly connected with a USB port of a computer, and simultaneously supplies power to the system.
From the above, the invention can realize interface conversion, such as RS-232 to RS-485, RS-485 to RS-232, USB to RS-485, USB to RS-232, and the like.
The MCU detects that which of the two inlets has an input signal circularly, sends the frame information to the outlet as it is after a complete data frame is received first, and records the source of the command at the same time, if another inlet also receives the signal, the received data frame is stored in the buffer area, waits for the data of the outlet to return, and returns the returned information as it is according to the source of the command after the data of the outlet returns to complete one frame. If a new command arrives at the moment, the new command is sent out, and the recording command source is repeated. The data frame length is not greater than 255 bytes.
How to judge the end of a frame, the system transmission rate, and the like is performed by the system setting, and is performed by the setting program through the designated port.
The set content comprises:
system transmission rate: 115200- - -300 (12 pieces in total)
Time-out time: 10-2000 ms
Command protocol: modbus protocol (RTU), Modbus protocol (ASCII), end of line change with carriage return, and others.
If the command protocol is otherwise, a frame is considered to be over when no characters are received within the time required to wait for a four byte transmission.
The system comprises three interrupt response modules, a timing module, a communication organization module (main module), a protocol analysis module and the like.
Three interrupt response modules: the three modules have the same structure and send data to be sent in the buffer area until the data are sent; and receiving the incoming data, judging that one frame is finished according to the protocol if the protocol exists, and then informing the main module (the timing module finishes the protocol if the protocol does not exist).
A timing module: the module is intended to solve the following problems: judging overtime; and judging that one frame is ended when no protocol exists.
A communication organization module: the communication organization module, namely the main module, sends the commands received by the inlet to the outlets in sequence, and simultaneously sends the data frames received by the outlets to the inlet sending the commands.
A protocol analysis module: responsible for resolving the end of a frame (if any).
The system sets up the communication protocol:
the system setting is completed by an entrance 1, and the Baud rate of the power-on port of the system is fixed as follows: 2400bps, and the system sends a request signal "toSetup \ r \ n" to wait for a response time of 1.5 seconds, and if no response is made, the system enters a working state.
If the system receives 'Setup \ r \ n' within 1.5 seconds, the system enters the Setup state. The system would then receive set instructions at 2400bps baud: and guiding to receive the StartWork \ r \ n to exit the setting and enter the working state (or power on again).
List of commands:
"? Protocol \ r \ n "- - -reads the Protocol status.
"? Overtime \ r \ n "- - -read timeout time.
"? BaudRate \ r \ n "- - -read baud rate.
Protocol xxxxxx \ r \ n "-write protocol status.
"═ OverTimexxxxxx \ r \ n" — write timeout time.
"═ BaudRatexxxxxx \ r \ n" - - - -write baud rate.
Wherein: protocol has four values, modbusRTU, modbusSCII, Newline, None.
The value range of OverTime: 10-2000 (units of milliseconds).
The value range of BaudRate: 115200, 57600, 38400, 28800, 19200, 14400, 9600, 4800, 2400, 1200, 600, 300.
Reading success return response parameters: if BaudRate is read, "9600 \ r \ n" is returned.
The read failure returns "Error \ r \ n" or no return.
The successful writing returns 'OK \ r \ n'
The write failure returns "NG \ r \ n" or no return.
The embodiments described above are described to facilitate understanding and application of the present patent to those of ordinary skill in the art. It will be readily apparent to those skilled in the art that various modifications to these embodiments may be made, and the generic principles described herein may be applied to other embodiments without the use of the inventive faculty. Therefore, the present invention is not limited to the embodiments described herein, and those skilled in the art should make improvements and modifications within the scope of the present invention based on the disclosure of the present invention.

Claims (7)

1. A2-in 1-out RS-232/RS-485 self-adaptive module is characterized in that: the system comprises a singlechip and a peripheral input and output circuit; the peripheral input and output circuit comprises two input ends, one output end and two isolating devices; the first input end comprises an RS-232 interface, an RS-485 interface, a USB interface and an AND gate, when in input, the low level of the RS-232 interface, the RS-485 interface and the USB interface effectively transmits an input signal to the singlechip through the AND gate, and the USB interface can be directly connected with the USB port of a computer and supplies power to the self-adaptive module; the second input end comprises an RS-232 interface, an RS-485 interface and an AND gate, and when the input is input, the low level of the RS-232 interface and the RS-485 interface effectively transmits an input signal to the singlechip through the AND gate; the output end comprises an RS-232 interface, an RS-485 interface and an AND gate; the first input end adopts 5V power supply, the self-adaptive module respectively supplies power to the second input end and the output end through 2 DC/DC modules, and the output end and the singlechip share a power supply; the two input ends are connected with the single chip microcomputer through isolating devices respectively, and the output end is not required to be isolated from the single chip microcomputer.
2. The 2-in 1-out RS-232/RS-485 adaptation module of claim 1, wherein: the isolation device adopts a high-speed special three-channel isolation device, and the transmission rate is not lower than 115200 bps.
3. A2-in 1-out RS-232/RS-485 self-adaptive method is characterized in that: the method comprises the steps that a single chip microcomputer, two input ends and one output end are configured, the two input ends and the output end are both provided with RS-232 and RS-485 interfaces, the RS-232 and RS-485 interfaces of each input end and each output end can be used at will, and two accessed signals can be transmitted only by one of two or not at the same time; the single chip microcomputer circularly detects which input end has an input signal, which input signal has a complete data frame to be received, and sends the frame information to the output end as it is, and records the source of the command, at the same time, if another input end also receives the signal, the received data frame is stored in the buffer area, waits for the data return of the output end, and when the data return of the output end completes one frame, the returned information is returned as it is according to the source of the command; if a new command arrives at the moment, the new command is sent out, and the recording command source is repeated.
4. The 2-in 1-out RS-232/RS-485 adaptive method of claim 3, wherein: all input ends are connected with the single chip microcomputer through isolating devices.
5. The 2-in 1-out RS-232/RS-485 adaptive method of claim 3, wherein: the data frame length is not greater than 255 bytes.
6. The 2-in 1-out RS-232/RS-485 adaptive method of claim 3, wherein: the single chip microcomputer judges the end of a frame, and the system transmission rate is set through a system and is set through a designated port; the set content comprises: system transmission rate: 115200 to 300 (12 in total); time-out time: 10-2000 ms; command protocol: modbus protocol (RTU), Modbus protocol (ASCII), end of line change with carriage return, others; if the command protocol is otherwise, a frame is considered to be over when no characters are received within the time required to wait for a four byte transmission.
7. The 2-in 1-out RS-232/RS-485 adaptive method of claim 3, wherein: the single chip microcomputer comprises three interrupt response modules, a timing module, a communication organization module and a protocol analysis module; the three interrupt response modules have the same structure and send data to be sent in the buffer area until the sending is finished; receiving the incoming data, judging that a frame is finished according to a protocol if the protocol exists, and then informing the main module, namely the communication organization module; the timing module is responsible for judging timeout, and judging that a frame is ended when no protocol exists; the communication organization module is a main module and sends the commands received by the inlet to the outlets in sequence, and simultaneously sends the data frames received by the outlets to the inlet for sending the commands; and the protocol analysis module is responsible for analyzing the end of one frame when a protocol exists.
CN201810977174.1A 2018-08-26 2018-08-26 2-in 1-out RS-232/RS-485 self-adaptive module and method Pending CN110858183A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810977174.1A CN110858183A (en) 2018-08-26 2018-08-26 2-in 1-out RS-232/RS-485 self-adaptive module and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810977174.1A CN110858183A (en) 2018-08-26 2018-08-26 2-in 1-out RS-232/RS-485 self-adaptive module and method

Publications (1)

Publication Number Publication Date
CN110858183A true CN110858183A (en) 2020-03-03

Family

ID=69635661

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810977174.1A Pending CN110858183A (en) 2018-08-26 2018-08-26 2-in 1-out RS-232/RS-485 self-adaptive module and method

Country Status (1)

Country Link
CN (1) CN110858183A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN203027245U (en) * 2012-11-09 2013-06-26 深圳市祈飞科技有限公司 RS232 and RS485 adaptive interface circuit
CN105516142A (en) * 2015-12-09 2016-04-20 梅照付 Mutual communication method in smart power system
CN105785958A (en) * 2016-05-08 2016-07-20 杭州集控软件有限公司 Smart factory-based multi-function data acquisition device, acquisition system and method
CN107465576A (en) * 2017-08-23 2017-12-12 江苏舾普泰克自动化科技有限公司 A kind of more host communication system and methods based on Modbus agreements

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN203027245U (en) * 2012-11-09 2013-06-26 深圳市祈飞科技有限公司 RS232 and RS485 adaptive interface circuit
CN105516142A (en) * 2015-12-09 2016-04-20 梅照付 Mutual communication method in smart power system
CN105785958A (en) * 2016-05-08 2016-07-20 杭州集控软件有限公司 Smart factory-based multi-function data acquisition device, acquisition system and method
CN107465576A (en) * 2017-08-23 2017-12-12 江苏舾普泰克自动化科技有限公司 A kind of more host communication system and methods based on Modbus agreements

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
崔建峰和陈海峰主编: "《物联网TCP/IP技术详解》" *

Similar Documents

Publication Publication Date Title
DE3845018B4 (en) Base station for wireless digital telephone system - has channel controllers coupled to multiplexer for connecting assigned time slots to given subscriber stations
US4441162A (en) Local network interface with control processor & DMA controller for coupling data processing stations to common serial communications medium
US3961139A (en) Time division multiplexed loop communication system with dynamic allocation of channels
CN111901164B (en) Adaptive control method, device, equipment and system of OCP NIC network card
JPS61212940A (en) Data transmission method for multi-network system
CN104901859A (en) AXI/PCIE bus converting device
CN110635982B (en) Double-host communication method and system on communication bus, industrial control gateway and storage medium
CN101794152A (en) Embedded controller with LVDS serial interface and control method thereof
CN109062847A (en) System on chip, IP kernel and its control method for RS485 serial communication
CN107992439B (en) Extensible data interaction method and system
CN1960276B (en) Remote control system and method
CN113904762B (en) Full duplex 485 bus communication system with annular buffer zone and method
CN108667706B (en) Ethernet serial server with dynamically adjustable serial number and data transmission method thereof
CN109975764A (en) A kind of transmission of general purpose radar integratedization high speed fibre and control interface plate and its application
CN110858183A (en) 2-in 1-out RS-232/RS-485 self-adaptive module and method
CN103124195A (en) Method for implementing fiber channel link speed negotiation
CN207780763U (en) Multiplex roles CPU module
CN202795349U (en) Serial bus data analyzer and analysis system
EP0607375B1 (en) A centralized management system utilizing a bus interface unit
CN213582152U (en) PCIE signal bit width automatic switching device of desktop and server system
CN210804414U (en) Circuit with reusable communication interface
CN110442096B (en) Data acquisition control workstation and data transmission method thereof
CN209994385U (en) Double-network-port embedded industrial control terminal supporting POE power supply
CN109328449A (en) RTEX-EtherCAT protocol conversion apparatus and industrial control system
CN220629487U (en) Repeater capable of expanding multiple hosts

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200303