Chapter 12 programming examples, Com port communication program, Chapter 12 – Solvline PB2xxxUG User Manual
Page 91: Programming examples
![background image](/manuals/711383/91/background.png)
Programming Examples
This chapter describes three application programs that communicate through COM ports, TTY ports and
sockets to help the user develop a PC based application using Portbase.
1. COM Port Communication Program
COM port communication is most generally used serial communication way in the Windows
environment.
1)
Function Description
CreateFile() -------------- Create a communication port.
|
GetCommState() ------------ Get the speed, byte spec of the open communication port.
|
SetCommState() ------------ Set the speed, spec of the open communication port.
|
ReadFile(), WriteFile() --- Read or write data from the open communication port.
|
CloseHandle() ------------- Close the open communication port.
2) Result
Application repeatedly transmits “This is LoopBack Data!” through the COM3 port at 3 second
intervals and displays data from COM3 on screen.
3) How to Run
12
Plug the loopback connector to the first serial port of Portbase.
Run Redirector and select Portbase to register the first serial port as COM3.
(Refer to Chapter 6 COM Port Redirection.)
If you run the program, the following screen appears and “This is LoopBack Data!“ is
repeatedly displayed on the edit box at 3 sec. Intervals.
91