{'fraction_non_alphanumeric': 0.02981046433171809, 'fraction_numerical': 0.005520456357725572, 'mean_word_length': 4.528653780942692, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
CNC Software Control System Using Visual Basic

Computer Numerical Control (CNC) machines are having a great industrial role in the progress of humanity to furnish an exactly crafted pieces for different tools and instruments. In the last decade their use had become more popular due to the cheap microcontrollers that emerged and still emerging. The 3D printers’ availability made manufacturing of CNC machines simpler. But the need for easing the means to program a CNC machine is still required. This paper gives a software which is intended to make dealing with G-code used with this type of machines easier. This software allows the user to execute manually any step he wants in predefined steps which can be changed on demand, return to origin of working palette, control the working head to any level demanded. Also, it can transform any G-code already prepared to the CNC machine. This software is built using the visual basic vb6.net. The microcontroller used is the Arduino uno, the mechanical set is locally prepared, and the presented application is for line drawing. CNC machines can do a variety of jobs including; drilling, plotting, engraving, laser cut, PCB drilling … etc. This software had been tested successfully for drawing with ability to show the G-code for each manual movement. Applying it to other CNC applications demands changing the operation head and care for each condition application circumstances.


I-Introduction
Computer Numerical Control (CNC) is a process of automatic control of machine tools that are guided by a microcontroller through a suitable program. The machine tools which can be automated include mills, plotters, lathes, lasers …etc. CNC machines are increasingly taken care of so as to get sophisticated products. They are controlled through what is known as the G-code, it offers all the means to control the movements of tools to perform the wanted actions, such as milling, plotting, scratching, and other activities. The objective of the research is to design a program in visual basic with graphical user interface (GUI) that gives the user a nice way to download the commands to the microcontroller and gives the details as instructions step by step, indicating what path the machine follows. Also indicating all the necessary information about the coordinates, feed rate, pen or tool depth, speed, and control the machine movement for a specific coordinate manually. There are plenty of open source CNC software libraries available on the internet, but most are difficult to customize. The source code of these libraries is rather complicated to understand, as it is mainly developed in JAVA or PYTHON. The main drawback of these libraries is that they are not fully compatible with CNC machines controlled by ARDUINO using stepper motors. While in visual basic language the control of the stepper motors is more flexible and it can be exported as execution files. Also, it is more compatible with windows versions and the interface with Arduino microcontrollers is easily achievable. After a suitable study of the mentioned limitations, this software has been proposed. Various authors have studied the development of software that control CNC machines "Adel MESSAOUDI" [1], 2016 in his master thesis projects, suggests a developed front-end user application to simplify the process of sending G-code to the Arduino microcontroller. Where it contains the important actions that makes the CNC machine easy and simple to be controlled. It was built using python programming language. "Yusri Yusofl, and Kamran Latifi" [2],2015 in their paper developed interpreter software component to translate existing CAD/CAM system-generated ISO 6983 code into an open architecture-based CNC system understandable data structure. It has been programmed in NI LabVIEW. The LabVIEW platform was chosen because it is a graphical language. "Alma G. Rodríguez, Luis R. Vidal P., Juan Miguel Díaz M., and Cesar Leonardo González Pinzón" [3], 2013 in their paper implementing interpreter software with GUI using Microsoft visual basic 2010. This interface is used for a profile milling processes on an XY plane executing motion control instructions. "Dan Lorenc" [4], 2010 in his master thesis developed a software CNC controller using MATLAB as the primary development platform with the GUI. The user must interface with the software to tell the machine what to do. The software allowed the user to input G-Code. This G-Code was run through a G-Code processor in order to turn commands on, the machine was then told what to do by the machine controller. The software is applied on a prototype CNC machine as a plotter. It results in obtaining the required G-code for each task demanded successfully. This paper includes the following; Background, Software structure, results, and Conclusion with future works.

II-Background
Today, CNC machines are widely used in the manufacturing field and can be controlled by certain programming languages in order to perform a wider range of tasks with greater accuracy. There are many types of CNC machines, the most common CNC machines are of two-axis and three-axis movement directions [5]. The two-axis machines can move on vertical and horizontal directions only which are X and Y axis. Three-axis machines can operate starting with three primary axis which are X, Y, and Z. The Z axis is parallel with the spindle or the pen, motion of three stepper Motors to control the coordinates (X, Y, and Z) of a pen with flexible head can be used as a Plotter in this article. CNC machines are supplied with a series of instructions which are delivered to the controller. These instructions are in the form of codes which are a part of the numerical control programming language. The code for programming CNC machines is called the G-code as mentioned earlier. G-code also known as, geometric code, or the MIT (RS-274) [6], is the most frequent (computer-aided design and manufacturing) CAD/CAM programming language. The G-code was started as a limited language lacking constructs such as a loops, conditions, and as programmer-declared with natural-word variables. The program could not logically be encoded. The latest implementations of G -code include language capabilities that are somewhat closer to high level programming. In manufacturing, automation and engineering areas, G-codes are playing a major role in dealing with CNC machines. The states used in Gcode tell the computer that controls the stepper motors of the machine how far to move to a specific point and at what speed it can be run. G-code can provide the instructions to the computer-controlled equipment to move the head through work space to create a specific job. G-Code source program contains a variety of commands [7] that are processed sequentially to do a certain job and it may contain the following options as shown in Figure   G codes tell the machine to perform the specific functions. There are many special orders, Rapid movement (quick move between the coordinates), manage feed in a straight line and arccontrolled feed actions, and order tool setting such as offset switch coordinate systems. For example the G00 (Rapid positioning mode) tool is taking the shortest path by programming X, Y, Z position. Also, the G01 (Linear mode) for moving the head in a straight line by one unit according to the feed rate decided. Although the G-code for a certain design can be written manually, it is generally easier to use the CAD/CAM software packages. These packages give easier, faster, and also rather automated method to get the required codes without the need to be an expert in G-code details.
The CNC machine used as a plotter is given in Figure (2) below.
The system here is furnished with the following hardware components: ARDUINO UNO as the microcomputer, CNC shield V3, four stepper motors (type Nema 17), stepper motors driver 4988, ball bearing holders, linear rods, end shafts, supporting 3D printed parts, and the pen holder. Figure (3), shows the CNC plotter block diagram used to test this proposed software. III. Software Structure CNC control software was developed as a front-end user application to simplify the process of sending G-code to the Arduino microcontroller. It has been tested on Windows 10 and Windows 7 successfully. This software is written and developed using Vb6.net as shown in Figure (5), where it contains the important actions that makes the CNC machine easy and simple to be controlled. After Loading Arduino with the proposed software firmware, it reads the G-code file that has been designed in CAD/CAM software, which was opened by the user while interacting with the GUI (Graphical user interface) or codes written personally. Then it displays the G-code lines gradually as the output that should be machined by the CNC. It waits for an event (mouse click) which is linked or binded with a button. If a start button was pressed, then it starts sending data line by line to the microcontroller through the USB/serial port, this is one job of the software as well as the manual control on the three axes (x, y, and z) by sending the G-code of each movement to the CNC.
The steps that should be followed to use this software are as shown in Figure ( First, connect to Arduino using the computer USB port of your choice. The program settings have been set as (baud rate to 115200, 8-bits, no parity, and 1-stop bit) in the code and there is no need to change these setting manually. Once connected you should get the software prompt. The GUI structure contains at the top a control bar referring to the USB port selection for the Arduino controller and after selecting the communication port that corresponds with the machine, software is transferred to the Arduino through the USB connection. This GUI includes a menu bar containing, as shown in Figure (5) the following: -Open ---choose the port to connect with Arduino.
-Refresh ---if you want to connect with another port you must press refresh.
-Close ---exit from the entire program The main control menu contains three menus these are:

1-Machine control:
It consists of many buttons everyone has a specific function. The Home button job is to retain the CNC with x, and y to the default point or zero point. The Safe Z button specifies the height that the Z axis should retain before moving on any other axis. This is needed to keep the pen high enough to avoid any clamps or other things that may get hit. Also, four buttons for controlling the x and y axes manually by one step in each direction, and the z axis up and down (X+, X-,Y+, Y-, Z+, and Z-). The machinist can move to any point with specific coordinates after choosing the step size as (0.1, 1, 10, or 100) [8]. Changing the step size and units in this interface will affect commands that are sent manually, this will not change the way that jobs are ran on the machine which are imported from external code sources.

2-File Send:
It contains two buttons as shown in Figure ( file: choosing the G-code file with the right extension from the its directory. The file name appears in the file name field.
Send file: after getting the desired G-code file and pressing this button the software sends the Gcode file to the Arduino UNO microcontroller so that it can be executed by the CNC machine.

Console:
Software also has system command types that are outside of the normal G-code streaming. System command types are taken from Arduino library in visual basic language. This command streams are composed of special set of characters that will immediately give orders to do a task in real-time. It's not part of the G-code stream. These commands can be sent at any time, no matter what the software is doing. They should either immediately change software's running behavior or immediately print a report of the important real time data like current position Realtime commands are single control characters that perform an action in real-time. These commands include: reset, feed hold, resume, status reports, etc. This console feature has the ability to order the machine to do a specific task and run it directly. A review for the commands used in this part of the software: -$ Command: Type $ and press enter to have a software help message showing the commands that can be written in the tool bar and then press send as shown in Figure ( The '$'-commands include the following options:

$$ Command
View and write software settings.
View G-code parameters. G-code parameters store the coordinates offset values, predefined positions, coordinates offset, tool length offsets, and probing. Probing means that settings will remain the same, regardless of power-down conditions until are changed by any means.
-$G Command View G-code parser state. This command prints all of the active G-code modes in software G-code parser.
-$I Command View build info, this prints information to the user software's version and source code build date. Also, identify which CNC machine you are communicating with, if the software attached with multiple CNC machines.
-$Nx Command View the startup blocks that software runs every time you power on the software or reset it. A startup block is a line of G-code that you run to set your G-code modal defaults.
-$SLP Command Enable Sleep Mode, this command will place software into a de-powered sleep state, shutting down the spindle, and stepper motor enable pins, so blocking any commands.

IV. Results
Integrating the proposed software with the hardware system makes up an effective CNC plotter. The interpreter plays an important role in CNC systems. It translates Gcode program into commands that can be executed by the CNC machine, so that stepper motor can be moved along linear or circular movement. After the generation of G-code file, the next step is to upload the codes into the developed software. Two different tests applied, the first by taking image file 'basmala' Figure (8-a). and convert it to vector using (CAD/CAM) program and then save it as G-code.Tap file, so that the software can deal with it. The original and the plotted files (8-b) are shown in Figure (  If compared with the original G-code file and the produced sketch by software, the results obtained indicate the accuracy and clarity of the implementation of the machine in plotting with a small error rate in addition to the time factor. The second test is writing G-codes manually in the G-code editor then saving the file as Gcode extension. After that the file is executed by the software which decoded it and sent it to the microcontroller with the result as shown in Figure (  Drawing steps can be explained as: In the first make a rapid movement to (x0, y0) and that is the default coordinates then use (G02) command which is clock wise circular interpolation, after that drawing the top arc of the first circle on the left (left eye) and then the bottom arc with the same way. Now go to the default coordinates again by using (G90) as absolute position and draw the second circle (right eye) with the same method mentioned above, after that draw the (mouth), an arc Then draw the surrounding circle also with (G02), the nose by using (G01) as linear interpolation, and finally the (M30 ) which refer to the end of program.

V-Conclusions and future work
This study is about building and testing a proposed software for controlling 3-axis CNC plotter machine which is able to interpret G-code file that can draw any image or text on a given solid surface due to precise controlling of the stepper motors. As well as manual control and direct command feature for ordering the CNC machine. This software was designed in visual basic with its libraries been used as the programming language. The software decodes the instructions and starts sending the G-code lines one after another to be executed by the microcontroller. The goal of this work has been accomplished, i.e. the development and programming of CNC software control is achieved in aspects of the accuracy of the plot.
As further work, the software also can be developed in future to have simulation of actual run and including the path monitor show, also adding feature of other file extension support like DXF. A drill can be used with appropriate holder and power supply. Also, a limit switch can be