CN114328336A - Serial port transceiving method, system, terminal and storage medium based on Android - Google Patents
Serial port transceiving method, system, terminal and storage medium based on Android Download PDFInfo
- Publication number
- CN114328336A CN114328336A CN202111594821.9A CN202111594821A CN114328336A CN 114328336 A CN114328336 A CN 114328336A CN 202111594821 A CN202111594821 A CN 202111594821A CN 114328336 A CN114328336 A CN 114328336A
- Authority
- CN
- China
- Prior art keywords
- data
- serial port
- module
- android
- processor
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 40
- 230000005540 biological transmission Effects 0.000 claims abstract description 10
- 238000004590 computer program Methods 0.000 claims description 9
- 230000002028 premature Effects 0.000 abstract description 4
- 238000004891 communication Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
Images
Landscapes
- Information Transfer Systems (AREA)
Abstract
The invention relates to an Android-based serial port transceiving method, which comprises the following steps: before the RS485 module is used for sending data, the RS485 module is switched to a sending mode; in the data sending process, inquiring a register in a processor for carrying out data sending processing at intervals of a set duration, and judging whether the data is sent completely; after the data transmission is finished, the RS485 module is switched into a receiving mode; by the method, when the RS485 serial port sends data, the register condition of the processor is continuously inquired, and the RS485 serial port is switched into the receiving mode when the data sending is finished, so that the condition that data packets are lost due to premature switching is avoided, extra hardware is added wirelessly, and the hardware cost is reduced.
Description
Technical Field
The invention relates to the technical field of serial port control of Android systems, in particular to a serial port transceiving method, a serial port transceiving system, a serial port transceiving terminal and a storage medium based on Android.
Background
The mobile phone and the tablet personal computer are widely applied, so that the application prospect of the pushing technology for the intelligent terminal is wider and wider. Currently, operating systems used by intelligent terminal platforms mainly include Windows Mobile, Android, IoS, Sybian platforms, and the like. By implanting a terminal program in the operating system. Different platforms CAN not be matched with peripheral equipment, and the common communication modes with the peripheral equipment include IIC, UART (RS232 and RS485), CAN, SPI and the like.
RS485 is usually used for communicating with external devices such as a single chip microcomputer (or signal acquisition), an Android operating system is not a real-time operating system, and more or less delay phenomenon exists in a scheduling thread, so that the RS485 is changed into a receiving mode without sending data completely, and packet loss is caused; therefore, at present, the RS485 basically receives and transmits data through hardware to avoid the situation of data loss, and the use of hardware for receiving means that the hardware cost is increased; in order to reduce the cost, a method for receiving and transmitting data by a serial port in a software mode and preventing packet loss is needed.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide an Android-based serial port transceiving method, an Android-based serial port transceiving system, an Android-based serial port transceiving terminal, and a computer-readable storage medium, in view of the above-mentioned defects in the prior art.
The technical scheme adopted by the invention for solving the technical problems is as follows:
a serial port receiving and transmitting method based on Android is constructed, wherein the method comprises the following steps:
the first step is as follows: before the RS485 module is used for sending data, the RS485 module is switched to a sending mode;
the second step is that: in the data sending process, inquiring a register in a processor for carrying out data sending processing at intervals of a set duration, and judging whether the data is sent completely;
the third step: and after the data transmission is finished, switching the RS485 module into a receiving mode.
The serial port receiving and transmitting method based on the Android comprises the following steps that a RK3568 chip is adopted by a processor;
in the second step, the operation method of inquiring the register is as follows:
and inquiring a UART LSR register in the RK3568 chip at a set time interval.
In the Android-based serial port transceiving method, in the first step, the RS485 module is switched to a sending mode by pulling up a GPIO port of an RS485 control chip.
In the third step, the operation of switching the RS485 module to the receiving mode is realized by pulling up the GPIO port of the RS485 control chip.
A serial port receiving and dispatching system based on Android is used for realizing the serial port receiving and dispatching method based on Android, and comprises an RS485 module, an RS485 control chip and a data processor;
the S485 control chip is used for switching the RS485 module into a sending mode before the RS485 module is used for sending data, and switching the RS485 module into a receiving mode after the data is sent;
the data processor is used for inquiring the register at a set time interval in the data sending process and judging whether the data is sent completely; and the S485 control chip is also used for sending an instruction to the S485 control chip before and after data is sent so as to control the operation of the S485 control chip.
According to the serial port receiving and transmitting system based on the Android, the mode switching of the RS485 module is realized by changing the high and low level states of the GPIO port of the RS485 control chip.
The serial port transceiving system based on the Android, disclosed by the invention, is characterized in that the data processor adopts an RK3568 chip, and the register is a UART LSR register.
A serial port transceiver terminal based on Android comprises a memory, a processor and a computer program which is stored in the memory and can run on the processor, wherein the steps of the method are realized when the processor executes the computer program.
A computer-readable storage medium, in which a computer program is stored, which, when being executed by a processor, carries out the steps of the method as described above.
The invention has the beneficial effects that: by the method, when the RS485 serial port sends data, the register condition of the processor is continuously inquired, and the RS485 serial port is switched into the receiving mode when the data sending is finished, so that the condition that data packets are lost due to premature switching is avoided, extra hardware is added wirelessly, and the hardware cost is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the present invention will be further described with reference to the accompanying drawings and embodiments, wherein the drawings in the following description are only part of the embodiments of the present invention, and for those skilled in the art, other drawings can be obtained without inventive efforts according to the accompanying drawings:
FIG. 1 is a flowchart illustrating an Android-based serial port transceiving method according to a preferred embodiment of the present invention;
fig. 2 is a schematic block diagram of an Android-based serial port transceiving system according to a preferred embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention, and it is obvious that the described embodiments are some embodiments of the present invention, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without inventive step, are within the scope of the present invention.
As shown in fig. 1, the serial port transceiving method based on Android according to the preferred embodiment of the present invention includes the following steps:
s01: before the RS485 module is used for sending data, the RS485 module is switched to a sending mode;
s02: in the data sending process, inquiring a register in a processor for carrying out data sending processing at intervals of a set duration, and judging whether the data is sent completely;
s03: after the data transmission is finished, the RS485 module is switched into a receiving mode;
by the method, when the RS485 serial port transmits data, the register condition of the processor is continuously inquired, and the RS485 serial port is switched into a receiving mode when the data transmission is finished, so that the condition of data packet loss caused by premature switching is avoided, extra hardware is added wirelessly, and the hardware cost is reduced;
more specifically, the invention aims to solve the problem that the RS485 is not strict in use, the method can be used for most RK485 communication, and an LSR (line Status register) register in the RK3568 UART is matched with a related algorithm for use, so that data can be accurately received and transmitted, and the hardware cost is saved;
it should be noted that, when the query register finds that the data transmission is timed out, the RS485 module is also switched to the receiving mode.
Preferably, the processor adopts RK3568 chip; the operation method for inquiring the register comprises the following steps: and inquiring a UART LSR register in the RK3568 chip at a set time interval.
It will be appreciated that other processor chips and corresponding registers within the chips may be substituted based on the above principles of the present application, and that simple alternatives based on such principles are within the scope of the present application;
preferably, in the first step, the RS485 module is switched to the transmission mode by pulling up a GPIO port of the RS485 control chip; in the third step, the operation of switching the RS485 module into a receiving mode is realized by pulling up the GPIO port of the RS485 control chip; the mode switching operation is simple, convenient and quick; the model of the RS485 control chip can be a conventional model.
An Android-based serial port transceiving system is used for realizing the Android-based serial port transceiving method, and comprises an RS485 module 1, an RS485 control chip 2 and a data processor 3 as shown in FIG. 2;
the S485 control chip 2 is used for switching the RS485 module into a sending mode before the RS485 module is used for sending data, and switching the RS485 module into a receiving mode after the data is sent;
the data processor 3 is used for inquiring the register 30 at a set time interval in the data sending process and judging whether the data is sent completely; the data transmission device is also used for transmitting a command to the S485 control chip 2 to control the operation of the data transmission device before and after the data transmission;
by the method, when the RS485 serial port sends data, the register condition of the processor is continuously inquired, and the RS485 serial port is switched into the receiving mode when the data sending is finished, so that the condition that data packets are lost due to premature switching is avoided, extra hardware is added wirelessly, and the hardware cost is reduced.
Preferably, the mode switching of the RS485 module is realized by changing the high-low level state of a GPIO port of the RS485 control chip; the mode switching operation is simple, convenient and quick; the model of the RS485 control chip can be a conventional model.
Preferably, the data processor adopts an RK3568 chip, and the register is a UART LSR register; other processor chips and corresponding registers within the chip may be substituted, and simple alternatives based on this principle are within the scope of the present application.
A serial port receiving and transmitting terminal based on Android comprises a memory, a processor and a computer program which is stored in the memory and can run on the processor, wherein the steps of the method are realized when the processor executes the computer program.
A computer-readable storage medium, in which a computer program is stored, which, when being executed by a processor, carries out the steps of the method as described above.
It will be understood that modifications and variations can be made by persons skilled in the art in light of the above teachings and all such modifications and variations are intended to be included within the scope of the invention as defined in the appended claims.
Claims (9)
1. A serial port transceiving method based on Android is characterized by comprising the following steps:
the first step is as follows: before the RS485 module is used for sending data, the RS485 module is switched to a sending mode;
the second step is that: in the data sending process, inquiring a register in a processor for carrying out data sending processing at intervals of a set duration, and judging whether the data is sent completely;
the third step: and after the data transmission is finished, switching the RS485 module into a receiving mode.
2. The Android-based serial port transceiving method of claim 1, wherein the processor employs an RK3568 chip;
in the second step, the operation method of inquiring the register is as follows:
and inquiring a UART LSR register in the RK3568 chip at a set time interval.
3. The Android-based serial port transceiving method of claim 1, wherein in the first step, switching of the RS485 module to a sending mode operation is achieved by pulling up a GPIO port of the RS485 control chip.
4. The Android-based serial port transceiving method of claim 1, wherein in the third step, switching of the RS485 module to the receiving mode operation is achieved by pulling up a GPIO port of the RS485 control chip.
5. An Android-based serial port transceiving system for realizing the Android-based serial port transceiving method according to any one of claims 1 to 4, which is characterized by comprising an RS485 module, an RS485 control chip and a data processor;
the S485 control chip is used for switching the RS485 module into a sending mode before the RS485 module is used for sending data, and switching the RS485 module into a receiving mode after the data is sent;
the data processor is used for inquiring the register at a set time interval in the data sending process and judging whether the data is sent completely; and the S485 control chip is also used for sending an instruction to the S485 control chip before and after data is sent so as to control the operation of the S485 control chip.
6. The Android-based serial port transceiving system of claim 5, wherein switching of the mode of the RS485 module is achieved by changing the high and low level states of a GPIO port of the RS485 control chip.
7. The Android-based serial port transceiving system of claim 5, wherein the data processor employs a RK3568 chip, and the register is a UART LSR register.
8. An Android-based serial port transceiver terminal, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 4 when executing the computer program.
9. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111594821.9A CN114328336A (en) | 2021-12-24 | 2021-12-24 | Serial port transceiving method, system, terminal and storage medium based on Android |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111594821.9A CN114328336A (en) | 2021-12-24 | 2021-12-24 | Serial port transceiving method, system, terminal and storage medium based on Android |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114328336A true CN114328336A (en) | 2022-04-12 |
Family
ID=81012474
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111594821.9A Pending CN114328336A (en) | 2021-12-24 | 2021-12-24 | Serial port transceiving method, system, terminal and storage medium based on Android |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114328336A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117573214A (en) * | 2024-01-17 | 2024-02-20 | 深圳前海深蕾半导体有限公司 | Method and device for fusing serial device and Android system frame |
Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1649349A (en) * | 2005-02-04 | 2005-08-03 | 艾默生网络能源***有限公司 | RS485 communication interface conversion device |
CN202351862U (en) * | 2011-11-24 | 2012-07-25 | 深圳市宇泰科技有限公司 | Zero delay automatic transmit/receive switching circuit and device |
CN109062847A (en) * | 2018-07-31 | 2018-12-21 | 深圳职业技术学院 | System on chip, IP kernel and its control method for RS485 serial communication |
CN109313623A (en) * | 2017-11-15 | 2019-02-05 | 深圳配天智能技术研究院有限公司 | Switch the method and device of serial data transmission state |
CN109800201A (en) * | 2018-12-18 | 2019-05-24 | 珠海派诺科技股份有限公司 | The driving method of RS485 real-time tranception control based on linux |
CN111737180A (en) * | 2020-06-08 | 2020-10-02 | 湖北三江航天万峰科技发展有限公司 | Serial port driving system based on PCI bus |
CN112713910A (en) * | 2020-12-30 | 2021-04-27 | 重庆芯讯通无线科技有限公司 | Method, system, equipment and medium for switching RS485 receiving and transmitting states |
CN112765084A (en) * | 2021-04-06 | 2021-05-07 | 阿里云计算有限公司 | Computer device, virtualization acceleration device, data transmission method, and storage medium |
CN113515479A (en) * | 2021-05-19 | 2021-10-19 | 河南牧原智能科技有限公司 | Method, device, equipment and medium for controlling 485 receiving and transmitting direction switching |
-
2021
- 2021-12-24 CN CN202111594821.9A patent/CN114328336A/en active Pending
Patent Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1649349A (en) * | 2005-02-04 | 2005-08-03 | 艾默生网络能源***有限公司 | RS485 communication interface conversion device |
CN202351862U (en) * | 2011-11-24 | 2012-07-25 | 深圳市宇泰科技有限公司 | Zero delay automatic transmit/receive switching circuit and device |
CN109313623A (en) * | 2017-11-15 | 2019-02-05 | 深圳配天智能技术研究院有限公司 | Switch the method and device of serial data transmission state |
CN109062847A (en) * | 2018-07-31 | 2018-12-21 | 深圳职业技术学院 | System on chip, IP kernel and its control method for RS485 serial communication |
CN109800201A (en) * | 2018-12-18 | 2019-05-24 | 珠海派诺科技股份有限公司 | The driving method of RS485 real-time tranception control based on linux |
CN111737180A (en) * | 2020-06-08 | 2020-10-02 | 湖北三江航天万峰科技发展有限公司 | Serial port driving system based on PCI bus |
CN112713910A (en) * | 2020-12-30 | 2021-04-27 | 重庆芯讯通无线科技有限公司 | Method, system, equipment and medium for switching RS485 receiving and transmitting states |
CN112765084A (en) * | 2021-04-06 | 2021-05-07 | 阿里云计算有限公司 | Computer device, virtualization acceleration device, data transmission method, and storage medium |
CN113515479A (en) * | 2021-05-19 | 2021-10-19 | 河南牧原智能科技有限公司 | Method, device, equipment and medium for controlling 485 receiving and transmitting direction switching |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117573214A (en) * | 2024-01-17 | 2024-02-20 | 深圳前海深蕾半导体有限公司 | Method and device for fusing serial device and Android system frame |
CN117573214B (en) * | 2024-01-17 | 2024-04-19 | 深圳前海深蕾半导体有限公司 | Method and device for fusing serial device and Android system frame |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108494414B (en) | Ultra-low power consumption multimode wireless module of internet of things | |
US5778309A (en) | Gain adjustment method in two-way communication systems | |
US20090137276A1 (en) | Simultaneous interface use | |
US20210176810A1 (en) | Method and device for reconnecting bluetooth communication | |
EP1578154A4 (en) | Information processing apparatus, devices thereof, and communication device | |
CN111835458B (en) | Information transmission and receiving method, terminal and network side equipment | |
CN104469905A (en) | Method and system for reducing idle power consumption of NFC chip | |
EP2852101A1 (en) | Method and device for data transmission in wireless local area network | |
US20210075451A1 (en) | Dual Processor Power Saving Architecture Communications System | |
CN114328336A (en) | Serial port transceiving method, system, terminal and storage medium based on Android | |
CN105323837A (en) | Intermittent networking method and system | |
KR20040076730A (en) | Serial communication interface apparatus of hybrid type adaptable to high peformance wireless lan and method of the same | |
JP2021170840A5 (en) | ||
CN114055468B (en) | Track reproduction method, track reproduction system and terminal equipment | |
US6317425B1 (en) | Data synchronizing method for radio multi-terminal communications system | |
US20200285781A1 (en) | Terminal and communication method | |
CN109800201B (en) | Driving method for RS485 real-time receiving and transmitting control based on linux | |
CN108920403B (en) | Control method and device based on MCU serial port communication | |
CN101430671B (en) | Mobile terminal peripherals coexisting apparatus | |
CN109889226B (en) | RTX-based bidirectional communication software radio implementation device and method | |
CN111065078B (en) | System for realizing connection of intelligent POS (point of sale) and wireless base based on WIFI (Wireless Fidelity) and Bluetooth | |
CN113196864B (en) | Method and apparatus for discontinuous reception | |
CN109561416A (en) | A kind of method and terminal reducing Bluetooth communication power consumption | |
CN114844524B (en) | Communication control method, terminal and storage medium | |
CN112423004B (en) | Video data transmission method, device, transmitting end and storage medium |
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 |