Research
Research Divisions
Research Progress
Location: Home>Research>Research Progress
Design and Implementation of Serial Communication for Automatic Titanium Alloy Sorting System
Author: Update times: 2014-02-21                          | Print | Close | Text Size: A A A

During the process of Titanium alloy cutting, a lot of heat are generated which will cause the change of materials, and bring bads. In order to solve this problem, researchers from Shenyang Institute of Automation (SIA), the Chinese Academy of Sciences (CAS) proposed a Titanium alloy automatic sorting system based on machine vision and image processing can realize the separation of goods and bad ones. 

The sorting machine consists of the vibration feeding, transmission and dividing mechanism. The main control system is composed of OMRON CP1L and PLC. The communication between PLC and host computer rely on serial ports. Host computer does status inquiry of PLC and then go ahead to control vision and dividing mechanism by serial communication.

RS-232 (ANSI/EIA-232 Standard) is the serial connection found on IBM-compatible PCs. It is used for many purposes, such as connecting a mouse, printer, or modem, as well as industrial instrumentation. RS-232 is limited to point-to-point connections between PC serial ports and devices. RS-232 hardware can be used for serial communication up to distances of 50 feet.

The framework of Titanium alloy automatic sorting system is composed of four parts, which are industrial camera, light source, sorting machine and host computer. Host computer is the master of the system, and all the rest except light source are slavers. The master needs transfer data and commands with the slaver. To finish these tasks, efficient, reliable and flexible serial communication should be built between host computer and sorting system. Kinds of programming tools can accomplish this work, such as VB, VC+ +, and Delphi etc. VC++ is the best choice because of its extraordinary capacity. First, the program base on VC++ can run very fast, and has a high degree of portability. Second, VC++ has rich API functions for image processing and communication program. In this system, the image from the camera should be calculated and analyzed to control the activity of sorting machine. The image processing part is not talked about in this paper.

 

Fig. 1 Automatic Titanium alloy sorting machine system (Image provided by CUI Shuping, et.al)

The software flow is illuminated by the Fig2. Just as the figure shows, the operation of serial ports goes through the entire program. The program is started with essential initiation. After that it will go into an infinite loop. The first step of the loop is writing the serial ports, and then reading them. Either reading or writing is failed, the program will return. After the analysis on the data from serial communication, the subsequent action can be decided that is going back to the start of the loop, or going forward to the step of taking picture and image processing. According to the result of image processing, current sample can be recognized. The goods will be retained, and the bads will be eliminated by dividing mechanism after host computer finishes writing to the serial ports. Then the program goes back to the start of the loop. So host computer accomplishes the status inquiry and control to the sorting machine by the serial communication.

The main content of software development of automatic Titanium alloy sorting system is to exploit a MFC dialog-based application with windows API functions for serial communication and image processing. Dialog-based application is convenient to debug the operation, such as watching the data transferred or received from serial ports. On the dialog a start button can be created to activate the action of the program. During the flow of the software, all steps except taking picture and processing Image rely on the analysis based on the data from serial communication.

 

Fig. 2 The software flow of the automatic Titanium alloy sorting system (Image provided by CUI Shuping, et.al)

There are two ways of building the serial communication on the MFC dialog-based development platform. First is using ActiveX controls. ActiveX control programs are modular programs designed to give a specific type of functionality to a parent application. They are easy to use in MFC dialog-based applications because they have been designed for reuse, but not very flexible and give you little control of the implementation. Second is using Windows API functions, which is quite flexible and gives engineers much freedom to intervene the program’s operation.

Developing a serial communication application should obey the following four steps. First is openning the serial ports. CreateFile function is used to open serial ports. Here are the codes:

       HANDLE hCom;
       hCom=CreateFile("COM1",
              GENERIC_READ|GENERIC_WRITE,
              0,
              NULL,
              OPEN_EXISTING,
              0,
              NULL);
        if(hCom==(HANDLE)-1) {//} else {//}
       SetupComm(hCom,5096,5096);

Second is initiating the serial ports. After the serial ports are opened, they require initiation with the DCB (device-control block) structure. The DCB structure defines the control setting for a serial communications. The following code illustrates setting baud rate to 115200bps, byte size to 7, stopbits to 2, and parity to 2(even parity).
      DCB dcb;
       GetCommState(hCom,&dcb);
       dcb.BaudRate=115200;
       dcb.ByteSize=7;
       dcb.Parity=EVENPARITY;
       dcb.StopBits=TWOSTOPBITS;
       SetCommState(hCom,&dcb);

Third is setting Time-out. To deal with the situation of exception during data transfer, the COMMTIMEOUTS structure is used in the SetCommTimeouts and GetCommTimeouts functions to set and query the time-out parameters for serial ports which determine how long it is before ReadFile or WriteFile operation is abandoned.
                   COMMTIMEOUTS TimeOuts;
                   GetCommTimeouts(hCom,&TimeOuts);
       TimeOuts.ReadIntervalTimeout=1000;
       TimeOuts.ReadTotalTimeoutMultiplier=500;
       TimeOuts.WriteTotalTimeoutConstant=5000;
       TimeOuts.WriteTotalTimeoutMultiplier=500;
       TimeOuts.WriteTotalTimeoutConstant=2000;
       SetCommTimeouts(hCom,&TimeOuts);

The last is writing and reading the serial ports. WriteFile function writes to the serial ports and ReadFile functions reads data from the serial ports. The following codes illustrate how to use WriteFile function:
                  char lpOutBuffer[100]="@00FA08000020000000000FC000101B1000A0000017B*\r";
                  DWORD dwBytesWrite=100;
       BOOL bWriteStat;
       COMSTAT ComStat;
       DWORD dwErrorFlags;
       ClearCommError(hCom,&dwErrorFlags,&ComStat);
       PurgeComm(hCom,PURGE_TXCLEAR|PURGE_RXCLEAR);
       bWriteStat=WriteFile(hCom,lpOutBuffer,dwBytesWrite,&dwBytesWrite,NULL);

The following codes illustrate how to use ReadFile function:
                   char str[50];
       DWORD wCount;
       BOOL bReadStat;
       bReadStat=ReadFile(hCom,str,50,&wCount,NULL);

From long time testing, the serial communication between host computer and sorting machine is very efficient, reliable and flexible. The button capture one on the dialog window controls the operation of the software. The dialog window is shown as Fig3.

 

Fig3 The software window (Image provided by CUI Shuping, et.al)

Under the above configuration of serial ports, WriteFile function cost s about 4ms. ReadFile function costs 3ms. Without image processing, once loop time is only about 16ms, make great contribution to increase the performance of the whole system. With the help of ActiveX controls, the documents are used to watch the data for debugging.

This work was published on the Applied Mechanics and Materials Vols. 519-520 (2014) pp 1340-1344. It was financially supported by the National High Technology Research and Development Program of China (863 Program) under grant 2011AA040102 and 2012AA041701.

CONTACT:
Cui Shuping
Shenyang Institute of Automation, the Chinese Academy of Sciences
Email:
cuisp@sia.cn

 

Copyright © 2003 - 2013. Shenyang Institute of Automation (SIA), Chinese Academy of Sciences
All rights reserved. Reproduction in whole or in part without permission is prohibited.
Phone: 86 24 23970012 Email: siamaster@sia.cn