Lmms Linux Multimedia Studio Computer Accessories Mint V4 Pc Programming Guide Users Manual
2015-02-09
: Lmms Lmms-Lmms-Linux-Multimedia-Studio-Computer-Accessories-Mint-V4-Pc-Programming-Guide-Users-Manual-575332 lmms-lmms-linux-multimedia-studio-computer-accessories-mint-v4-pc-programming-guide-users-manual-575332 lmms pdf
Open the PDF directly: View PDF .
Page Count: 88
Download | |
Open PDF In Browser | View PDF |
Mint™ version 4 PC Programming Guide MN1278 Issue 1.2 MN1278 05.2001 Mint v4 PC Programming Guide ii 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 makes no representations or warranties with respect to the contents hereof and specifically disclaims any 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. MINT™ is a registered trademark of Baldor UK Ltd. 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 MN1278 05.2001 Baldor ASR GmbH Telephone: +49 (0) 89 90508-0 Fax: +49 (0) 89 90508-492 Baldor ASR AG Telephone: Fax: +41 (0) 52 647 4700 +41 (0) 52 659 2394 Australian Baldor 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 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 1.1 Feb 00 UM00545-001 1.2 May 2001 UM00545-002 MN1278 05.2001 Comments Raised from MN00249-003. This is a new UM for v4, allowing updates to the v3 manual to continue as MN00249-XYZ Added NextMove PC device driver documentation. Corrected for Mint v4 ( new C++ files, Win2000, WinME. Updates for PC Developer Libraries 1302 release. v Mint v4 PC Programming Guide vi MN1278 05.2001 Contents 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 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 viii 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 MN1278 05.2001 Contents 6.10 Data Synchronisation..............................................................................66 Appendix 2: Timings ................................................................ 67 7.1 Immediate Command Mode Functions ...................................................67 Appendix 3: Symbolic Constants ............................................ 69 Bibliography ............................................................................. 77 MN1278 05.2001 ix Introduction 1. Introduction 1 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. 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. • Updating 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) controllers. • 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, SmartStep, EuroSystem, EuroStep, EuroServo. 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 2 This chapter covers general communication with Mint controllers. 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 Installation Guide for details on installing the device drivers. 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 Installation Guide for details on installing 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 host. • 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 MN1278 05.2001 */ 0 5 Mint v4 PC Programming Guide /* COMMS location uses #define CONTROL_LOCATION #define PARAM_1 */ 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 of the read functions 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, tmmOFF) 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 for 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 doMintBreak doMintRun getSerialChar getSerialCharTimeout getSerialStringTimeout setSerialChar setSerialCharTimeout setSerialStringTimeout 8 Description Sends Ctrl-E to Mint,( bypassing the pseudo-serial buffer on NextMove PC and PCI ). Write RUNRead a char from the pseudo-serial buffer if one is available Read a char from the if one is available within the given period of time. Read up to 64 chars from serial buffer into a string Write a character Writes a character with a timeout Writes a string, timing out if the pseudo-serial transmit buffer is full MN1278 05.2001 Using the Library with Various Languages 3. Using the Library with Various Languages 3 This chapter details the use various different programming languages. The languages covered are: MN1278 05.2001 ◊ C++ ◊ Visual C++ 6 ◊ Visual Basic 6 ◊ Inprise Delphi 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 NextMove PCI NextMove BX MintDrive ServoNode 51 CNextMovePC CNextMovePCI1 CNextMoveBX CMintDrive CServoNode51 nextmove.h nm_pci1.h nm_bx.h mintdrv.h 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 Mint v4 PC Programming Guide are derived from the CController class (defined in BASE.H.) All functions are virtual, so it is safe to pass pointers to objects as (CController*) if the class type to be created is not known at compile time. The following files should be included in your C++ project. 10 File Controller base.cpp baldorserial.cpp host_def.cpp logfile.cpp mme.cpp mml.cpp nextmove.cpp nm_nt.cpp nm_pci1.cpp nm_win32 All All Serial All All MintDrive, NextMove BX, ServoNode 51 All NextMove PC NextMove PC NextMove PCI NextMove PC & PCI MN1278 05.2001 Using the Library with Various Languages File Controller nmbase.cpp nmstd.cpp precomp.cpp serial.cpp syncronisation.cpp uncompress.cpp NextMove PC NextMove PC All All Serial All 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 Settings For: on the left. In the 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. 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 Settings 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 WorkBench 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 Appwizard(exe)’ from the ‘Projects’ tab. Enter the name ‘VCTutorial’ for the project and press ‘OK’. Figure 3-4: Visual C++ 6 New Project (step 1) MN1278 05.2001 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. 16 Delete all the controls from the dialog (‘OK’ button, ‘Cancel’ button and ‘TODO: Place dialog controls here.’ Text) 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 definitions’ list. This will cause the existing “stdafx.h" to be included in the precompiled header. Figure 3-6: Project Settings (step 4) MN1278 05.2001 17 Mint v4 PC Programming Guide 5. Select ‘Precompiled Headers’ in the ‘Category’ drop list. Change ‘stdafx.h’ to ‘precomp.h’ in the ‘Use Precompiled header’ option. Figure 3-7: Project Settings (step 5) 18 MN1278 05.2001 Using the Library with Various Languages 6. Select ‘Preprocessor’ from the ‘Category’ drop list. Add ‘.,’ (dot-comma ) followed by the path to the Mint Interface Library header files in the ‘Additional include directories’ field. Press ‘OK’ to close the dialog. Figure 3-8: Project Settings (step 6) 7. In the ‘FileView’ pane, delete stdafx.cpp. Right-click on ‘VCTutorialFiles’ and select ‘Add Files To Project.’ Add ‘precomp.cpp’ (which should be in the c:\mint\host directory. ) MN1278 05.2001 19 Mint v4 PC Programming Guide 8. Right click on ‘precomp.cpp’ in ‘FileView’ and select ‘Settings’. Select ‘All Configurations’ in the ‘Settings For’ drop list. Select ‘Precompiled headers’ in the category drop-list on the ‘C/C++’ tab. Click the ‘Create Precompiled Header’ radio button and enter ‘precomp.h’ in the text field. Figure 3-9: Project Settings (step 8) 9. 20 Edit ‘VCTutorial.cpp’ and ‘VCTutorialDlg.cpp’. In both files, replace ‘#include “stdafx.h”’ with ‘#include “precomp.h”’. Check the project builds ! MN1278 05.2001 Using the Library with Various Languages 10. Select ‘ClassView’. Right click on ‘CVCTutorialDlg’ and select ‘Add Member Function’. Copy the dialog below. Figure 3-10: Class View dialog (step 10) Hit ‘OK’ to edit the new function. The MILError function will check the return code from all Mint Interface Library functions. Edit the function as follows. __int16 CVCTutorialDlg::MILError(__int16 nError) { if ( erSUCCESS != nError ){ TCHAR szError[ szMAX_ERROR ]; getErrorString( szError, nError ); MessageBox( szError ); } return nError; } 11. At this point an attempt to build the code will fail at the link stage, as the source for getErrorString has not been included. Add ‘host_def.cpp’ to the project and the code should build. MN1278 05.2001 21 Mint v4 PC Programming Guide 12. Select ‘ClassView’. Right click on ‘CVCTutorialDlg’ and select ‘Add Member Variable’. Copy the dialog below. Figure 3-11: ClassView Dialog (step 12) 13. Find CVCTutorialDlg::OnInitDialog() in the file ‘VCTutorialDlg’. Replace the comment ‘// TODO: Add extra initialization here’ with code to initialise the CController * object. This will depend on the controller being used Note that m_pController could have been declared as the class that will be created (e.g. CMintDrive) in which case would not have to be used.. The #define values should be modified to reflect the system being used. MintDrive #define NODE 10 #define COMMPORT 1 #define BAUDRATE 57600 m_pController = dynamic_cast ( new CMintDrive ( NODE, COMMPORT, BAUDRATE, TRUE )); NextMove PC #define NODE 0 #define ADDRESS 0x23C m_pController = dynamic_cast ( new CNextMovePC ( NODE, ADDRESS )); NextMove PCI #define NODE 0 #define CARDNUMBER 0 m_pController = dynamic_cast ( new CNextMovePCI1 ( NODE, CARDNUMBER )); NextMove BX #define NODE 1 #define COMMPORT 2 #define BAUDRATE 9600 m_pController = dynamic_cast ( new CNextMoveBX ( NODE, COMMPORT, BAUDRATE, TRUE )); 22 MN1278 05.2001 Using the Library with Various Languages 14. The code should now compile, but not link. The following files should be added to the project to make it link. MintDrive & NextMove BX base.cpp baldorserial.cpp host_def.cpp ( if you have not already added it ) logfile.cpp mme.cpp mml.cpp serial.cpp synchronisation.cpp uncompress.cpp NextMove PC Base.cpp Host_def.cpp ( if you have not already added it ) logfile.cpp mml.cpp nextmove.cpp nm_nt.cpp nm_win32.cpp nmbase.cpp nmstd.cpp synchronisation.cpp uncompress.cpp NextMove PCI Base.cpp Host_def.cpp ( if you have not already added it ) logfile.cpp mml.cpp nm_pci1.cpp nm_win32.cpp nmbase.cpp synchronisation.cpp uncompress.cpp 15. Add a button to the dialog in the dialog editor. Double-click the button to edit the ‘OnButton1’ routine and add this code. void CVCTutorialDlg::OnButton1() { BOOL b; /*------------------------------------------------*/ /* Display a busy cursor. */ /*------------------------------------------------*/ CWaitCursor cur; /*------------------------------------------------*/ /* Read the state of the axis 0 enable. */ /*------------------------------------------------*/ if ( erSUCCESS != MILError ( m_pController-> getDriveEnable( 0, &b ))) return; MN1278 05.2001 23 Mint v4 PC Programming Guide /*------------------------------------------------*/ /* Toggle it. */ /*------------------------------------------------*/ MILError ( m_pController->setDriveEnable( 0, ( FALSE == b ))); } 3.1.4 Compiling an ATL COM Project with Visual C. When compiling an ATL COM project in Visual C, define _NO_AFX_. This prevents AFX and MFC files being included. 3.1.5 RS485 Networks. Individual controllers on an RS485 network can be accessed from within one application built using the source code. One CController derived object can be created for each node on the network, and they will share the serial port. Other applications will not be able to access controllers on the same port. When using controllers on an RS485 link, remember to call setHandShakeMode(0) to disable hardware handshaking. If there are several CController objects sharing the port, setHandShakeMode(0) only has to be called for one of the controllers. 3.2 All Other Languages : The ActiveX Control ( OCX ) The ActiveX control is known as the Baldor Motion Library. When used, a TMintController object is created. This can be used with a large number of languages. This section documents the use of the control with Visual Basic 6 and Delphi 5, but the principle is the same in any language. 3.2.1 The ActiveX Control And The Languages It Can Be Used With. The control is a Active X (COM) control. It can be used with any languages that support • Long integers (32 bit signed integers) • Short integers ( 16 bit signed integers) • Floats ( 32 bit floating point) • BSTRs (Visual Basic Style strings) • Pointers to all the above types. Some languages do not support all of these data types (e.g. WonderWare InTouch does not support short integers or pointers). For these languages, a ‘wrapper’ COM server may have to be written to convert to types used by the language. Documentation should be provided with each language on how to perform this. 24 MN1278 05.2001 Using the Library with Various Languages 3.2.2 The ActiveX Control and Error Handling. The ActiveX control produces COM (ActiveX) errors (exceptions) if any function fails. These will be trapped by whatever exception handling method is implemented in that language (error handling in Visual Basic is described in more detail in 3.3.1 ) The meaning of the error code can be found as follows: • Mask off the top 16 bits ( or 17 in VB ) as the actual error code is only contained in the lower 16 bits. • If the number is 200 hex ( 512 ) or greater it is a Mint Interface Library error. • 3.2.3 If the number is less than 200 hex ( 512 ) it is a standard COM error created by the framework, not the Mint Interface Library. The ActiveX Control and Serial Controllers. One instance of (part of) the ActiveX control will be shared by all applications that use it. This means that more than one application can access the same serial controller. This is not true of applications written with the C++ source code, where only one application can access a serial controller. 3.2.4 The ActiveX Control and RS485 Networks. To access several nodes on an RS485 network, create one MintController object for each controller. The Visual Basic RS485 example shows how Immediate commands can be performed and also how the command line of each controller can be accessed. When using controllers on an RS485 link, remember to call setHandShakeMode(0) to disable hardware handshaking. If there are several MintController sharing the port, setHandShakeMode(0) only has to be called for one. 3.2.5 Distributing an Executable Which Uses The ActiveX Control. When distributing a program which uses the ActiveX control, the files MILOCXZZZZ.OCX and MILSERVERZZZZ.OCX (where ZZZZ is the version number) must be installed in the windows\system directory and registered. Microsoft DCOM95 must also be installed. The easiest way to do this is to use a package such as InstallShield Express and install MDAC2.0 which forces installation of DCOM95. 3.2.6 ‘Server Busy” / “Component Request Pending” Errors. MN1278 05.2001 25 Mint v4 PC Programming Guide When using the Active Control, warning messages such as the dialog above ( taken from a Visual Basic application ) may be shown for slow operations such as file download. This is because the application expects the ActiveX operation to finish its operation in a certain time ( the default for Visual Basic is five seconds. ) It should be able to change these timeouts or remove the check completely, the method will be different for each language. The following sections give advice on how to do this in Visual Basic and Visual C. “Component Request Pending” in VB. This error ( as shown in the dialog above ) can be prevented by adding the following code before the function which times out is called. App.OleRequestPendingTimeout = 60000 This will increase the timeout to a minute ( the timeout is in milliseconds. ) If this is still not long enough, the value can be increased. “Server Busy” in a Visual C MFC Application. This is described fully in the Microsoft MSDN article Q248019 HOWTO: Prevent Server Busy Dialog Box From Appearing During a Lengthy COM Operation. To solve the problem add the following lines of code to the CWinapp derived classes InitInstance function. AfxOleInit(); 26 MN1278 05.2001 Using the Library with Various Languages AfxOleGetMessageFilter()->EnableNotRespondingDialog( FALSE ); The file will have to include afxole.h 3.3 Visual Basic 6 3.3.1 Error number conversion The error numbers returned in Err after a function call in Visual Basic differ from the constants defined in mil.bas. To convert from an Err code (other than 0) to a MIL error, mask off the top 17 bits by ANDing with &H7FFF and subtract &H200. There is a function called VBErrorToMIL in mil.bas to do this. Public Function VBErrorToMIL(VBError&) As Long If VBError& = 0 Then VBErrorToMIL& = erSUCCESS Else VBErrorToMIL& = (VBError& And &H7FFF) - &H200 End If End Function If the result of this function is negative, the error was produced by VB, not the Mint Interface Library. 3.3.2 A Visual Basic Tutorial. This section will guide you through creating a visual basic 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 WorkBench to do this). 1. Open Visual Basic and create a ‘New’ ‘Standard Exe.’ 2. Select ‘Components’ from the ‘Project’ menu. MN1278 05.2001 27 Mint v4 PC Programming Guide Figure 3-12: Selection of Mint Component 3. Find ‘Baldor Motion Library XXXX for Mint Build XXXX in the list and check the box. In this example the version 1107 is being used, but you this will have changed by the time this manual is printed. If there is a choice of several versions, choose the most recent, unless you want to target an older version of Mint. Hit ‘OK’ This should have added the icon to the toolbox. 4. Select’Add Module’ from the ‘Project’ tab. Click on the ‘Existing’ tab and add ‘mil.bas’ which should be in the ‘c:\mint\host’ directory. 5. Click on the icon in the toolbox and draw a square on the form. This will create a MintController ActiveX control which will be used to communicate with the controller. Click on the control on the form And change the name from MintController1 to myController. 28 MN1278 05.2001 Using the Library with Various Languages 6. In the Form_Load module we will tell the COM server which type of controller we want to communicate with. These means the code will depend on the controller you have. The Consts should be editted to match your system, - MintDrive Private Sub Form_Load() Const NodeNumber = 10 Const CommPort = 1 Const Baudrate = 57600 myController.setMintDriveLink(NodeNumber, CommPort, Baudrate, True) End Sub - NextMove PC Private Sub Form_Load() Const NodeNumber = 0 Const Address = &H23C myController.setNextMovePCLink(NodeNumber, Address) End Sub - NextMove PCI Private Sub Form_Load() Const NodeNumber = 0 Const CardNumber = 0 myController.setNextMovePCI1Link(NodeNumber, CardNumber) End Sub 7. Add a command button, and place the following code behind it. Private Sub Command1_Click() Dim bState As Boolean '********************************************* ' Read the state of the drive enable for axis 0 '********************************************* myController.getDriveEnable 0, bState '********************************************* ' Toggle the state of the enable '********************************************* myController.setDriveEnable 0, (bState = False) End Sub 8. This code should now work. At this stage, an error handler will be added. Change the getDriveEnable code to access an axis that does not exist. E.g. myController.getDriveEnable -1, bState This should create the following error when run. MN1278 05.2001 29 Mint v4 PC Programming Guide Figure 3-13: Example Dialog Box 9. Add the following code to trap this (or any other error). Private Sub Command1_Click() Dim bState As Boolean On Error GoTo command1_error '********************************************* ' Read the state of the drive enable for axis 0 '********************************************* myController.getDriveEnable -1, bState '********************************************* ' Toggle the state of the enable '********************************************* myController.setDriveEnable 0, (bState = False) Exit Sub command1_error: '********************************************* ' Display the error and leave subroutine '********************************************* MsgBox Error$ Exit Sub End Sub 30 MN1278 05.2001 Using the Library with Various Languages 3.4 Borland Delphi 5.0 NOTE: Before any programs, including the examples, can be built, the type library must be imported. See step 2. This section will guide you through creating a simple Delphi application. The application will contain one button which will toggle the state of the drive enable output for axis 0. Note that the axis must already be configured as servo (use the Mint WorkBench to do this). 1. Open Delphi and create a new project. 2. If this is the first time a Delphi Mint Interface Library application has been created on this machine a type library file will have to be created. Select ‘Import ActiveX Control’ from the ‘Components’ menu. Find ‘Baldor Motion Control Library XXXX for Mint XXXX in the list and check the box. In this example the version 1109 is being used, but this will have changed by the time this manual is printed. If there is a choice of several versions, choose the most recent, unless you want to target an older version of Mint. Hit ‘Install…’ and follow the default options. MN1278 05.2001 31 Mint v4 PC Programming Guide Figure 3-14: Delphi – Installing Mint Component 3. Select the ActiveX tab on the toolbar. The rightmost icon should now be the MintController icon. Click the icon and then click Form1 to create an instance of the control. Examining the properties of the control should show that the name is MintController1. 4. We now have to edit the FormCreate function. Double click on Form1 to open the FormCreate function. The line of code depends on the controller being used. It will tell the COM server which type of controller we want to communicate with. These means the code will depend on the controller you have. The consts should be editted to match your system, 32 MN1278 05.2001 Using the Library with Various Languages - MintDrive procedure TForm1.FormCreate(Sender: TObject); const NodeNumber = 10; const CommPort = 1; const BaudRate = 57600; begin MintController1.setMintDriveLink( NodeNumber, CommPort, BaudRate, TRUE ); end; - NextMove PC procedure TForm1.FormCreate(Sender: TObject); const NodeNumber = 0; const Address = $23c; begin MintController1.setNextMovePCLink( NodeNumber, Address ); end; - NextMove PCI procedure TForm1.FormCreate(Sender: TObject); const NodeNumber = 0; const CardNumber = 0; begin MintController1.setNextMovePCI1Link( NodeNumber, CardNumber ); end; end. 5. Add a button and double click on it to edit the Button1Click procedure. Add the following code. procedure TForm1.Button1Click(Sender: TObject); var wbEnabled : WordBool; begin { Read the current state of the drive enable. } MintController1.getDriveEnable( 0, wbEnabled ); { Write back the toggled value. } MintController1.setDriveEnable( 0, ( wbEnabled = FALSE )); end; end. MN1278 05.2001 33 Mint v4 PC Programming Guide 6. This code should now run. To add an error handler, change the first parameter to setDriveEnable to –1 to create a run time error. This will raise an EOleException error. To trap this error, modify the code as follows. procedure TForm1.Button1Click(Sender: TObject); var wbEnabled : WordBool; begin { Trap errors. All errors will cause program flow to jump to the except } try { Read the current state of the drive enable. } MintController1.getDriveEnable( 0, wbEnabled ); { Write back the toggled value. } MintController1.setDriveEnable( 0, ( wbEnabled = FALSE )); except { This is called on any function in the try block failing } On E: Exception do MessageBox ( 0, pchar(E.Message), 'Mint Interface Library Call failed', 0 ); end; end; To prevent Delphi from halting program execution in the event of an exception the ‘Stop on Delphi Exceptions’ check box must be cleared. This is found in the ‘Debugger Options’ from the ‘Tools’ menu. Figure 3-15: Delphi - Debugger Options 34 MN1278 05.2001 PC Based Motion Control 4. PC Based Motion Control 4 This chapter covers creating motion applications on the host PC. MN1278 05.2001 35 Mint v4 PC Programming Guide The Mint Interface Library provides all of the functionality that is available in the Mint programming language. Motion applications can be written on the host PC by calling functions from the Mint Interface Library. When a function is called, the Mint Interface Library communicates with the controller and calls the specified function directly on the controller. The Mint functionality is still being performed by the controller but it has been initiated directly by a host application. The real-time elements of Mint are still run on the controller but the sequencing can be controlled by the host application. The following diagram shows the architecture, known as Immediate Command Mode: Controller Host Terminal/ Comms Mint Host I/F ICM MIL Device Driver MINT Motion Library Profiler xN Servo Loop xN Figure 4-1: Immediate Command Mode Interface Immediate Command Mode (ICM) is the method that allows Mint motion functions to be called from a host application, bypassing Mint. Calling functions from the host is particularly useful if there is a large amount of processing to do (i.e. calculation of multi-axis paths) as the host can do the processing and send the commands to the controller. Note that these functions can be used in conjunction with a Mint program. For example a Mint program handles the I/O and the host calculates the path and sends it to the controller using setVectorA(). The Immediate Command Mode interface can also be used for testing applications to be compiled by a C31 compiler and run on NextMove. This is described in Mint v4 Embedded Programming Guide. There is a one to one correlation between Mint commands and Mint Interface Library Functions. For example, within a Mint program, the MOVER keyword is used to create a relative positional move on an axis. MOVER.0 = 10 The Mint Interface Library function for this is setMoveR. setMoveR (0, 10) The keyword has been prefixed with set. Almost all Mint keywords are available in the Mint Interface Library. The will be prefixed with set for writes, get for reads and do for commands. 36 MN1278 05.2001 PC Based Motion Control Functions called from the host fall into two categories. Those functions that replicate Mint keywords are known as Mint Motion Library calls (MML) and those functions which are general communications functions are known as Mint Interface Library calls (MIL). Example: The following code is a Visual Basic extract showing a host application set up a move on a NextMove BX. The TMintController object has been added to the form and named ‘myController’. ‘ Set up some data Dim axis0(1) As Integer Dim isIdle As Boolean axis0 = 0 ' Create handle to NextMove: node, comm port, baud rate, open myController.setNextMoveBXLink 2, 1, 19200, 1 ‘ Set move parameters on myController.setSpeed 0, myController.setAccel 0, myController.setDecel 0, myController.doReset 0 axis 0 40! 400! 400! ‘ Load the move and start it myController.setMoveR 0, 100 myController.doGo 1, axis0 ‘ Wait until move is completed Do myController.getIdle 0, isIdle Loop Until isIdle 4.1 Limitations of PC based applications There are a number of event handlers available in Mint such as #ONERROR. Only NextMove PCI supports events to the host. This means that event handlers can be installed in the host application that are called directly when a Mint event occurs. For other controllers, the event handlers must be placed in a Mint program. Commands called from the host execute slower than if called directly on the controller. See Appendix 2 for example timings. The host functions take priority over the Mint program running on the controller. If MML functions are called continuously from the host, this will slow the execution speed of the Mint program. MN1278 05.2001 37 Mint v4 PC Programming Guide 4.2 Events and Interrupt Control on NextMove PCI The NextMove PCI controller requires a device driver to be installed on the host PC in order for communication to be established between it and the controller. The use of device drivers makes it possible for interrupts from the card to be trapped and handled. The Dual Port RAM interface allows the PC to interrupt the controller and the controller to interrupts the host. Interrupt handling using the NextMove PCI controller is supported under both Windows NT and Windows 95 and 98. 4.2.1 Writing and Installing an Interrupt Handler When the controller interrupts the host PC the device driver will trap the interrupt and determine what ‘type’ of event has occurred. Following this it will call the appropriate event handler. NextMove can generate a number of events in response to certain situations: • Axis idle - an axis has become idle. • CAN 1 (CAN Open) – an event on CAN bus 1 • CAN 2 (Baldor CAN) – an event on CAN bus 2 • Comms – the comms location 1 to 5 has been written to • DPR event – the user generated a DPR event ( see 4.2.3 Interrupting the Host from a Mint Program ( DPR Events )) • Errors – an error occurred on the NextMove card • Fast position latch – an axis has latched position • Digital input active – a digital input has become active • Move buffer low - the numbers of moves in a move buffer drops below a specified threshold. • Reset – the NextMove PCI card has reset • Serial receive – the controller has put a character into its pseudo serial transmit buffer. • Stop switch – a stop switch has become active • Timer – the timer event period has expired The events are prioritised in the following order: Priority 0: Highest 1 2 3 4 5 38 Event Serial Receive Error CAN 1 (CANOpen) CAN 2 (Baldor CAN) Stop switch Fast position latch MN1278 05.2001 PC Based Motion Control Priority 6 7 8 9 10 11 Event Timer Digital input Comms DPR event Move Buffer Low Axis Idle Note: The reset event is generated if the controller resets, hence this is not generated by the firmware and is consequently not subject to the priority scheme. The NextMove PCI controller will check for a pending event every 2ms. If multiple events occur within a 2ms tick, then the above priority system will be used to decide which event to generate. A higher priority event will interrupt a lower priority event. Each event is processed within a separate thread by the host PC application. If more than one event is active on the host PC they will execute concurrently. In order for an event to be generated the, the appropriate event handler must be installed. The event handlers are installed with the following functions in C++: Axis Idle The install function for axis idle events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TAxisIdleEventHandler (void *pController, __int16 nAxisBitPattern) __int16 installAxisIdleEventHandler (TAxisIdleEventHandler *pHandler) CAN1 The install function for CAN events on bus 1, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TCANEventHandler (void *pController) __int16 installCAN1EventHandler (TCANEventHandler *pHandler) CAN2 The install function for CAN events on bus 2, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TCANEventHandler (void *pController) __int16 installCAN2EventHandler (TCANEventHandler *pHandler) Comms The install function for Comms events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TCommsEventHandler (void *pController, __int32 lCommsEventPending) __int16 installCommsEventHandler (TCommsEventHandler *pHandler) MN1278 05.2001 39 Mint v4 PC Programming Guide DPR The install function for DPR events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TDPREventHandler (void *pController, __int16 nCode) __int16 installDPREventHandler (TDPREventHandler *pHandler) Errors The install function for error events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TErrorEventHandler (void *pController) __int16 installErrorEventHandler (TErrorEventHandler *pHandler) Fast Position Latch The install function for fast position latch events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TFastInEventHandler (void *pController) __int16 installFastInEventHandler (TFastInEventHandler *pHandler) Digital Input The install function for digital input events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TInputEventHandler (void *pController, __int16 nBank, __int32 lActivatedInputs) __int16 installInputEventHandler (TInputEventHandler *pHandler) Move Buffer Low The install function for move-buffer-low events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TMoveBufferLowEventHandler (void *pController, __int16 nAxisBitPattern) __int16 installMoveBufferLowEventHandler (TMoveBufferLowEventHandler *pHandler) Reset The install function for reset events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TResetEventHandler (void *pController, __int16 nCode) __int16 installResetEventHandler (TResetEventHandler *pHandler) Serial Recieve The install function for serial receive events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TSerialReceiveEventHandler (void *pController) __int16 installSerialReceiveEventHandler (TSerialReceiveEventHandler *pHandler) 40 MN1278 05.2001 PC Based Motion Control Stop Switch The install function for stop switch events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TStopSwitchEventHandler (void *pController) __int16 installStopSwitchEventHandler (TStopSwitchEventHandler *pHandler) Timer The install function for timer events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. The parameter passed to the event handler is always zero. typedef void TTimerEventHandler (void *pController, __int16 nTimerEvent) __int16 installTimerEventHandler (TTimerEventHandler *pHandler) Unknown The install function for unknown events, it accepts a pointer to a function, if this is a NULL pointer the handler is uninstalled. typedef void TUnknownEventHandler (void *pController, __int16 nCode) __int16 installUnknownEventHandler (TUnknownEventHandler *pHandler) This handler will pick up any otherwise un-handled interrupt codes on the host. Under normal circumstances it will not be called, as all interrupts will be routed to the appropriate event hander. If this handler is not installed then unknown interrupts will be discarded. Example: The following code sample will install a timer event handler. // prototypes void cdecl FAR myTimerEventHandler (void *p, __int16 nTimerEventNumber); // main program void main ( void ) { // Create an instance of the CNextMovePCI class CNextMovePCI1 myPCI ( 0, 0 ); // install timer event handler myPCI.installTimerEventHandler ( myTimerEventHandler )); myPCI.setTimerEvent(1000); while(1) { myPCI.setRelay(0, 1); myPCI.doWait(500); myPCI.setRelay(0, 0); myPCI.doWait(500); } // set periodic timer event to 1000ms // Turn the main board relay on // Wait for 500 ms // Turn the main board relay off // Wait for 500 ms } MN1278 05.2001 41 Mint v4 PC Programming Guide // timer event handler void myTimerEventHandler ( void *p, __int16 nTimerEventNumber ) { cout << "Timer Event” << endl; } When a host PC event handler is called, the embedded application running on the controller will continue to execute. 4.2.2 Event Control Functions There are various functions that can be used to control events generation. These are detailed below The user can read which events are currently active using the function: getEventActive Any currently pending events can be cleared selectively using the function: setEventPending This accepts the same bit pattern as above, clearing a set bit will clear the pending flag for that event. Hence passing a value of zero will clear all pending interrupts. Once a handler has been installed the event generation can be disabled by using the function: setEventDisable This function accepts a bit pattern as above. Setting a bit will disable the generation of that type of event. Hence setting this to zero will enable all events which have a handler installed. The function: getEventDisable Will return a bit pattern of any currently disabled interrupts. By default all digital inputs will generate events when they become active. These digital inputs can be masked so that they do not generate events using the function: setIMask This function accepts a bit pattern which represents all digital inputs, it the bit is set then the digital input will generate an event when the input becomes active. Then function: getIMask Will return a bit pattern representing those digital inputs which will generate an event when they become active. 42 MN1278 05.2001 PC Based Motion Control 4.2.3 Interrupting the Host from a Mint Program ( DPR Events ) Events can be manually generated in both directions using the function doDPREvent and the DPREvent handler. If the host PC calls doDPREvent, this will generate an interrupt to the controller that will call the DPREvent handler on the controller. If the controller calls the function doDPREvent, this will generate an interrupt to the host PC that will call the DPREvent handler on the host PC. The function doDPREvent accepts an 8 bit code which is passed to the event handler. Example: The below code sample will install a DPREvent handler on the host, when a DPREvent is received the code is printed. // prototypes void myDPREventHandler (void *p, __int16 nCode); // main program void main(void) { // Create an instance of the CNextMovePCI class CNextMovePCI1 myPCI(0, 0); // install timer event handler myPCI.installDPREventHandler ( myDPREventHandler )); } // DPREvent handler void myDPREventHandler (void *p, __int16 nCode) { cout << "DPR Event ” << nCode << endl; } When this application is running on the host PC, calling DPREVENT from either Mint or an embedded application will generate an interrupt to the PC calling the DPREvent handler. 4.2.4 Handling Events Using the ActiveX Control As the ActiveX control supports all events; hence, any application that can use the ActiveX control can trap and handle events from the controller. This allows event handling using Visual Basic and Delphi. Once the ActiveX Control has been included in the project, the event handlers are accessed as ActiveX events. The functions listed below are used to tell the controller that a handler exists on the host PC and events of this type should be generated. installAxisIdleEventHandler installCAN1EventHandler installCAN2EventHandler installCommsEventHandler installDPREventHandler MN1278 05.2001 43 Mint v4 PC Programming Guide installErrorEventHandler installFastInEventHandler installInputEventHandler installMoveBufferLowEventHandler installSerialReceiveEventHandler installStopSwitchEventHandler installResetEventHandler installTimerEventHandler installUnknownEventHandler The passed parameter is a BOOLEAN parameter. • TRUE indicates that a handler exists on the host PC • FALSE indicates that a handler does not exist on the host PC. VisualBasic Example: Create a MintController object called ‘nmPCI’. in the Form_Load function add: nmPCI.setNextMovePCI1Link 0, 0 nmPCI.installTimerEventHandler TRUE nmPCI.setTimerEvent 1000 Double click on the MintController object and select the TimerEventHandler function, add the code: Dim b As Boolean nmPCI.getRelay 0, b If b Then nmPCI.setRelay 0, 0 Else nmPCI.setRelay 0, 1 End If When the timer event is generated on the controller, this will interrupt the host PC and create a timer event. This is trapped by the ActiveX control and executes the code in the timer event. In this example the timer event is set to trigger every second, the code within the timer event handler will toggle the state of the relay. 44 MN1278 05.2001 NextMove PCI and Non-Micorsoft Operating Systems 5. NextMove PCI and Non-Microsoft Operating Systems 5 This chapter details how to use the NextMove PCI with operating systems other than Windows NT and Windows 9x. MN1278 05.2001 45 Mint v4 PC Programming Guide This Chapter covers implementing an interface to NextMove PCI in under an operating system other than the systems supported by the standard Baldor Motion Toolkit for example QNX, Linux etc. A special version of the CNextMovePCI1 class has been written. This class (called CSimplePCI) provides all the functions required except the actual hardware interface functions, which must be provided by the user. 5.1 How to Recognize the NextMove PCI. To find the NextMove PCI, the computer’s PCI controller must be interrogated. The method for this will differ between operating systems. Each PCI device can be recognized by its Vendor ID and Device ID. For a NextMove PCI the following applies: Vendor ID = 145F(Hex) Device ID = 0001. 5.2 Host Accessible Hardware on NextMove PCI. The are three blocks of hardware which can be accessed on NextMove PCI. One of these is mapped into both memory and IO space, so it appears as if there are four blocks which can be accessed. Block Size Map type 1 128 bytes Memory 2 128 bytes I/O 3 4 16K 32 bytes Memory I/O Description This is NextMove’s PCI chip (also referred to as the PLX chip.) It controls the hardware reset and interrupt lines. This is also the PCI controller chip, but mapped into IO space, not memory. This is the Dual Port RAM. This is currently unused. Of these, the two memory mapped areas ( blocks 1 and 3 ) will be used. Blocks 2 and 4 are can be ignored. The memory mapped addresses of blocks 1 and 3 should be read from the computers PCI controller. The memory address of Block 1 must be stored for the functions PLXRead and PLXWrite and the address Block 3 is mapped into must be stored for use with the functions getLong and setLongInternal. 5.3 The CSimplePCI class. The CSimplePCI class splits the hardware access functions from the rest of the Mint Interface Library. To use the class inherit from the CSimplePCI class and supply the virtual functions required (listed below). The easiest way to do this is to modify the CMySimplePCI example. 46 MN1278 05.2001 NextMove PCI and Non-Micorsoft Operating Systems 5.3.1 The CMySimplePCI Example. The CMySimplePCI example overloads CSimplePCI to create a class which can be used to communicate with NextMove PCI under Windows 9X and Windows NT using the CSimplePCI interface. It is laid out in such a way that the Windows specific code can easily be replaced with code specific to another operating system. 5.3.2 Functions Required by the Overloaded Class. The CMySimplePCI class declaration is as follows. It shows all the functions required. #include "simplepci.h" class CMySimplePCI : public CSimplePCI{ public: /*------------------------------------------------------------------*/ /* START : These functions MUST be defined. */ /*------------------------------------------------------------------*/ CMySimplePCI ( int nNode, int nCard ); __int16 doDeviceClose ( void ); __int16 getDeviceOpen ( BOOL *bOpen ); __int16 doDeviceOpen ( void ); __int16 getLong ( __int16 nAddress, __int32 FAR *lplValue ); protected: __int16 InternalSetLong ( __int16 nAddress, __int32 lLong ); __int16 PLXRead ( __int16 nRegister, __int32 *plValue ); __int16 PLXWrite ( __int16 nRegister, __int32 lValue ); /*------------------------------------------------------------------*/ /* END : These functions MUST be defined. */ /*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/ /* START : Replace this. */ /*------------------------------------------------------------------*/ protected: bool m_bWinNT; // true : WinNT, false Win9X HANDLE m_hndFile; // Handle to the device driver. /*------------------------------------------------------------------*/ /* END : Replace this. */ /*------------------------------------------------------------------*/ }; The header shows how the code in the CMySimplePCI example is laid out. There are blocks marked with /*================================================================*/ /* START : Replace this */ /*================================================================*/ MN1278 05.2001 47 Mint v4 PC Programming Guide … … /*================================================================*/ /* END : Replace this */ /*================================================================*/ which show code that is only relevant to the example. This is code that should be replaced with code specific to that operating system. Only code in the files MySimplePCI.h and MySimplePCI.cpp should be modified. Do NOT modify SimplePCI.h and SimplePCI.cpp Constructor. A constructor must be supplied. This constructor must call the CSimplePCI constructor, passing the node and card number. Any other parameters required by the class may be passed. The CMySimplePCI constructor is as follows /*--------------------------------------------------------------------*/ /* CMySimplePCI */ /* */ /* Function: Constructor */ /* */ /* Argument list: */ /* int nNode - Node number : not currently used */ /* int nCard - PCI card number */ /* Return value: */ /* */ /*--------------------------------------------------------------------*/ CMySimplePCI::CMySimplePCI( int nNode, int nCard ) : CSimplePCI ( nNode, nCard ) { /*==================================================================*/ /* START : Replace this */ ====================================================================*/ m_hndFile = INVALID_HANDLE_VALUE; /*------------------------------------------------------------------*/ /* Find if we are running under Win9X or WinNT. */ /*------------------------------------------------------------------*/ OSVERSIONINFO VersionInfo; VersionInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO ); GetVersionEx ( &VersionInfo ); m_bWinNT = ( 0 != ( VersionInfo.dwPlatformId & VER_PLATFORM_WIN32_NT )); /*==================================================================*/ /* END : Replace this */ ====================================================================*/ doDeviceOpen (); } The constructor should initialize any required data and then call doDeviceOpen() to allow communications with the controller to start. 48 MN1278 05.2001 NextMove PCI and Non-Micorsoft Operating Systems doDeviceClose This function releases any resources which had been taken by the class. getDeviceOpen This function must report whether the class has control of any resources it requires to communicate with the controller and whether that controller is physically present. In the MySimplePCI example this reports whether it can communicate with device driver. In Windows 95 on instance of the device driver is created in memory per device it finds, so if the device driver instance exists in memory, the NextMove PCI is present. Under Windows NT, there is one device driver to handle all NextMoves, so the device driver must be interrogated to find if that card number is present. doDeviceOpen This function must take any resources required to communicate with the controller. In the MySimplePCI example, this creates a handle to the device driver. getLong This function must read from DPR (block 3 in section 5.2 ) This may take the form of (as in the MySimplePCI example) instructing the device driver to perform the task. The read should be a simple 32 bit read from the memory address the DPR has been mapped into (Block 3). internalSetLong This function must write to DPR (block 3 in section 5.2). This may take the form of (as in the MyMySimplePCI example) instructing the device driver to perform the task. The write should be a simple 32 bit write to the memory address the DPR has been mapped into (Block 3). PLXRead This function must read from the PLX chip (Block 3 in section 5.2) This may take the form of (as in the MySimplePCI example) instructing the device driver to perform the task. The read should be a simple 32 bit read from the memory address the PLX chip has been mapped into (Block 1). PLXWrite This function must write to the PLX chip (Block 3 in section 5.2 ) This may take the form of (as in the MySimplePCI example) instructing the device driver to perform the task. The write should be a simple 32 bit write to the memory address the PLX chip has been mapped into (Block 1). 5.3.3 Files to Include in a CSimplePCI Derived Class Project. The following Mint Interface Library files must be included in the project: • base.cpp • mml.cpp • nmbase.cpp • simplepci.cpp MN1278 05.2001 49 Mint v4 PC Programming Guide The following files may also be added: • host_def.cpp : if the function getErrorString is being used. • precomp.cpp : if this file is being used to construct the precompiled header. 50 MN1278 05.2001 Appendix 1: DPR Map 6. Appendix 1: DPR Map Each area of the address map is described below. Where an address is shown, that is the DPR location. Where an address offset is shown, that offset is added to the base address. Floating point numbers will conform to C31 format. It is up to the PC interface to convert to IEEE format before passing the data to the PC application. Likewise, IEEE floating point numbers must be converted to C31 format before writing to the DPR. All library functions do this automatically. • The update time on NextMove is 2ms. • Where units are shown, the key is as follows: uu - user units uu/s - user units / second au - analogue units. (See ADCMode keyword for explanation of ranges) % - percentage cts - encoder counts • All addresses and address offsets are in hex. 6.1 NextMove PCI DPR Map Dual Port RAM on NextMove PCI has 4K of 32 bit data. The DPR map is similar to NextMove PC but certain areas are designated as read only. This means that if the user tries to write to these locations, the data may be corrupted. The Dual Port RAM on NextMove PCI is 32 bit rather than the 16 bit wide DPR on NextMove PC, hence 32 bit values on will use two 16 bit DPR locations. In order for the memory map of DPR to be consistent between the two controllers where 32 bit values are stored, NextMove PCI will have a redundant location. Address 0xFFF Control Registers 0xFE0 0xFDF Use 0xFFF 0xFFE 0xFFD Read Only Interrupt Host Interrupt NextMove Reserved 0xFE0 0xFDF 1K User Area 0xBE0 0xBDF 0xBE0 Reserved for future use MN1278 05.2001 51 Mint v4 PC Programming Guide Address Use 0x600 0x5FF 0x5FF 0x500 0x4FF 0x500 0x4FF 0x480 0x480 0x47F Read Only ICM expansion Reserved for future axes Axis 11 Data Axis 10 Data Axis 9 Data Axis 8 Data 0x460 0x45F 0x440 0x43F 0x420 0x41F Axis Data 0x400 0x3FF Control Registers 0x3FB 0x3FA 0x3F9 0x3F8 0x3F7 0x400 0x3FF 0x3FE 0x3FD 0x3FC 0x3FB 0x3FA 0x3F9 0x3F8 0x3F7 0x29C 0x29B 0x29C 0x29B 0x1D6 0x1D5 0x1D6 0x1D5 Reserved Reserved Scratchpad (Unused) Functionality Code Application Code Interrupt Data Interrupt Data ICM handshake Reserved (Old user area) Comms (99 locations) Serial Transmit Buffer Serial Receive Buffer Immediate Command Mode 0x193 0x192 Pseudo Serial 0x150 0x14F 52 0x150 0x14F MN1278 05.2001 Appendix 1: DPR Map Address Use 0x130 0x12F 0x130 0x12F 0x110 0x10F 0x110 0x10F Read Only IO Data Axis 7 Data Axis 6 Data Axis 5 Data Axis 4 Data Axis 3 Data Axis 2 Data Axis 1 Data Axis 0 Data Reserved 1ms Timer Tick Axis Configurations (8-11) Axis Configurations (0-7) MINT Error Line MINT Error MINT Status MINT Line Number 2ms Timer Tick Build ID Analog I/O Mix Digital I/O Mix 0x0F0 0x0EF 0x0D0 0x0CF 0x0B0 0x0AF 0x090 0x08F 0x070 0x06F 0x050 0x04F 0x030 0x02F Axis Data 0x010 0x00F Status/Control Registers MN1278 05.2001 0x010 0x00F 0x00E 0x00D 0x00C 0x00B 0x00A 0x009 0x008 0x007 0x006 0x005 0x004 0x003 53 Mint v4 PC Programming Guide Address 0x000 6.2 Use 0x002 0x001 0x000 Read Only Axis Mix DPR Status Register DPR Control Register NextMove PC DPR Map Dual Port RAM on NextMove PC has 1K of 16 bit data. Address Use Control Registers 0x3FB 0x3FA 0x3F9 0x3F8 0x3F7 0x3FF 0x3FE 0x3FD 0x3FC 0x3FB 0x3FA 0x3F9 0x3F8 0x3F7 0x29C 0x29B 0x29C 0x29B 0x1D6 0x1D5 0x1D6 0x1D5 0x3FF Read Only Interrupt Host Interrupt NextMove Scratchpad (Unused) Functionality Code Application Code Interrupt Data Interrupt Data ICM handshake Reserved (Old user area) Comms (99 locations) Serial Transmit Buffer Serial Receive Buffer Immediate Command Mode IO Data Axis 7 Data Axis 6 Data 0x193 0x192 Pseudo Serial 0x150 0x14F 0x150 0x14F 0x130 0x12F 0x130 0x12F 0x110 0x10F 0x110 0x10F 0x0F0 0x0EF 0x0D0 54 MN1278 05.2001 Appendix 1: DPR Map Address Use Read Only 0x0CF Axis 5 Data Axis 4 Data Axis 3 Data Axis 2 Data Axis 1 Data Axis 0 Data Reserved 1ms Timer Tick Axis Configurations (4-7) Axis Configurations (0-3) MINT Error Line MINT Error MINT Status MINT Line Number 2ms Timer Tick Build ID Analog I/O Mix Digital I/O Mix Axis Mix DPR Status Register DPR Control Register 0x0B0 0x0AF 0x090 0x08F 0x070 0x06F 0x050 0x04F 0x030 0x02F Axis Data 0x010 0x00F Status/Control Registers 0x000 MN1278 05.2001 0x010 0x00F 0x00E 0x00D 0x00C 0x00B 0x00A 0x009 0x008 0x007 0x006 0x005 0x004 0x003 0x002 0x001 0x000 55 Mint v4 PC Programming Guide 6.3 Status and Control Registers Address 0x000 0x001 0x002 0x003 0x004 0x005 0x006 0x007 0x008 0x009 0x00A 0x00B 0x00C 0x00D 0x00F Use Symbolic Constant Read Only DPR Control Register DPR Status Register Axis Mix Digital I/O Mix Analog I/O Mix Build ID 2ms Timer Tick MINT Line Number MINT Status MINT Error MINT Error Line Axis Configurations (PCI:0-7, PC:0-3 ) Axis Configurations (PCI:8-11, PC:4-7 ) 1ms Timer Tick Reserved roCONTROL roSTATUS roAXIS_MIX roNUM_DIO roNUM_AIO roBUILD roTIMER_TICK roMINT_LINE roMINT_STATUS roMINT_ERR roMINT_ERL roAXIS_CF n/a ro1MS_TIMER n/a DPR Control Register – NextMove PCI: Bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 - 16 17 18 19-31 56 Meaning Symbolic Constant Lock DPR contents Lock axis 0 DPR contents Lock axis 1 DPR contents Lock axis 2 DPR contents Lock axis 3 DPR contents Lock axis 4 DPR contents Lock axis 5 DPR contents Lock axis 6 DPR contents Lock axis 7 DPR contents Lock axis 8 DPR contents Lock axis 9 DPR contents Lock axis 10 DPR contents Lock axis 11 DPR contents Reserved Lock IO data Lock auxiliary axes Reserved btLOCK btLOCK_AXIS_0 btLOCK_AXIS_1 btLOCK_AXIS_2 btLOCK_AXIS_3 btLOCK_AXIS_4 btLOCK_AXIS_5 btLOCK_AXIS_6 btLOCK_AXIS_7 btLOCK_AXIS_8 btLOCK_AXIS_9 btLOCK_AXIS_10 btLOCK_AXIS_11 btLOCK_IO btLOCK_AUX_AXES MN1278 05.2001 Appendix 1: DPR Map DPR Control Register – NextMove PC: Bit 0 1 2 3 4 5 6 7 8 9 10 11-15 Meaning Symbolic Constant Lock DPR contents Lock axis 0 DPR contents Lock axis 1 DPR contents Lock axis 2 DPR contents Lock axis 3 DPR contents Lock axis 4 DPR contents Lock axis 5 DPR contents Lock axis 6 DPR contents Lock axis 7 DPR contents Lock IO data Lock auxiliary axes Reserved btLOCK btLOCK_AXIS_0 btLOCK_AXIS_1 btLOCK_AXIS_2 btLOCK_AXIS_3 btLOCK_AXIS_4 btLOCK_AXIS_5 btLOCK_AXIS_6 btLOCK_AXIS_7 btLOCK_IO_PC btLOCK_AUX_AXES_PC DPR Status Register: Bit 0 1 2 - 15 Meaning Symbolic Constant DPR Contents locked if 1 DPR contents invalid if 0 Reserved btLOCKED btVALID Axis Mix: This specifies the number and types of axes available on the NextMove variant: Lo-Byte - Number of stepper axes Hi-Byte - Number of servo axes Digital I/O Mix: This specifies the number of digital inputs and outputs available on the NextMove variant: Lo-Byte - Number of digital outputs Hi-Byte - Number of digital inputs Analog I/O Mix: This specifies the number of analog inputs and outputs available on the NextMove variant: Lo-Byte - Number of analogue outputs Hi-Byte - Number of analogue inputs MN1278 05.2001 57 Mint v4 PC Programming Guide MML Build ID: The build identifier of the Mint Motion Library running on NextMove. Each version of the Mint Interface Library can only communicate with one version of Mint. To make sure the versions match, each version of Mint has a build number embedded in it. To return the build number call getAAABuild. Timer Tick: This is a free running 16bit counter that is updated by NextMove once every 2ms and can be used to synchronize data with the DPR. Mint Line Number: This is the currently executing Mint program line. By reading this location, it is possible to trace program execution without affecting program flow unlike Mints built in program tracer. The Mint status flag should be read to determine which buffer is currently being executed. Mint Status: The Mint Status flag consists of various bit masks for status information. The top 8 bits convey the current Mint error status. If a programming error occurs that results in the termination of a program, the top 8 bits will reflect the error. The Mint Line Number register will determine the line on which the error occurred. Bit 0 1 2 3-7 Meaning Symbolic Constant Command line interface not available. Program or config file running. Config buffer if 0, program buffer if 1 1 if Mint is executing code Reserved mkNOT_COMMAND_LINE mkPROGRAM mkEXECUTING Mint Error: The Mint ‘ERR’ code for the last Mint error that occurred. Mint Error Line: The Mint line number where the last Mint error occurred. Axis Configurations: NextMove PC: The current axis configurations are written to two 16 bit locations, each axis configurations represented by 4 bits. Each four bit location holds the axis CONFIG value. DPR location 0x0B 0x0C 58 Bits 12-15 Bits 8-11 Bits 4-7 Bits 0-3 Axis 3 Axis 7 Axis 2 Axis 6 Axis 1 Axis 5 Axis 0 Axis 4 MN1278 05.2001 Appendix 1: DPR Map NextMove PCI: Axis Configurations gives the current configuration of each axis in 4 bits. 31 28 Axis 7 31 28 - 27 24 Axis 6 27 24 23 20 Axis 5 23 - 20 - 19 16 Axis 4 19 16 - 15 12 Axis 3 15 12 Axis 11 11 8 Axis 2 11 8 Axis 10 7 4 3 0 Axis 1 Axis 0 7 3 4 Axis 9 0 Axis 8 Values are: 0 – Axis is configured off. 1 – Axis is configured as a servo axis. 2 – Axis is configured as a stepper axis. 3 – Axis is configured for PWM. The 1ms Timer Tick is an incrementing counter that indicates that NextMove is running. The counter is 32 bit. The counter increments by 1 every 1ms. 6.4 Axis Data The axis data area is divided into 12sections, four for the main board axes and four for the expansion board axes. The base address for each axis is listed below: Address 0x010 0x030 0x050 0x070 0x090 0x0A0 0x0C0 0x0E0 0x400 0x420 0x440 0x460 Use Symbolic Constant Axis 0 Axis 1 Axis 2 Axis 3 Axis 4 Axis 5 Axis 6 Axis 7 Axis 8 Axis 9 Axis 10 Axis 11 roAXIS_0 roAXIS_1 roAXIS_2 roAXIS_3 roAXIS_4 roAXIS_5 roAXIS_6 roAXIS_7 roAXIS_8 roAXIS_9 roAXIS_10 roAXIS_11 Each group contains the following data. MN1278 05.2001 59 Mint v4 PC Programming Guide Offset 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E 0x1F Use Symbolic Constant Data Size Measured Position Reserved Measured Velocity Reserved Speed* Reserved Mode of motion Reserved Axis error Following Error Reserved Kprop* Reserved Kvel* Reserved KvelFF* Reserved Kderiv* Reserved Kint* Reserved KintLimit(%)* Reserved Next Mode of motion Reserved DAC value Free Spaces in buffer Move buffer ID Demand Position Reserved Demand Velocity Reserved roPOSITION float roMEASURED_SPEED float roDEMAND_SPEED float roMODE_OF_MOTION int 32 roMOTION_ERROR roFOLLOWING_ERROR int 32 float roP_GAIN float roV_GAIN float roFF_GAIN float roD_GAIN float roI_GAIN float roI_RANGE float roNEXT_MODE int 32 roDAC_VALUE roFREE_SPACES roMOVE_ID roDEMAND_POS int 16 int 16 int 16 float roDEMAND_VEL float The layout of the section is compatible to the current layout on NextMove PC. The locations used on NextMove PC for the upper 16 bits of data are unused. All data is written every 2ms by NextMove except those marked *. These locations are only written when they change. 60 MN1278 05.2001 Appendix 1: DPR Map 6.5 I/O Data The I/O data area is as follows: Address 0x110 0x111 0x112 0x113 0x114 0x115 0x116 0x117 0x118 0x119 0x11A 0x11B 0x11C 0x11D 0x11E 0x11F 0x120 0x121 0x122 0x123 0x124 0x125 0x126 0x127 0x128 0x129 0x12A 0x12B 0x12C 0x12D 0x12E 0x12F 1 Use Symbolic Constant Data Size Analog 0 Analog 1 Analog 2 Analog 3 Expansion Analog 4 Expansion Analog 5 Expansion Analog 6 Expansion Analog 7 Base Digital inputs Reserved Base Digital Outputs Stop / Error bits Boost Outputs1 Auxiliary Encoder 0 Reserved Auxiliary Encoder 0 vel Reserved Auxiliary Encoder 1 Auxiliary Encoder 1 vel Auxiliary Encoder 2 Auxiliary Encoder 2 vel Expansion 1 Digital Inputs Expansion 1 Digital Outputs Expansion 2 Digital Inputs Expansion 2 Digital Outputs Reserved Reserved Reserved Reserved Reserved Reserved Reserved roANALOG_0 roANALOG_1 roANALOG_2 roANALOG_3 roANALOG_4 roANALOG_5 roANALOG_6 roANALOG_7 roINPUTS int 16 int 16 int 16 int 16 int 16 int 16 int 16 int 16 int 32 roOUTPUTS roMG_STATUS roBOOST roAUXENC_0_POS int 16 int 16 int 16 float roAUXENC_0_VEL float roAUXENC_1_POS roAUXENC_1_VEL roAUXENC_2_POS roAUXENC_2_VEL roEXP1_INPUTS roEXP1_OUTPUTS roEXP2_INPUTS roEXP2_OUTPUTS float float float float int 32 int 32 int 32 int 32 Not applicable to NextMove PCI MN1278 05.2001 61 Mint v4 PC Programming Guide The layout of the section is compatible to the current layout on NextMove PC. The locations used on NextMove PC for the upper 16 bits of data are unused. All data is written every 2ms. 6.6 Comms Array The Comms area simulates protected Comms communications on serial based controllers. The Comms array uses an area of DPR from address 0x1D6 to 0x29A. The data is accessed as: Address Comms Location 0x1D6 0x1D8 0x1DA ….. 0x298 0x29A location 1 location 2 location 3 location 98 location 99 Each location is a float value. The area is the same as NextMove PC at 99 locations. Comms is accessed using the COMMS keyword in MINT or the getComms()/setComms() functions. 6.7 Immediate Command Mode The ICM area is used for the transfer of Motion Generator commands The start of the ICM area is 0x130 and has the symbolic constant roFRONT_START. 62 MN1278 05.2001 Appendix 1: DPR Map 6.8 Pseudo Serial Interface The serial interface works by implementing a 64 word circular buffer within DPR. There is one such buffer for the receive buffer and one for the transmit buffer. Head and tail pointers are also located in DPR allowing both sides of DPR to check the status of the buffers. The serial interface occupies DPR locations 0x150 to 0x1D5 in the following configuration: 0x85 Txd Buffer Txd Reserved Txd Tail Txd Head 0x46 0x45 0x44 0x43 0x42 Rxd Buffer Rxd Reserved Rxd Tail Rxd Head 0x03 0x02 0x01 0x00 The buffer itself has two sets of symbolic constants, depending on which side, NextMove or host, that is using them. Offset 0x00 0x01 0x03 0x43 0x44 0x46 Symbolic Constant - Host Symbolic Constant - NextMove ofTXD_HEAD ofTXD_TAIL ofTXD_BUFFER ofRXD_HEAD ofRXD_TAIL ofRXD_BUFFER ofNM_RXD_HEAD ofNM_RXD_TAIL ofNM_RXD_BUFFER ofNM_TXD_HEAD ofNM_TXD_TAIL ofNM_TXD_BUFFER The offsets from the start of the serial interface are shown in hex. The start of the serial I/O buffer has a symbolic constant of ofSERIAL_IO_BASE. MN1278 05.2001 63 Mint v4 PC Programming Guide 6.9 Special Functions Registers Address 0x3F8 0x3F9 0x3FA 0x3FB 0x3FC 0x3FD Use Symbolic Constant ICM Handshaking Data associated with events Data associated with events Application Code Register Functionality Code Register Scratchpad Register roICM_HANDSHAKE roINTERRUPT_DATA_1 roINTERRUPT_DATA_2 roAPPLICATION_CODE roFUNCTION_CODE roSCRATCH_PAD The way in which dual port RAM is used may vary from application to application. All applications should use the registers detailed in this document in the same way. This will allow host resident code to determine whether it recognizes the application and the protocol used for communication. There is no hardware restriction upon those locations that may be read or written from either side. Both NextMove and the host have full read and write access to all locations. Application Code Register (3FB) This register identifies the software running on NextMove. The host may use this to determine how to communicate with the software or better interpret the bits within the Functionality Code Register. Each application program should have a unique identifier. Of the 65536 possible codes, the first half are reserved. Codes 32768 to 65535 may be used to identify user programs. Application programs should prime this register after all other initialization. It is recommended that the host does not write to this location. Code 0 1 2 3 4 5 6 7 8+ 64 Description Of Program Symbolic Constant Unidentified program or no program running. Loader running. Immediate Command Mode supported. NextMove test program running. Mint for NextMove suported. Mint for NextMove suported. Custom Version. Mint Motion Library. (Embedded) Reserved apNONE apLOADER apFRONT apNM_TEST apNM_MINT apFRONT_MINT apRPD_MINT apMML MN1278 05.2001 Appendix 1: DPR Map Functionality Code Register (3FC) This register describes the capabilities of the software running on NextMove. The register may be used by a host to determine how it should communicate with the software, what data is stored in dual port RAM, etc. The register contains a series of bits each of which indicate whether a specific feature is supported. The table below describes the current list of standard application capabilities. It is expected that this list will grow over time. Application programs should set the relevant bits in this register after all other initialization. It is recommended that the host does not write to this location. Bit 0 1 2 3 4 5 6 - 15 Description Of Feature Symbolic Constant Loader communication protocol. Motion Generator auto update of locations 0 to $12F. FRONT.OUT communication protocol. Pseudo Serial Port Buffer. Mint interpretation of serial buffer communications (Comms Protocol) Mint running Reserved fcLOADER_COMMS fcAUTO_UPDATE fcFRONT_COMMS fcSERIAL_PORT fcCOMMS_ON fcMINT_RUNNING Scratchpad Register (3FD) This register is a general purpose register used only by the host. It is only written to by the Loader immediately after reset when it is cleared to zero. It may be used by the host to determine that a NextMove may be installed on the bus. As NextMove will not write to this location the host can write codes and read them back in the knowledge that they should not have changed. After use by the PC host, the scratchpad should be returned to the value it originally contained. It is recommended that NextMove application programs do not write to this register. MN1278 05.2001 65 Mint v4 PC Programming Guide 6.10 Data Synchronization It may be desirable to prevent NextMove PC and PCI from updating the DPR update area for a period to allow a ‘snap-shot’ of DPR to be taken. The status and control registers provide a mechanism for this. It is supported by the function lockDPR. This function can be used to • request that DPR not be updated by Mint • inform Mint that it can now update MML. Note that locking DPR can take up to two milliseconds to complete. Note: lockDPR can also be used to speed up code running on NextMove, as NextMove will not have to update the MML area of DPR. 66 MN1278 05.2001 Appendix 2: Timings 7. Appendix 2: Timings These timings show the time taken to call Immediate Command Mode (ICM) functions from a host. The tests were performed on a 300 MHz Pentium II PC. On both MintDrive and NextMove PCI the timings were the same on Windows 95 and Windows NT. 7.1 Immediate Command Mode Functions Function NextMove PCI Mint NextMove PCI WinNT4 / Win95 MintDrive Mint MintDrive WinNT4 / Win95 getPos setJog setSpeed 0.140ms 0.133ms 0.138ms 0.254 ms 0.182 ms 0.184 ms 0.726ms 0.648ms 0.656ms 10.7 ms 10.5 ms 10.5 ms This is the speed for a function called from a C++ application with the Baldor Motion Toolkit C++ source code compiled into the project. Using the ActiveX interface adds approximately 1ms to each function call. This can be reduced by setting the ‘DCOM and Events Enabled’ property to false. This makes ActveX access times approximately equal to the C++ times but you cannot use events from NextMove PCI. MN1278 05.2001 67 Mint v4 PC Programming Guide 68 MN1278 05.2001 Appendix 3: Symbolic Constants 8. Appendix 3: Symbolic Constants The library functions can return error codes or can be passed parameters for which a number of symbolic constants have been defined in appropriate header files. These values are shown below. Error Codes: Value Symbolic Constant Meaning 0 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 erSUCCESS erINITIALISING erNOT_RUNNING erBAD_COMMAND erBAD_ADDRESS erBAD_ERASE erBAD_BURN erCANNOT_OPEN_FILE erINVALID_FORMAT erERROR_DOWNLOADING erTIMEOUT erDPRAM_LOCATION erNOT_ENOUGH_MEM erBAD_BOOT_DEVICE erCARD_NOT_FOUND erINVALID_VME_TYPE erINVALID_NEXTMOVE_TYPE erINVALID_STRING_FORMAT 1018 erNO_Mint_PROMPT 1019 erNO_WIN95_VME_SUPPORT 1020 1021 1022 erCOMMAND_ABORTED erFRONT_ACTIVE erCOMMAND_INTERRUPTED 1023 erRETURN_INVALID 1024 erFRONT_DISABLED No error Loader initialising Loader not runnning Unrecognised command code Invalid address received Flash erase failed Flash program failed File bad or does not exist File not proper COFF format COFF download failed Loader did not respond in time DPR location out of range Insufficient memory for program Bad boot source id Unable to locate NextMove Bad VME parameter. Bad NextMove parameter. Must use NULL terminated string for string parameters. Command prompt was not avaiable for up/download. Should use MintBreak to stop a running program. NextMove/VME not currently supported under Windows 95. User aborted front command Front resource already in use Command was not passed to MG: try again. Return code invalid. Call getSystemErr. Immediate Command Mode has been MN1278 05.2001 69 Mint v4 PC Programming Guide 70 Value Symbolic Constant Meaning 1025 erINVALID_HANDLE disabled The handle had not been correctly initialised. 1026 1027 Error 1026 Removed erPROTOCOL_ERROR 1028 erFILE_ERROR 1029 erINVALID_FILETYPE 1030 erNO_PROMPT 1031 erNO_NT_SUPPORT 1032 1033 erRESPONSE erTEMP_FILE_ERROR 1034 1035 erCODE_ERROR erIN_COMMS_ROUTINE 1036 erDOWNLOADING 1037 1038 erUPLOADING erIN_Mint328_ROUTINE 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 erPORT_NOT_OPEN erCORRUPTION erPORT_OUT_OF_RANGE erNOTIFY erCHECKSUM_ERROR erNAK_RECEIVED Error 1045 Removed erERROR_OPENING_PORT erINVALID_CARDNUMBER erINVALID_AXIS_PARAM erINVALID_CONTROLLER_TYPE erINVALID_COMMS_ADDRESS Error 1051 removed erPORT_UNAVAILABLE erUSER_ABORT Unknown protocol on upload/download The file could not be opened, or was corrupted. The filetype parameter passes to up/downloadFile was not correct. The function failed as Mint was not at the command line. Try MintBreak and then call the function again. This function cannot be used under Windows NT. NextMove did not respond. The function was unable to create a required temporary file. Check disk space. Bad coding: contact supplier ! Interface already in use by the comms protocol Interface already in use by a file download Interface already in use by a file upload Interface already in use a a Mint328 routine Serial port not opened Corruption occured Specified port not available Could not enable WM_NOTIFY The checksum failed The controller sent NAK Port could not be opened Card number out of range Axis out of range Invalid controller enumeration Comms address out of range Port already in use The user aborted the command MN1278 05.2001 Appendix 3: Symbolic Constants Value Symbolic Constant Meaning 1054 1055 erCONTROLLER_REPORTS_ERROR erUPDATING 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 erRECEIVE_BUFFER_EMPTY erTRANSMIT_BUFFER_FULL erINVALID_RETRIES erBAD_SQUASH_FILE erUNDEFINED_SERIAL_ERROR erPSERIAL_BUFFER_CORRUPTION erFUNCTION_NOT_SUPPORTED erCANNOT_OPEN_FILE erINVALID_FORMAT erDATA_TOO_LONG erINCORRECT_ARRAY_SIZE erUNKNOWN_ERROR_CODE erCONTROLLER_NOT_RUNNING erMML_VERSION_MISMATCH erNO_DEVICE_DRIVER_SUPPORT erBAD_COM_PORT_NUMBER erBAD_BAUD_RATE erIN_GETCHARTIMEOUT erIN_PUTCHARTIMEOUT erIN_GETSTRINGTIMEOUT erIN_PUTSTRINGTIMEOUT erCAPTURING erLINE_TOO_LONG erINVALID_PLATFORM erNO_INTERRUPT_REGISTERED 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 erINVALID_IRQ erBAD_INPUT_BUFFER erBAD_OUTPUT_BUFFER erBAD_DEVICE_DRIVER_CALL erSEMAPHORE_TIMEOUT erINVALID_EVENT erFUNCTION_NOT_AVAILABLE erBOOT_TEST_FAIL erBUFFER_TOO_SMALL erREQUIRES_DEV_DRIVER 1091 1092 erICM_TX_TIMEOUT erICM_RX_TIMEOUT The controller detected an error Interface already in use by a firmware update The receive buffer is empty The transmit buffer is full The retries parameter failed Bad squash file parameter The serial error is unknown The (pseudo-)serial buffers are corrupt Not supported on this platform File bad or doesn't exist file not proper COFF format Too much data in one chunk Array size or pointer incorrect The error code was not known The controller is not running mgBUILD incorrect Device driver not set up Serial port not supported Baud rate not supported Interface already in use Interface already in use Interface already in use Interface already in use Interface already in use Mint line too long Invalid firmware for the controller No interrupt registered for this controller Invalid Interrupt Input buffer wrong size Output buffer wrong size The device driver call failed A semaphore was not available Could not register the event Function not currently available Power-up self test failed Not enough memory to load prog Requires development build of device driver Timeout on ICM Timeout on ICM MN1278 05.2001 71 Mint v4 PC Programming Guide 72 Value Symbolic Constant Meaning 1093 1094 1095 1096 1097 erICM_RX_SIZE_ERROR erICM_PROCESS_TIMEOUT erDEV_DRV_UNKNOWN_IOCTL erBBP_ACK_TIMEOUT erBBP_POLL_TIMEOUT 1098 erBBP_POLL_NO_DATA 1099 erBBP_RX_TIMEOUT 1100 erBBP_UNSUPPORTED_TRANS 1101 1102 erBBP_INVALID_DATA_LENGTH erBBP_VALUE_OUT_OF_RANGE 1103 erBBP_VALUE_OUT_OF_BOUNDS 1104 erBBP_CONTROL_FAULT_COND 1105 erBBP_STATUS_MODE_REJECT 1106 1107 1108 erBBP_BLOCK_REJECTED erBBP_END_OF_BLOCK erIN_BBP_ROUTINE 1109 1110 1111 1112 erAUTOTUNE_FAILED erNO_CAPTURED_DATA erSQ_INVALID_OUTPUT_FILE erSQ_INVALID_INPUT_FILE 1113 erSQ_TOO_MANY_VARIABLES 1114 erSQ_BASIC_TABLE_NOT_FOUND 1115 erSQ_MOTION_TABLE_NOT_FOUND 1116 erSQ_CONSTANT_TABLE_NOT_FOUND 1117 erSQ_INPUT_FILE_READ_ERROR 1118 erSQ_OUTPUT_FILE_WRITE_ERROR Error in ICM protocol Timeout on ICM Device driver mismatch No response from controller BBP protocol error : No response to poll BBP protocol error : No data ready for polling BBP protocol error : Receive data timeout Invalid ( or unsupported ) transaction number Invalid data field length for transaction Data value out of range for transaction (rejected) Data value out of bound for transaction (modified by controller) Controller fault condition prevented execution Controller status/mode prevented execution Block transfer value not accepted End of block reached A BBP access is blocking use of the resource Autotune function failed No captured data is available to upload Squash : Could not create output file Squash : Could not open file to be squashed Squash : Too many variables in the program Squash : Could not find the file basic.XYZ Squash : Could not find the file motion.XYZ Squash : Could not find the file constant.XYZ Squash : Error reading from file to squash Squash : Error writing to squash output file MN1278 05.2001 Appendix 3: Symbolic Constants Value Symbolic Constant Meaning 1119 erSQ_INVALID_OUTPUT_FILE_STRING 1120 erSQ_INVALID_INPUT_FILE_STRING 1121 erSQ_INVALID_PATH_STRING 1122 erSQ_TOO_MANY_BASIC_KEYWORDS 1123 erSQ_TOO_MANY_MOTION_KEYWORDS 1124 erSQ_TOO_MANY_CONSTANTS 1125 erSQ_VARIABLES_NOT_INITIALISED 1126 1127 1128 erCANNOT_WRITE_TO_INTERRUPT erNO_LINK_TO_CONTROLLER erFIRST_ARRAY_ELEMENT_IS_SIZE 1129 1130 erPOS_ARRAY_REQUIRED erARRAY_SIZE_MISMATCH 1131 1132 1133 1134 1135 erPARAMETER_CANNOT_BE_NEGATIVE erCAN_INIT_FAILED erEEPROM_CRC_FAILED erINSUFFICENT_MEMORY erCANNOR_RUN_APP 1136 erEVENT_HANDLER_IN_USE Squash : Name of file to squash not NULL terminated Squash : Name of squash output file not NULL terminated Squash : Path to squash tables not NULL terminated Squash : Too many basic keywords, contact technical support Squash : Too many motion keywords, contact technical support Squash : Too many constants, contact technical support Squash : Internal error, contact technical support No write access to interrupts Must use a setXXXLink function The first element in the array must specify the number of elements ( not including itself ) The postition array is not optional One or more array(s) are the wrong size The parameter cannot be negative Initialisation of CAN failed EEPROM failed CRC check Insufficent memory to run application Cannot run application for unknown reason Event handler already installed MN1278 05.2001 73 Mint v4 PC Programming Guide updateFirmware Codes (nBootDevice Parameter): Value 0 1 Symbolic Constant Meaning tmFLASH tmRAM Load program to flash memory Load program to RAM updateFirmware Codes (nTarget Parameter): Value 0 1 2 3 4 Symbolic Constant Meaning bdEPROM bdFLASH bdSERIAL bdNV bdDPR Boot from EPROM Boot from flash memory Boot from serial port Boot from NVRAM Boot from Dual Port RAM File Upload/Download Codes (Use with uploadMintFile & downloadMintFile): Value 1 2 3 Symbolic Constant Meaning filePROGRAM fileCONFIG fileARRAY Program file Configuration file Array file getControllerType Codes: Value Symbolic Constant Meaning 0 2 3 9 10 conEUROSYSTEM conNEXTMOVE_BX conNEXTMOVE_PC conNEXTMOVE_PCI conMINTDRIVE EuroSystem family NextMove BX NextMove PC NextMove PCI MintDrive set/getHandshakeMode Codes Value 1 Symbolic Constant Meaning mdRTS_CTS RTS/CTS Handshaking updateFirmwareEx Update Callback Codes: 74 Value Symbolic Constant Meaning 1 updateWAITING_POWERUP 2 3 updateERASING_FLASH updateSCANNING_FILE Waiting for the user to power cycle the controller Controller is erasing flash Scanning the firmware file MN1278 05.2001 Appendix 3: Symbolic Constants Value Symbolic Constant 4 updateDOWNLOADING 5 6 updateRESETTING updateRUNNING MN1278 05.2001 Meaning Downloading the firmware: use the percentage parameter. Resetting the controller Running the application 75 Mint v4 PC Programming Guide 76 MN1278 05.2001 Bibliography 9. Bibliography 6 Bibliography [1] Mint v4 Programming Guide [MN1262] [2] Mint v4 Advanced Programming Guide [MN1270] [3] Mint v4 PC Programming Guide [MN1278] [4] Mint v4 CAN Programming Guide [MN1282] [5] Mint v4 Function Reference Guide [MN1280] All manuals can be found on the Baldor Motion Toolkit CD-ROM. MN1278 05.2001 77 Mint v4 PC Programming Guide 78 MN1278 05.2001
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.3 Linearized : Yes Create Date : 2001:06:19 13:38:02 Producer : Acrobat Distiller 4.0 for Windows Modify Date : 2001:06:19 13:55:00+01:00 Title : Mint v4 PC Programming Guide Author : Baldor UK Page Count : 88 Page Mode : UseOutlinesEXIF Metadata provided by EXIF.tools