Chapter v. Hardware Interface Programming C++ CLI
Chapter v. Hardware Interface Programming C++ CLI
Hà Nội, 2018 1
Chapter V. Hardware Interface Programming
❖ 1. Introduction
❖ 2. Serial Port
❖ 3. Read Data
❖ 4. Send Data
❖ 5. Real-Time Data Transfer
❖ 6. Digital Image Processing
2
1. Introduction
➢ The CPU socket on the motherboard determines which CPU chips can be
used in the computer.
➢ Peripheral cards, such as a high-end graphics cards, plug into the bus on
the motherboard. The most common buses are PCI and PCI Express.
https://www.pcmag.com/encyclopedia/term/51988/standards-hardware-interfaces 3
1. Introduction
❖ The most widely used hardware interface for attaching external devices to
computers is USB. It connects printers, cameras, music players, flash drives
and auxiliary hard and optical drives.
❖ The GPIB IEEE 488 standard is used for process control instruments.
https://www.pcmag.com/encyclopedia/term/51988/standards-hardware-interfaces 4
2. Serial Port
5
2. Serial Port
6
2. Serial Port
SerialPort(String^, Int32, Parity, Initializes a new instance of the SerialPort class using the
Int32) specified port name, baud rate, parity bit, and data bits.
SerialPort(String^, Int32, Parity, Initializes a new instance of the SerialPort class using the
Int32, StopBits) specified port name, baud rate, parity bit, data bits, and stop bit.
7
2. Serial Port
CanRaiseEvents Gets a value indicating whether the component can raise an event. (Inherited from Component)
CDHolding Gets the state of the Carrier Detect line for the port.
Container Gets the IContainer that contains the Component. (Inherited from Component)
DataBits Gets or sets the standard length of data bits per byte.
DesignMode Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component)
DiscardNull Gets or sets a value indicating whether null bytes are ignored when transmitted between the port and the receive buffer.
DsrHolding Gets the state of the Data Set Ready (DSR) signal.
DtrEnable Gets or sets a value that enables the Data Terminal Ready (DTR) signal during serial communication.
Encoding Gets or sets the byte encoding for pre- and post-transmission conversion of text.
Events Gets the list of event handlers that are attached to this Component. (Inherited from Component) 8
2. Serial Port
IsOpen Gets a value indicating the open or closed status of the SerialPort object.
NewLine Gets or sets the value used to interpret the end of a call to the ReadLine() and WriteLine(String) methods.
ParityReplace Gets or sets the byte that replaces invalid bytes in a data stream when a parity error occurs.
PortName Gets or sets the port for communications, including but not limited to all available COM ports.
ReadTimeout Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish.
ReceivedBytesThreshold Gets or sets the number of bytes in the internal input buffer before a DataReceived event occurs.
RtsEnable Gets or sets a value indicating whether the Request to Send (RTS) signal is enabled during serial
communication.
Site Gets or sets the ISite of the Component. (Inherited from Component)
WriteBufferSize Gets or sets the size of the serial port output buffer.
WriteTimeout Gets or sets the number of milliseconds before a time-out occurs when a write operation does not finish.
9
2. Serial Port
Dispose() Releases all resources used by the Component. (Inherited from Component)
Dispose(Boolean) Releases the unmanaged resources used by the SerialPort and optionally releases the managed resources.
Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object)
ReadChar() Synchronously reads one character from the SerialPort input buffer.
Reads all immediately available bytes, based on the encoding, in both the stream and the input buffer of
ReadExisting()
the SerialPort object.
ReadLine() Reads up to the NewLine value in the input buffer.
Write(Char[], Int32, Int32) Writes a specified number of characters to the serial port using data from a buffer.
WriteLine(String) Writes the specified string and the NewLine value to the output buffer. 11
2. Serial Port
DataReceived Indicates that data has been received through a port represented by
the SerialPort object.
PinChanged Indicates that a non-data signal event has occurred on the port
represented by the SerialPort object.
12
2. Serial Port
13
2. Serial Port
14
2. Serial Port
15
2. Serial Port
16
2. Serial Port
17
2. Serial Port
18
2. Serial Port
19
2. Serial Port
20
3. Read Data
21
3. Read Data
22
4. Send Data
23
4. Send Data
24
4. Send Data
// grab text and store in send // grab text and store in send
buffer buffer
String^ message = "ON"; String^ message = "OFF";
// write to serial // write to serial
if (this->serialPort1->IsOpen) if (this->serialPort1->IsOpen)
this->serialPort1- this->serialPort1-
>Write(message); >Write(message);
else else
this->textBoxSendData->Text = this->textBoxSendData->Text =
"Port Not Opened"; "Port Not Opened";
25
4. Send Data
26
4. Send Data
27
4. Send Data
28
5. Real-Time Data Transfer
29
5. Real-Time Data Transfer
31
5. Real-Time Data Transfer
32
5. Real-Time Data Transfer
❖ Timer
▪ Example: Read and Display Temperature
• C++/CLI Code
33
5. Real-Time Data Transfer
❖ Timer
▪ Example: Read and Display Temperature
• C++/CLI Code
34
5. Real-Time Data Transfer
❖ Timer
▪ Example: Read and Display Temperature
• C++/CLI Code
35
5. Real-Time Data Transfer
❖ Multithreading
▪ Example: Read and Display Temperature
• C++/CLI Code
36
5. Real-Time Data Transfer
❖ Multithreading
▪ Example: Read and Display Temperature
• C++/CLI Code
37
5. Real-Time Data Transfer
❖ Multithreading
▪ Example: Read and Display Temperature
• C++/CLI Code
38