Windows is the host machine, and Linux is installed in the vmwarevm. You can also write a program in Linux to send messages to the serial port. The same principle is to use the virtual serial port software vspm to connect com3 to com4 and then capture it through the serial port debugger. The following is a C sample code for the serial program in Linux.
The use and download of vspm with reference to the "one of the serial programming: virtual serial port vspm to solve the serial Programming Problem" http://blog.csdn.net/zh405123507/article/details/7424877
Serial programming VB code please refer to the serial programming two: VB send serial data http://blog.csdn.net/zh405123507/article/details/7424889
Take Ubuntu command line mode as an example to configure the hardware of the Virtual Machine Under VMware. Select Add serial port hardware and use the physical serial port of the local machine. Select according to the serial port list. (It seems that only com3 is available)
Open the "virtual serial port interconnection plug-in" directory under the vspm folder and set vspm. INI copies the file to the vspm home directory and overwrites the original configuration file to connect com3 and com4 at the next startup, so that the program can capture the output of com4 in windows, that is, the input of com3 in Virtual Machine Linux.
It doesn't matter if the serial port you allocate to the virtual machine is not com3. The last four lines of the vspm. ini file are as follows:
COM3=127.0.0.1:7102;127.0.0.1:7101;Active;UDP_BCCOM4=127.0.0.1:7101;127.0.0.1:7102;Active;UDP_BCCOM5=127.0.0.1:7202;127.0.0.1:7201;Active;UDP_BCCOM6=127.0.0.1:7201;127.0.0.1:7202;Active;UDP_BC
The four ports are connected to each other (the first and second rows are connected, and the third and fourth rows are connected ). Therefore, you can modify the numbers after com to achieve the desired effect.
If you have set VMware and vspm, you can start the virtual machine to start testing. Now start the Serial debugger for Linux and Windows respectively under VMware.
Now, enter the command in Ubuntu (or other Linux console, the command is common)
echo hello > /dev/ttyS0
If "hello" is displayed in the Receiving Window of the serial port debugger, you can write a program to debug the virtual serial port of VMware Linux.
Below is a simple Linux C serial port program:
# Include <termios. h> # include <stdio. h> # include <stdlib. h> # include <unistd. h> # include <fcntl. h> # include <sys/signal. h> # define false 0 # define true 1int main () {volatile int stop = false; volatile int FD; /* Open the serial port */FD = open ("/dev/ttys1", o_rdwr) in a way similar to reading and writing files; If (-1 = FD) {perror ("error prompt! ");}/* Set the serial port parameter */struct termios OPT; tcgetattr (FD, & OPT); cfsetispeed (& OPT, b19200); // receives the baud rate cfsetospeed (& OPT, b19200); // send the baud rate tcsetattr (FD, 1, & OPT); OPT. c_cflag & = ~ Parenb; opt. c_cflag & = ~ Cstopb; opt. c_cflag & = ~ Csize; opt. c_cflag | = ~ Cs8;/* start to send data to fd */INT c = '0'; printf ("send data \ n"); While (stop = false) /* modem input handler */{C ++; C % = 255; write (FD, & C, 1);/* stdout */usleep (100000 );} return 0;}/* need to write another function to capture keyboard input so that stop = false, Send stop */
After compilation, the program output is as follows:
==========================================
From: http://blog.csdn.net/zh405123507