Serial Port 1.0 beta
|
A simple test of serial port writing data to the port. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include "debug-msg.h"
#include "serialport.h"
Functions | |
void * | write_port_thread (void *argc) |
void * | read_port_thread (void *argc) |
void | sig_handle (int sig_num) |
int | main (void) |
Variables | |
pthread_t | write_tid |
pthread_t | read_tid |
char * | buf = "Are you going to die? " |
char | tmp [512] |
Detailed Description
A simple test of serial port writing data to the port.
Copyleft (C) 2010 Late Lee This program is tested on LINUX PLATFORM, WITH GCC 4.x. The program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. Please feel free to use the program, and I feel free to ignore the related issues. Any questions or suggestions, or bugs, please contact me at <$ echo -n "aHR0cDovL3d3dy5sYXRlbGVlLm9yZwo=" | base64 -d> or e-mail to <$ echo -n "bGF0ZWxlZUAxNjMuY29tCg==" | base64 -d> if you want to do this.
- Date:
- Mon Jan 10 2011
- Test:
- To compile the program, type
gcc main.c serialport.c -lthread
,then it will generate the executable binarya.out
. To run it, type./a.out
.Make sure you have the permission to open the serial port.
You can start a ternimal and typeminicom
(also make sure you can open the device). When everything is OK, you can see the data in minicom using the same port if you connect pin 2 & pin 3 of the port (the male connector, see the picture below)(but I don't know the reason, isn't it blocked?).
If you want to stop the program, just use 'Ctrl+c'.
Here are snapshots of the program:

Writing to the port...

Reading the data in minicom...
And here comes the serial port connector:

A 9-pin male D-Sub connector(*)

A 9-pin female D-Sub connector
(*)We use this connector in the test.
Function Documentation
void* read_port_thread | ( | void * | argc | ) |
read_port_thread - Thread that reads data from the port
- Parameters:
-
argc : Here means the port(specified by the fd).
- Note:
- This function has not tested yet.
void sig_handle | ( | int | sig_num | ) |
sig_handle - Handle the INT signal.
- Parameters:
-
sig_num : The signal.
- Note:
- This function is not used.
void* write_port_thread | ( | void * | argc | ) |
write_port_thread - A thread that writes data to the port
- Parameters:
-
argc : Here means the port(specified by the fd).
- Note:
- This is only a test, not the real one.
Variable Documentation
char* buf = "Are you going to die? " |
The data we write to the port.
pthread_t read_tid |
read thread
char tmp[512] |
data we receive
pthread_t write_tid |
write thread
Generated on Tue Jan 18 2011 13:43:21 for Serial Port by
