LMMS MN1278 User Manual

MN1278 05.2001
Mint™ version 4
PC Programming Guide
MN1278
Issue 1.2
Mint v4 PC Programming Guide
MN1278 05.2001
Copyright
Copyright Baldor UK Ltd © 2001. All rights reserved.
This manual is copyrighted and all rights are reserved. This document or attached software may not, in whole or in part, be copied or reproduced in any form without the prior written consent of Baldor UK. Baldor UK mak es no represe ntation s or warrant ies with resp ect to the c ontents h ereof and speci fically dis claims an y implied warranties of fitness for any particular purpose. The information in this document is subject to change without notice. Baldor UK assumes no responsibility for any errors that may appear in this document.
is a registered trademark of Baldor UK Ltd.
MINT Windows 95, Windows 98 and Windows NT are registered trademarks of the Microsoft Corporation.
Baldor UK Ltd Mint Motion Centre 6 Bristol Distribution Park Hawkley Drive Bristol BS32 0BF U.K. Telephone: +44 (0) 1454 850 000 Fax: +44 (0) 1454 859 001 Web site: www.baldor.co.uk Sales email: sales@baldor.co.uk Support email: technical.support@baldor.co.uk
Baldor Electric Company Telephone: +1 501 646 4711 Fax: +1 501 648 5792 email: sales@baldor.com web site: www.baldor.com
Baldor ASR GmbH Telephone: +49 (0) 89 90508-0 Fax: +49 (0) 89 90508-492
Baldor ASR AG Telephone: +41 (0) 52 647 4700 Fax: +41 (0) 52 659 2394
Australian Ba ldor Pty Ltd Telephone: +61 2 9674 5455 Fax: +61 2 9674 2495
Baldor Electric (F.E.) Pte Ltd Telephone: +65 744 2572 Fax: +65 747 1708
MN1278 05.2001
iii
Mint v4 PC Programming Guide
iv
MN1278 05.2001
Manual Revision History
Manual Revision History
Issue Date BOCL
Reference
1.0 Apr 99 UM00545-000 Raised from MN00249-003.
1.1 Feb 00 UM00 545-001 Added NextMove PC device driver documentation.
1.2 May 2001 UM00545-002 Updates for PC Developer Libraries 1302 release.
Comments
This is a new UM for v4, allowing updates to the v3 manual to continue as MN00249-XYZ
Corrected fo r Mint v4 ( new C++ fil es , Win2000, WinME.
MN1278 05.2001
v
Mint v4 PC Programming Guide
vi
MN1278 05.2001
Introduction................................................................................1
1.1 Introduction...............................................................................................2
1.2 Installation ................................................................................................2
Communicating with a Controller.............................................3
2.1 NextMove PCI...........................................................................................4
2.2 NextMove PC............................................................................................4
2.3 Dual Port RAM on NextMove PCI and PC................ ............. ... .. .. ... .. .. .. ...4
2.4 Mint Comms Array (All Controllers)...........................................................5
2.5 Interfacing with Mint.. .. ... ............. .. ... .. .. ... .. .. .. ... .. .. .. ... .. .. ... .. .. .. ... .. .. ... .. .. .. ...7
2.5.1 Preventing Deadlock Situations............................................................7
Using the Library with Various Languages..............................9
3.1 C++.........................................................................................................10
3.1.1 C++ : the Classes...............................................................................10

Contents

3.1.2 Pre-Compiled Headers in Visual C++ 6.0...........................................11
3.1.3 A Visual C++ 6.0 Tutorial ............ .. .. ... .. .. .. ... .. .. .. ... .. .. ... .. .. .. ... .. .. ..........14
3.1.4 Compiling an ATL COM Project with Visual C........ .. ... .. .. .. ... .. .. ..........24
3.1.5 RS485 Networks. ...............................................................................24
3.2 All Other Languages : The ActiveX Control ( OCX ) ...............................24
3.2.1 The ActiveX Control And The Languages It Can Be Used With.........24
3.2.2 The ActiveX Control and Error Handling.............................................25
3.2.3 The ActiveX Control and Serial Controllers. .......................................25
3.2.4 The ActiveX Control and RS485 Networks. . .. .. ... ............. .. ... .. .. .. ... .. .. .25
3.2.5 Distributing an Executable Which Uses The ActiveX Control. ............25
3.2.6 ‘Server Busy” / “Component Request Pending” Errors............. .. ... .. .. .25
3.3 Visual Basic 6.. .. ... .. .. .............. .. .. ... .. .. .. ... .. .. .. ... .. .. .. ... .. .. ... .. .. .. ... .. .. .. ... .....27
3.3.1 Error number conversion....................................................................27
MN1278 05.2001
vii
Mint v4 PC Programming Guide
3.3.2 A Visual Basic Tutorial. ............. .. .. .. ... .. .. .. ... .. .. ... .. .. .............. .. .. ... .. .. .. .27
3.4 Borland Delphi 5.0 ........... .. .. ... .. .............. .. .. .. ... .. .. .. ... .. .. ... .. .. .. ... .. .. ... .. .. .. .31
PC Based Motion Control........... .............................................35
4.1 Limitations of PC based applications ......................................................37
4.2 Events and Interrupt Control on NextMove PCI ......................................38
4.2.1 Writing and Installing an Interrupt Handler .........................................38
4.2.2 Event Control Functions.....................................................................42
4.2.3 Interrupting the Host from a Mint Program ( DPR Events ).................43
4.2.4 Handling Events Using the ActiveX Control........ .. .. .. ... .. ............. ... .. .. .43
NextMove PCI and Non-Microsoft Operating Systems..........45
5.1 How to Recognise the NextMove PCI........... ... .. .. .. ... .. .. ... .. .............. .. .. .. .46
5.2 Host Accessible Hardware on NextMove PCI.. . . .. ... .. .. .. ... .. .. .. ... .. ............46
5.3 The CSimplePCI class............................................................................46
5.3.1 The CMySimplePCI Example.............................................................47
5.3.2 Functions Required by the Overloaded Class. ............ .. .. .. ... .. ............47
5.3.3 Files to Include in a CSimplePCI Derived Class Project. ....................49
Appendix 1: DPR Map ..............................................................51
6.1 NextMove PCI DPR Map ........................................................................51
6.2 NextMove PC DPR Map .........................................................................54
6.3 Status and Control Registers..................................................................56
6.4 Axis Data ................................................................................................59
6.5 I/O Data..................................................................................................61
6.6 Comms Array..........................................................................................62
6.7 Immediate Comand Mode.......................................................................62
6.8 Pseudo Serial Interface ..........................................................................63
6.9 Special Functions Registers ...................................................................64
viii
MN1278 05.2001
6.10 Data Synchronisation..............................................................................66
Appendix 2: Timings................................................................67
7.1 Immediate Command Mode Functions ...................................................67
Appendix 3: Symbolic Constants............................................69
Bibliography .............................................................................77
Contents
MN1278 05.2001
ix
1. Introduction
The Mint™ v4 PC Programming Guide details how to call Mint v4 functions and how to communicate with Mint controllers from PC based host applications.
1

Introduction

MN1278 05.2001
1
Mint v4 PC Programming Guide
1.1 Introduction
The PC Developer Libraries allow PC based applications to be written that communicate with Mint controllers. This is achieved using the Mint Interface Library which is a common API (Application Program Interface) for the range of Mint based motion controllers. The Mint Interface Library is suitable for use under Windows 95, 98, ME, NT and 2000 via an ActiveX control or C++ source code.
Features include:
Ability to upload and download Mint programs and configuration files.
Ability to interrogate the Mint command line.
Updati ng of new firmware into FLASH or RAM.
Support for the Mint Comms Protocol, whereby data can be transferred to an executing Mint program by
means of a protected datapacket.
Ability to read Dual Port RAM locations on the NextMove PCI and NextMove PC (Mint v4)
controll ers. PC based motion control.
Support for communications with controllers on a CAN network.
Support is provided for the following controllers:
NextMove product family: NextMove PCI, NextMove BX and NextMove PC.
MintDrive.
ServoNode 51.
EuroSystem product family: SmartMove, SmartSt e p, EuroSystem, EuroStep, E uroServo.
This manual does not include detail on individual Mint Interface Library functions. Details can be found in the Mint v4 Function Reference Guide.
1.2 Installation
From the Baldor Motion Toolkit CD, the ‘PC Developer Libraries’ should be installed from the NextMove PCI, NextMove BX v4, MintDrive and ServoNode 51 product pages. This will install the ActiveX component, the C++ source files and the examples. A custom setup option is also included to allow selective install of the components.
2
MN1278 05.2001

Communicating with a Controller

2. Communicating with a Controller
This chapter covers general communication with Mint controllers.
2
MN1278 05.2001
3
Mint v4 PC Programming Guide
The Mint Interface Library is a common API that allows access to Mint controllers. It can be used via an ActiveX control or through C++ source code. The Mint Interface Library is suitable for use under Windows 95, 98, ME, NT and 2000.
The ActiveX control (OCX) can be used with a large number of languages. This document concentrates on Microsoft Visual C++, Microsoft Visual Basic and Borland Delphi but the principle is the same in any language. The C++ source code can also be used directly from Visual C++.
Communication to NextMove PCI and NextMove PC occurs over Dual Port RAM on the card. Communication to all other controllers takes place over a serial port using either RS232 or RS485.
The are several example programs included on the Baldor Motion Toolkit as part of the PC Developer Libraries. This chapter covers general methods of communication with Mint controllers. The next chapter covers the
specifics of using the Mint Interface Library.
2.1 NextMove PCI
NextMove PCI requires a device driver under all Windows operating systems. See the NextMove PCI Installati o n Gu ide for details on installi n g the device dr ivers.
The version number of the device driver can be found using the following method:
Windows 95, 98, ME:
Locate the file NMPCI1.VXD in the \WINDOWS\SYSTEM directory using Windows Explorer. Right click the file and select ‘Properties’. The ‘Version’ tab of the displayed dialog gives version information for the device driver.
Windows NT, 2000:
Locate the file NMPCI.SYS in the \WINNT\SYSTEM32\DRIVERS directory using Windows Explorer. Right click the file and select ‘Properties’. The ‘Version’ tab of the displayed dialog gives version information for the device driver.
2.2 NextMove PC
NextMove PC requires a device driver under Windows NT and Windows 2000. See the NextMove PC Mint v4 Installati o n Guide for d etails on instal ling the device driver.

2.3 Dual Port RAM on NextMove PCI and PC

All communication between NextMove PCI / PC and the host is performed using Dual Port RAM (DPR). This is physical block of memory on NextMove which can be accessed by either NextMove or the host. Various locations in DPR have been set aside for special purposes such as sending control codes and passing I/O information. Other locations have been left for the user to pass any required information back and forth.
4
MN1278 05.2001
Communicating with a Controller
The main features and uses of DPR are:
Support for the Mint Comms protocol. This is a method of asynchronously updating variables in a Mint
program from the host. Mint pseudo serial buffer. This allows communication with the Mint command line and Mint program
and configuration loading/saving. Reporting of Mint status. The host can read whether Mint is at the command line and if not, which line
it is executing.
Automatic reporting of motion variables. Every 2 milliseconds NextMove writes various motion
parameters into DPR such as position and velocity of an axis. This can be read at any time by the host. Event control. This allows NextMove to interrupt the host and the host to interrupt NextMove.
Flags & control registers. Each NextMove application uses control registers to tell the host which
features it supports. Control registers can also be used to synchronize communications between NextMove and the ho s t.
User area. There is an area in DPR which has been left to allow NextMove and the host application to
exchange whatever application specific data is required.
Appendix 1 shows the layout of DPR and describes the functionality of each section in detail.
2.4 Mint Comms Array (All Controllers)
The Mint Comms Protocol is a secure communication method allowing asynchronous transfer of floating point data to and from a Mint controller. This is a 255 element array where the first 99 elements can contain user data and the remaining elements contain pre-defined data such as axis position and velocity. Comms provides the best way of communicating data between a Mint program running on a controller and the host at run time. It can be used for simple data transfer, or as a method of synchronizing events. Comms can also be used for transferring data directly between controllers. For further information on the uses of Comms, see the Mint v4 Programming Guide section 5, ‘Mint Comms Communications’, and the Mint v4 CAN Programming Manual section 3, ‘Getting Started with CANopen’.
On Mint v4 serial controllers, Comms now uses binary packets to transfer data but in earlier Mint versions, an ASCII based packet was used. All Mint v4 controllers also support the older protocol.
Example:
In this example, Comms is used to pass commands to a Mint program using two Comms locations. Location 1 is used to pass the command and location 2 is used to pass data. The host code is written in C++ but the principles are applicable to any language.
Host:
/* Address of NextMove PC */ #define nmADDRESS 0x33C
/* Node number */ #define NODE0 0
MN1278 05.2001
5
Mint v4 PC Programming Guide
/* COMMS location uses */ #define CONTROL_LOCATION 1 #define PARAM_1 2
/* Flags for control location */ #define COMPLETED 0.0 #define SPECIAL_ROUTINE1 1.0
/* Create a handle to the controller */ CNextMovePC myNextMove ( NODE0, nmADDRESS );
/* Define variables */ float fErrorCode; float fOutput = 1.0; float fControl = SPECIAL_ROUTINE1;
/* Write to comms location */ myNextMove.setComms (NODE0, PARAM_1, &fOutput );
/* Write to comms location */ myNextMove.setComms (NODE0, CONTROL_LOCATION, &fControl );
/* Handshake to Mint program to wait for completion of function */ do {
myNextMove.getComms (NODE0, CONTROL_LOCATION, &fControl );
} while ( COMPLETED != fControl );
/* Read the data returned */ myNextMove.getComms (NODE0, PARAM_1, &fErrorCode );
Mint for NextMove:
REM COMMS location uses DEFINE control = COMMS (1) DEFINE param1 = COMMS (2)
REM Flags for control location DEFINE completed = 0 DEFINE special_routine1 = 1
REM I/O DEFINE open_gripper = OUT0 = 1 DEFINE gripper_fully_open = IN6 = 1 DEFINE gripper_error = IN7
WHILE 1
IF control = special_routine1 DO
OUT1 = param1 : REM Use param supplied by top end open_gripper PAUSE gripper_fully_open: REM Wait for an event param1 = gripper_error: REM Data to pass back to host control = completed : REM synchronise with host
ENDIF
ENDW
6
MN1278 05.2001
Communicating with a Controller

2.5 Interfacing with Mint

The Mint command line allows manual execution of Mint keywords. Using the Mint WorkBench, the Mint command line can be used when testing, commissioning and debugging Mint programs.
There are several functions in the Mint Interface Library for direct access to the serial buffer:
setSerialChar, setSerialCharTimeout, setSerialStringTimeout, getSerialChar, getSerialCharTimeout and getSerialStringTimeout.
These allow characters and strings to be passed to and from a Mint application. A Mint application may use the serial buffer for program control, user information or debug information.
For example:
myNextMoveBX.setSerialStringTimeout ( “MA.0=100:GO.0\n”, 100).
2.5.1 Preventing Deadlock Situations
If Mint has a character to write to the serial port, it will wait indefinitely until there is a space in the transmit buffer. This means that the serial buffer must be emptied by the host application for the Mint program to proceed. There are several ways of doing this:
Call one o f th e read func tions e.g. getSerialChar until the buffer is emptied. Set the terminal mode to be overwrite or off. The terminal mode controls how the serial buffer is used. If the
mode is overwrite, then the oldest characters in the buffer are overwritten by the new characters. If the mode is off, all characters are discarded as they are placed in the buffer. See the TERMINALMODE keyword in the Mint v4 Programming Guide for further details.
The functions setTerminalmode (tmRS232, tmmOVERWRITE) will set the terminal mode on the RS232 port to be overwrite. setTerminalmode (tmDPR, tmmO FF) will disable all serial communications on the pseudo serial buffer on NextMove PC or PCI.
The terminal mode can also be set for NextMove PC and PCI when firmware is downloaded to the controller. Specify TRUE fo r the bEchoOverwrite parameter of doUpdateFirmware / doUpdateFirmwareEx. This will set the pseudo-serial communications into overwrite mode.
To download and upload and Mint program and configuration files to Mint, the functions doMintFileDownload and doMintFileUpload are used. These are unaffected by the setting of terminalmode.
MN1278 05.2001
7
Mint v4 PC Programming Guide
The following is a summary of the functions used to access the Mint command line:
Function Name Description
doMintBreak Sends Ctr l-E to Mint,( bypas s ing the pse udo-serial
buffer on NextMove PC and PCI ).
doMintRun Write RUN <ENTER>
getSerialChar Read a char from the pseudo-serial buffer if one is
available
getSerialCharTimeout Read a char from the if one is available within the
given period of time.
getSerialStringTimeout Read up to 64 chars from serial buffer into a string
setSerialChar Write a character
setSerialCharTimeout Writes a character with a timeout
setSerialStringTi meout Writes a string, timing ou t if the pseudo -serial tra nsmit
buffer is full
8
MN1278 05.2001

Using the Library with Various Languages

3. Using the Library with Various Languages
This chapter details the use various different programming languages. The languages covered are:
C++
Visual C++ 6
3
Visual Basic 6
Inprise Delphi
MN1278 05.2001
9
Mint v4 PC Programming Guide
3.1 C++
The Mint Interface Library was written in C++. The source code is provided and can be included in your project. The only supported compilers are Visual C++ v6.0 and Watcom 11. All other compilers must use the ActiveX control to communicate with controllers.
3.1.1 C++ : the Classes
The Mint Interface Library contains a C++ class for each controller. In each case the class is defined in the header file in the right of the table. All of these headers are included in
precomp.h (see later).
Controller Class Header file to include
NextMove PC CNextMovePC ne xtmove.h NextMove PCI CNextMovePCI1 nm_pci1.h NextMove BX CNextMoveBX nm_bx.h MintDrive CMintDrive mintdrv.h ServoNode 51 CServoNode51 snode51.h
The simplest way to interface to any of these controllers is to create an instance of the object and call any of the functions described later in the manual.
For example, to download nmpci.out to a NextMove PCI a CNextMovePCI1 object can be created.
Hint : All controllers referenced in the
class (defined in
The following files should be included in your C++ project.
File Controller
base.cpp All baldorserial.cpp All Serial host_def.cpp All logfile.cpp All mme.cpp MintDrive, NextMove BX, ServoNode 51 mml.cpp All nextmove.cpp NextMove PC nm_nt.cpp NextMove PC nm_pci1.cpp NextMove PCI nm_win32 NextMove PC & PCI
10
BASE.H.
(CController*) if the class type to be created is not known at compile time.
) All functions are v irt ual, so it is safe to pass po i nte r s to objects as
Mint v4 PC Programming Guide
are derived from the CController
MN1278 05.2001
Using the Library with Various Languages
File Controller
nmbase.cpp NextMove PC nmstd.cpp NextMove PC precomp.cpp All serial.cpp All Serial syncronisation.cpp All uncompress.cpp All
3.1.2 Pre-Compiled Headers in Visual C++ 6.0.
In order to speed up compilation of C++ projects using C++, the Mint Interface Library files precomp.cpp and precomp.h can be used. This has been found to reduce build times by up to 85% so although not required are worth using. To use precompiled headers, include precomp.h at the top of each source file. Then include precomp.cpp in the project and set it to create the pre-compiled header file. The following sections go into more
detail on how to set up precompiled header files in the supported compilers. To use pre-compiled headers with a Visual C++ project.
1. Make sure precomp.cpp is included in the project.
2. If the project was generated by the App Wizard, it will have created a file called stdafx.cpp to create the precompiled header file. As precomp.cpp replaces stdafx.cpp, delete stdafx.cpp from the project.
3. If stdafx.cpp was NOT deleted in the previous step proceed to step 6.
4. Replace all instances of #include “stdafx.h” with #include “precomp.h”.
5. In the Project menu, select Settings. This will open the ‘Project Settings’ dialog. Select the C/C++ tab. In the Category drop-down, select General. Select All Configurations in S Preprocessor definitions: field, add _INC_STDAFX_H_ separating it from the preceding text with a comma. This causes precomp.h to include the files previously included by stdafx.h. stdafx.h can still be edited to add more files to the precompiled header as required. The dialog should now look similar to the screen shot below. Press OK to store these changes. Now proceed to step 7.
ettings Fo r: on the left. In the
MN1278 05.2001
11
Mint v4 PC Programming Guide
Figure 3-1: Visual C++ 6.0 Project Settings (step 5)
6. Add #include “precomp.h” to the top of each source (.c or .cpp) file. Note that no pre-compiler directives (e.g. #include, #if, #define) should be placed above this line (although comments can be).
7. In the Project menu, select Settings. This will open the ‘Project Settings’ dialog. Select the C/C++ tab. In the Category drop-down, select Precompiled Headers. Select All Configurations in S
ettings For: on the left. Click on Use precompiled header file (.pch) and enter precomp.h in the Through Header text field. The dialog should now look similar to the screen shot below. Press OK to store these changes. This will instruct the project to use the pre-compiled file.
12
MN1278 05.2001
Using the Library with Various Languages
Figure 3-2: Visual C++ 6.0 Project Settings (step 7)
8. Select precomp.cpp in File View. Right click with the mouse and select Settings. This will open a dialog similar to the dialog in step 3, but this time the dialog will only apply to precomp.cpp. Again, select Settings
For: All Configurations, and the Precompiled Headers Category on the C/C++ tab. This time, select Create precompiled header file (.pch) and add precomp.h to the Through Header field. Check the dialog resembles the one below and press OK.
MN1278 05.2001
13
Mint v4 PC Programming Guide
Figure 3-3: Visual C++ 6.0 Project Settings (step 8)
9. Rebuild the project. Precomp.cpp should now be the first file to build. This causes the pre-compiled header file to be built. All the other files will now use this pre-compiled header as opposed to having to re-compile all the header files each time.
3.1.3 A Visual C++ 6.0 Tutorial
This section will guide you through creating a Visual C application. The application will contain one button which will toggle the state of the enable output for axis 0. Note that the axis must already be configured as servo (use the Mint WorkBen ch to do this).
14
MN1278 05.2001
Using the Library with Various Languages
1. Open Visual C and select ‘ New’ from the ‘File’ menu. Select ‘MFC Appwizar d( exe)’ from the ‘Projects tab. Enter the name ‘VCTutorial’ for the project and press ‘OK’.
MN1278 05.2001
Figure 3-4: Visual C++ 6 New Project (step 1)
15
Mint v4 PC Programming Guide
2. At Step 1 of the wizard, select ‘Dialog based’ and press ‘Finish’.
Figure 3-5: Visual C++ 6 Application Wizard (step 2)
3. Delete all the controls from the dialog (‘OK’ button, ‘Cancel’ button and ‘TODO: Place dialog controls here.’ Text)
16
MN1278 05.2001
Using the Library with Various Languages
4. Select ‘Settings’ from the ‘Project’ menu. Select ‘All configurations’ from the ‘Settings For’ drop list. Select the ‘C/C++’ tab and add _INC_STDAFX_H_ to the end of the ‘Preprocessor defini tions’ list. This will cause the existing “stdafx.h" to be included in the precompiled header.
MN1278 05.2001
Figure 3-6: Project Settings (step 4)
17
Loading...
+ 61 hidden pages