12.06.2013 Views

How to make a GUI for USBCNC with Qt4 - Femtotech

How to make a GUI for USBCNC with Qt4 - Femtotech

How to make a GUI for USBCNC with Qt4 - Femtotech

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The typedef is needed because the cncapi uses the integer type _int64 which <strong>Qt4</strong> does not know. Now build the<br />

project (Ctrl + B or click on the hammer icon in the lower left). You should get no errors but a lot of warnings which<br />

are due <strong>to</strong> the syntax used by the cncapi. <strong>How</strong>ever, we may ignore them.<br />

Now let’s see how <strong>to</strong> do something useful <strong>with</strong> the <strong>USBCNC</strong> SDK.<br />

3.3 The <strong>USBCNC</strong> Server<br />

On launching the <strong>USBCNC</strong> software (this standard can be called <strong>GUI</strong>), a process will run in background: it is the<br />

CncServer.exe. In order <strong>to</strong> work properly, the standard <strong>GUI</strong> and all other <strong>GUI</strong>s, that we can build, have <strong>to</strong> be<br />

connected <strong>to</strong> this server.<br />

Open the mainwindow.ui <strong>for</strong>m, drag and drop a Pushbut<strong>to</strong>n and a Line Edit widgets and set the following properties:<br />

Pushbut<strong>to</strong>n<br />

objectName btnConnect<br />

text CONNECT<br />

Line Edit<br />

objectName txtServerStatus<br />

readOnly true<br />

At the moment we do not use any layout, but we will come back <strong>to</strong> this <strong>to</strong>pic later.<br />

Open the mainwindow.h and add the following code in the class definition:<br />

private slots:<br />

void on_btnConnect_clicked();<br />

At this point, add the implementation in the mainwindow.cpp:<br />

void MainWindow::on_btnConnect_clicked()<br />

{<br />

CNC_RC rc = CncConnectServer("");<br />

ui->txtServerStatus->setText(CncGetRCText(rc));<br />

}<br />

The “on_” prefix allows <strong>to</strong> connect au<strong>to</strong>matically a signal (clicked() in the example) <strong>to</strong> the slot declared. In this way<br />

on clicking the pushbut<strong>to</strong>n, the on_btnConnect_clicked() function is called.<br />

CncConnectServer() is the first cncapi function that we use. In order <strong>to</strong> know something more about any cncapi items<br />

just place the cursor on and press F2. The edi<strong>to</strong>r will show the definition in the header file. CncConnectServer() takes<br />

one optional argument: the .ini file name. You should pass this parameter only <strong>for</strong> stand-alone applications which<br />

will run <strong>with</strong>out <strong>USBCNC</strong>4 software. In our example we have already the server running because the <strong>USBCNC</strong>4<br />

Fem<strong>to</strong>tech di Marco Trapanese Via Ripamonti, 14 – 22044 Inverigo (CO) tel. 031 5481112 / 347 9431074 fax 031 2280476<br />

info@fem<strong>to</strong>tech.it www.fem<strong>to</strong>tech.it C.F. TRP MRC 81S13 B639G P.IVA 03041740139<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!