Connect the VC ++ serial port in Win95

Source: Internet
Author: User
 

Practical Skills

Research Institute of Nanjing jingshi oil and Material Research on VC ++ serial port communication in Win95
Wu FengHua

---- Microsoft Visual C ++ is named by its open and open nature, because of its simplicity and ease of learning, the 32-bit path programming for the object, and the flexibility of activate X, it is favored by the developers of large-scale computing machines, widely used in various domains. How to Use VC ++ to establish the communication program of the serial port is a basic function. This is the whole production process control system for real-time monitoring and small-sized backup, the serial port programming of VC ++ is especially important. I have participated in and compiled the Real-time Monitoring and Control System for Non-Linear Frequency segments, and the hybrid Soil Mixing self-dynamic production control system. The lower part of the experience will be shared with the reader.

---- In general conditions, there are no two methods for intercommunication: one is to use the number of API calls of windows, the second is to use VC ++ (or its language) to implement the quasi-Communication Letter Number _ p and _ outp.

---- Although the number of API functions in Windows is widely used, the complexity is fixed by the complexity, the programming process is divided into the initial string port, configuration string port, ultra-time control system, data transmission, and closed string port.

---- Connect through VC ++

---- 1. initialize the communication interface

---- Before passing through the serial port of the computing machine to send a message, it is necessary to have the parameter number in the data monitoring and control system, determine the two-party communication method, including the setting of wave rate, odd-even verification, and the setting of stop bit. Determine the frame type of data transmission, and determine the UART operation method. One-to-one line channel control memory generator, wave rate sub-memory generator and m0dem memory generator write operation.

---- Determine whether the access address of the computer is 3f8 or 2f8 (the root user needs different requirements, and the cards can be inserted with 3e8 and 2e8, in this example, 2f8 is used as the end port address. Use _ outp (port, 0x0c) to set the wave rate to 9600, and (_ outp (port, 0x30) to 2400, _ outp (port, 0x18) sets the wave rate to 4800 ).

---- The data transmission format is determined by the address port + 3. If you choose to use seven-digit, one-stop, and one-stop parity verification, you can use outp (Port + 3, 0x3a) and outp (Port + 3, 0x1a). If you choose to use an eight-digit, one-stop-and-stop-position without ODD-even correction, you can use outp (Port + 3, 0x3a) and outp (Port + 3, 0x03). Why, you can take the test on the books in the data format of the Cross-step communication.

---- 2. query and send the stream process

---- You only need to check and test the CPU to the UART sender to ensure that the sender is empty, that is, to input a character to the UART. The sender first enters the RTS and DTR, and checks the modem storage device. Only the CTS and DSR that are received in Dec are valid, the CPU sends a text delivery character to the UART.

---- 3. query the receiving process

---- You only need to check and test the CPU to obtain the data quasi-standby mode of the UART Receiver, that is, you can read a word character from the data sender of the receiver. The receiving party first enters the final end of the data and has an effect (DTR = 1). Then, it checks and tests the modem-state storage device, only the DSR = 1, the CPU receives one character.

---- Process example

---- For the programming party, I present sub-steps in the form of starting, receiving, and sending of serial ports in the real-time monitoring and control process.

Confirm the location of the Communication Port: int Port = 0x2f8; suborder of the receiving character: Char near readbyte (void) {int time_limit; char sta; time_limit = 5000; while (STA = Indium (Port + 5) & 0x01 )! = 1) {time_limit --; If (time_limit = 0) {/* printf ("s = % 4xm", Sta); */return 0 ;}} return Indium (port); printf ("% s", Indium (port);} send a letter sub-order: void sendbyte (unsigned char sdata) {long int time_limit; time_limit = 50000; while (Indium (Port + 5) & 0xf0 )! = 0x60) {time_limit --; If (time_limit = 0) break;} outp (port, sdata);} initial sub-process sequence of the string port: void init_com (port) {char I; outp (Port + 9600x80); outp (port, 0x0c);/* baud rate */outp (Port + ); /* 8bit 1 stop no even */outp (Port + 3, 0x3a); outp (Port + 3, 0x03); I = Indium (Port + 5) & 0xfe; outp (Port + 5, I);} substring sending sub-sequence: void sendstrn (char * mess) {for (; * mess; mess ++) sendbyte (* mess); sendbyte (0x0d);/* sendb Yte (0x0a); */} Master route of the simple Ticket: init_com (ox2f8); sendstrn (port, "func"); j = 0; line = 0; do {for (I = 0; I <25; I ++) ttemp [I] = "/0"; if (readbyte (port) = "= 'M ') "{I =" 0; "do {ttemp [I] =" readbyte (port); "I ++;} while (ttemp [I-2]! = "13) & (ttemp [I-1]! = 10); "line ++; dcqd. textout (450, line * 20 + 180, ttemp);} J ++;} while (j <1000) & (line <5); wed, 16 Sep 1998 "acejet" <cejet@public1.ptt.js.cn>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.