Application of communication between PC and multiple single-chip computers based on VB6

Publisher:张延强Latest update time:2012-11-23 Source: 21ic Keywords:VB6 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the warehouse management system, the traditional method is to use detection equipment such as hygrometers and bimetallic measuring instruments for manual measurement, and then ventilate, dehumidify, and cool down the warehouses that do not meet the temperature and humidity requirements. This manual method is inefficient, has large errors, and random events are difficult to predict, so the quality of warehouse management cannot be well guaranteed. The system discussed in this article is a monitoring and management system for pharmaceutical factory warehouses. In addition to supervising and controlling the lower computer (MCS-51 single-chip microcomputer), the upper computer (PC) is also used to collect data transmitted by the lower computer for database management. In addition, the upper computer can also manage the warehouse drug entry, exit, validity period, transaction method and other information, and can be queried in the form of real-time curves and reports. The lower computer (MCS-51 single-chip microcomputer. We call the MCS-51 single-chip microcomputer and its peripheral equipment the warehouse computer) is responsible for collecting information such as temperature, humidity, smoke, etc. in the warehouse and transmitting it to the upper computer. This system allows office workers to monitor and manage warehouses hundreds of meters away while sitting in their offices. It not only frees office workers from heavy physical labor, but also makes warehouse management fast and accurate, improving the management level and office automation level of the enterprise.

2 System composition and working principle

The PC is installed with a warehouse management system written in VB6 as the front-end operating system. The database format of the system adopts the VB database format, also known as the local database. This type of database file uses the same format as MicroSoft Access. The data access uses the ADO control of VB6 through the MicroSoft Jet (Joint Engineering Technology) database engine, which is fast and efficient. This management system includes inquiries on incoming drugs, incoming dates, outgoing drugs, outgoing dates, and persons in charge, as well as reminders of expired drugs. In addition, the data transmitted from the warehouse machine is displayed in real time and stored in the local hard disk for query and printing. The background system is a communication system between a host computer and multiple slave computers. Multiple slave computers continuously collect temperature, humidity, smoke and other data from the warehouse and transmit them to the host computer. The PC displays them in real time and can set temperature, humidity, smoke and other parameters. The single-chip microcomputer controls the dehumidification, cooling and alarm systems in the warehouse according to the set parameters, so that the warehouse reaches the predetermined environment. If the environment in the warehouse does not match the set environment, the single-chip microcomputer will wake up the cooling and dehumidification equipment and lock the parameters in the warehouse within the predetermined range. If there is an accident such as fire or theft, the single-chip microcomputer will drive the fire and anti-theft alarm system and transmit the signal to the host computer for display on the screen.



3 Communication between PC and MCU

3.1 Implementation of communication method

Communication between PC and MCU is realized through serial port (as shown in Figure 2). Since the MCU system level is TTL level, which is incompatible with RS-232C, and considering the communication distance, we use Max485 chip produced by Maxim to convert TTL level into RS-485 standard, and then convert between RS-485 and RS-232, and then connect to the serial port of PC. This conversion method extends the communication distance, up to 1200 meters, and improves the feasibility of the system.

3.2 Communication protocol and program design ideas

Since this system consists of one host computer and multiple slave computers, a communication code must be set for the slave computer. For simplicity, any four between 0 and 255 can be used. When the PC wants to communicate with a single-chip computer, it sends a communication code to all single-chip computers. After receiving the code, the microcontroller checks it with its own code. If they are consistent, it responds to the PC and starts communication. Other microcontrollers continue to collect and transmit data.



3.3 Host Computer Programming

There is a control in VB6 specifically used for serial communication - the MSComm control. The most commonly used properties of the MSComm control are as follows:

CommPort property: sets and returns the communication port number, specifies the serial port used for communication on the PC

Setting property: sets and returns the baud rate, parity, data bits, and stop bits in the form of a string

PortOpen property: sets and returns the status of the communication port, used to open and close the port

Rthreshold property: The MSComm control sets the CommEvent property to ComEvReceive and generates OnComm before setting and returning the number of characters to be received

Input property: returns and deletes characters from the receive buffer, used to receive data

InputLen property: sets and returns the number of characters read from the receive buffer by the Input property

Output property: writes a character to the buffer, used to send data [page]

The VB6 communication initialization program for this system is as follows:

MSComm1.CommPort = 1; select COM1 as the communication port

MSComm1.Setting ="9600,n,8,1"; set the baud rate to 9600, no parity, 8 data bits, and one stop bit

MSComm1.OutBuffersize = 256 ;Set the output buffer size to 256 bytesMSComm1.RThreshold

= 3;When there are 3 characters in the input buffer, trigger the OnComm eventIf

Not MSComm1.PortOpen = True

Then MSComm1.PortOpen = True;Open the serial port and prevent the error of opening the same serial port at runtimeEnd

IfThe

above MSComm1 is the name (Name) of the system default MSComm control. After initialization,

send data through MSComm1.Output=OutputString, and OutputString is a defined character variable (Dim OutputString As String). Generally, the Timer event of the timer is used to send data regularly, and the timer is turned off after receiving the response character. The MSComm control can directly convert the string into binary data and send it, without us using algorithms to convert it in the program. It is best to close the serial port after each transmission. Use MSComm1.PortOpen=False to achieve this. The MSComm_OnComm event can capture errors that occur during communication and can also receive data. Since the attribute value of RThreshold is 3, when the input buffer is full of three characters, the MSComm_OnComm event is triggered. By judging the received characters, the direction of the main program branch can be determined.



3.4 Lower computer program design

