User Tools

Site Tools


Sidebar

Network and communication

k24:k24.1:k24.1.5:k24.1.5.2:start

24.1.5.2 RS232 terminal projects

Two RS232 terminal projects are presented to you. It has proved advantageous for the authors to use the terminal projects as a starting point for application programs with the serial RS232 interface, in which they are adapted, extended or specialized.

24.1.5.2.1 Terminal project 1

The first project is an extensively tested and fully functional example for the use of Gambas for serial (RS232) communication. The source code is licensed under the Creative Common License and can be adapted as a basis for own applications. The following characteristics characterize the project:

  • Check if the user is a member of the group 'dialout' and therefore has the permission to use serial interfaces.
  • Provision of a list of (real) serial interfaces recognized on the PC, including RS232-USB adapters.
  • The communication parameters such as baud rate or number of stop bits can be changed in dialog.
  • Together with the selected interface, the current communication parameters are displayed in two fields.
  • Only two options are available for data flow control: Hardware flow control (On) or no flow control (Off).
  • The set communication parameters are automatically saved and are available again at further program starts.
  • (ASCII) texts can be transmitted.
  • Incoming text is displayed in a separate control. Optionally, control characters present in the text can be displayed marked.
  • The status of selected control lines is displayed in the dialog for configuring the serial interface.
  • When starting the program, the window positions and the window size are automatically restored.

BILD 1

Figure 24.1.5.2.1: Dialog for configuring the serial interface

BILD 2

Figure 24.1.5.2.2: Sending text

24.1.5.2.2 Terminal project 2

The second project is based on project 1 and does without a separate dialog for setting the transfer parameters. It is integrated into the main window. No settings of the serial interface and window positions are saved. There are some enhancements in the functional scope:

  • ASCII texts and texts (UTF-8 encoding) can be sent and received.
  • Two texts are available for tests (ASCII and UTF-8).
  • The display has the options to display the text in the original or in hexadecimal, decimal or binary form. Selected control characters are highlighted.
  • Only two options are available for data flow control: Hardware flow control (H - On) or no flow control (N - Off).
  • You can specify which character should be sent as last character (Newline at ..).
  • The contents of the two text fields RxD and TxD can be deleted.

BILD 3

Figure 24.1.5.2.3: Sending ASCII text

The source code section for displaying received text is interesting if it is utf8-encoded. The basis of the conversion is the understanding of how characters are encoded in Unicode - with the subset UTF8. The following pages describe this coding in a very understandable way:

The complete source code for both terminal projects can be found in the download area.

24.1.5.3 RS232 project

The attached project for the long-term measurement of temperatures is a project that has been developed in its current version on the basis of the two presented RS232 terminal projects. The special feature of this project is that control is only possible via the context menu of the tray icon and the temperature values read out can be saved in a log file.

Download

This website uses cookies. By using the website, you agree with storing the cookies on your computer. More information in the privacy policy.
k24/k24.1/k24.1.5/k24.1.5.2/start.txt · Last modified: 02.07.2018 (external edit)

Page Tools