VC ++ serial port in Win95 interface

zhaozj2021-02-11  197

Practical Skills Win95 Interface VC Serial Communication Procedure Nanjing Petroleum Probe Research Institute Wu Fenghua ---- Microsoft Visual C is known as its interface, due to its simple, 32-bit object-oriented programming and Activate X flexibility It is favored by the majority of computer developers and is widely used in various fields. How to use VC to enter the serial number of serial ports, this is a basic function. It is especially in real time monitoring, the entire production process of large-scale devices, the serial programming of VC is especially important. I have participated in the real-time monitoring system, which wrote a non-legal frequency paragraph, and the mixture was mixed with autonomous production control system. A little experience in your next face will share with readers. ---- Serial port communication without using two ways: First, use Windows communication API functions, second, using VC (or its language) standard communication function _inp, _outp to real. ---- WINDOWS API function is widely used, but has a fixed difficulty than compared to more complex, it is simple to describe, and its programming is divided into initial schitches, configured serial ports, timeout control, data transmission, shutting off the string, etc. ---- VC serial communication ---- First, initialize the serial communication port ---- Before the computer serial port is communicating, the communication parameters of the monitoring device must be agreed to the communication methods of both parties, including the baud rate setting. , The establishment of the parity check and stop bit. Determine the data transmission frame format to determine the UART operating method. Write the operation of the line control register and the wave pyroelectronic register and the M0DEM register. ---- First, determine the computer's communication port address is 3F8 or 2F8 (according to the different requirements of the user, there is 3E8, 2E8, even using multiple user cards, 3220, 3228, 4220, 4228, 5220, 5228 The example is a port address with 2F8. The proportional rate is set to 9600 using _outp (port, 0x30) (_ OUTP (port, 0x30) sets the wave magnetization to 2400, _outp (port, 0x18) set the wave magnet at 4800).

---- Data transmission format is determined by address port 3, such as selecting seven-bit stop bit check, two statements in OUTP (Port 3, 0x3a) and OUTP (Port 3, 0x1a); Outp (port 3, 0x3a) and OUTP (Port 3, 0x3A) and OUTP (Port 3, 0x3A), and OUTP (Port 3, 0x03) are adopted; as for the books on asynchronous communication data formats. ---- Second, check the sending process ---- Just the CPU detected that the UART deliverer holding the register is empty, ie, output a character to the UART. The first output of RTS and DTR first output RTS and DTR, detect the Modem register, only the CTS, DSR is effective, and the CPU is output to UART. ---- Third, check the receipt process ---- Just the CPU detects the UART receiver data ready to read the character from the receiver data register. The first output of the receiver first outputs the data terminal (DTR = 1), then detects the Modem-state register, only DSR = 1, the CPU receives a character. ---- Circular Example ---- For the program, I put the serialization of the serial number in real-time monitoring process, serial port, serial delivery, etc. in the form of a sub-program. Determine the address address: int port = 0x2f8; receive character subscription:

Char Near ReadByte (Void)

{

INT TIME_LIMIT;

CHAR STA;

TIME_LIMIT = 5000;

While (sta = INP (port 5) & 0x01)! = 1)

{TIME_LIMIT -;

IF (Time_Limit == 0) {

/ * Printf ("s =% 4xm", STA); * / return 0;

}

Return INP (Port);

Printf ("% s", INP (port));

}

Send character subscription:

Void Sendbyte (unsigned char sdata)

{

Long Int Time_Limit;

Time_limit = 50000;

While ((INP (Port 5) & 0xF0)! = 0x60)

{TIME_LIMIT -;

IF (Time_Limit == 0) Break;

}

OUTP (Port, SDATA);

}

Series initialization subscription:

Void Init_com (port)

{

Char i;

OUTP (Port 3,0x80);

OUTP (port, 0x0c); / * baud Rate 9600 * /

OUTP (Port 1, 0);

/ * 8bit 1stop no even * /

OUTP (port 3, 0x3a);

OUTP (port 3, 0x03);

I = INP (Port 5) & 0xfe;

OUTP (port 5, i);

}

String Subpanuk Sequence:

Void SendStrn (Char * Mess)

{

For (; * message; mess )

SendByte (* message);

Sendbyte (0x0D);

/ * Sendbyte (0x0a); * /

}

Simple main program:

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"

转载请注明原文地址:https://www.9cbs.com/read-4073.html

New Post(0)