When the single-chip microcomputer MCS-51 of this system communicates, timer T1 is used in timing mode 2 as a frequency generator, and a crystal oscillator of 11.0592 is selected. Since the baud rate is 9600, the initial value of timer T1 is 0FDH. Initialization also requires setting the control status register SCON used to control and monitor the serial port status. The initialization program is as follows:

MOV SCON, #0C0H; Communication mode 3

MOV PCON, #00H; SMOD=0

MOV TMOD, #20H; Timer T1, working in mode 2

MOV TL1, #0FDH; Set the baud rate to 9600 MOV TH1

, #0FDH

The single-chip microcomputer is always in a passive state, and only enters the interrupt service subroutine to send data and enter the communication state after receiving the communication command. When the PC communicates with the MCU, it first sends a call signal. After receiving the agreed call signal, the MCU sends a response signal to the PC, indicating that it is ready to receive. After receiving the response signal, the PC sends a communication code. The MCU receives the communication code and subtracts it from its own code. If it is 0, it starts to accept commands and set new parameters; if it is not 0, it continues to execute the program of collecting and sending data.

3.5 Design of the library machine

The design of the library machine is based on the MCU, equipped with EPROM, A/D conversion, digital display, photoelectric isolation and control circuits. The sensor converts non-electrical quantities such as temperature and humidity into electrical quantities, which are converted into digital quantities through A/D conversion, and then sent to the PC database for storage through the serial communication of the MCU. At the same time, the MCU compares the collected results with the set parameters. If it is not within the specified parameter range or the state quantity collected by the MCU is abnormal, the photoelectric isolation amplifier is driven. After a first-level amplification, the relay can be driven to open the cooling, dehumidification equipment and alarm system. Here, photoelectric isolation can effectively avoid the false operation of the relay and improve the anti-interference ability of the system.


4 Conclusion

The management and monitoring system introduced in this paper is based on the master-slave communication structure of VB6, which has good reliability and strong feasibility. Its hardware structure is simple, the software (VB6) programming environment is friendly, the interface is flexible, and it is easy to learn and use. This system can easily control the selection of communication objects, display the collected data in real time, and the human-computer dialogue is flexible and easy to operate. The application of this serial communication technology between the single-chip microcomputer and the database provides a new direction for the development of warehouse management.

Keywords:VB6 Reference address:Application of communication between PC and multiple single-chip computers based on VB6

Previous article:Temperature and humidity automatic detection system composed of AT89C51/55
Next article:Design of low power consumption and high precision snow melting measuring instrument based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 19:54

PC Future: How will 5G connectivity drive the shift from traditional laptops to mobile PCs?
In 2021, we are welcoming the accelerated popularization of 5G. 5G will accelerate the birth of more terminal innovations and applications, and empower a wider range of industries. On this occasion, Alex Katouzian, senior vice president and general manager of mobile, computing and infrastructure business of Qualcomm T
[Embedded]
PC Future: How will 5G connectivity drive the shift from traditional laptops to mobile PCs?
AMD launches the world's first 7nm professional-grade PC workstation graphics card
AMD announced the launch of the world's first 7nm professional-grade PC workstation graphics card, the AMD Radeon™ Pro W5700. It provides new levels of performance and advanced features that enable 3D designers, architects and engineers to visualize, check and interact with their designs in real time, greatly accelera
[Embedded]
AMD launches the world's first 7nm professional-grade PC workstation graphics card
Design of digital voltmeter based on PC
  Digital voltmeters have been designed and developed in many types and styles. Traditional digital voltmeters have their own characteristics. They are suitable for manual measurement on site. To complete remote measurements and further analyze and process the measurement data, traditional digital voltmeters cannot co
[Test Measurement]
Design of serial communication between DSP and PC
1 Introduction DSP is the abbreviation of both Digital Signal Processing and Digital Signal Processor. The former refers to the theory and method of digital signal processing, while the latter refers to the programmable microprocessor used for digital signal processing. The TMS320F240 series is a fixed-poin
[Embedded]
A big change for automotive chips? The PC/mobile phone camp "fights" for the "throne" of the next-generation smart cockpit
The battle for future chips for automobile intelligence is entering a new cycle. Among them, compared with autonomous driving, smart cockpits are changing faster and the pattern is more uncertain. This week, at the CES show in the United States, Intel officially announced that it will launch a series of AI-enhanced
[Automotive Electronics]
SPCE061A single chip collects voice signals and transmits them to PC for analysis
introduction With the continuous improvement of the integration level of single-chip microcomputers, modern single-chip microcomputers have digital signal processing functions, making it possible to implement voice signal processing with single-chip microcomputers. SPCE061A, a product launched by Taiwan Lingyan
[Microcontroller]
Circuit Enables PC-Based Voltage Measurement
Abstract: In its simplest form, the PC voltmeter consists of a 4-channel, 10-bit A/D converter (IC2) with a few passive components, connected to the PC printer port via a 25-pin male D-type connector. In its simplest form, the PC voltmeter of Figure 1 consists of section "A" alone: a 4-channel, 10-bit A/D converter
[Power Management]
Circuit Enables PC-Based Voltage Measurement
Zhongke Microcommunication's 5G NR small base station based on Picotech PC802 baseband SoC passes the operator's live network test
Zhongke Microcommunication's 5G NR small base station based on Picotech PC802 baseband SoC passes the operator's live network test The operator's live network test fully verified that the PC802 PHY SoC and the 5G small base station developed based on it have the commercial deployment and delivery
[Network Communication]
Zhongke Microcommunication's 5G NR small base station based on Picotech PC802 baseband SoC passes the operator's live network test
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号