using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.IO; using TML; using TMLLibDefs; /*================================================================================= Steps to build an application with TML_lib library: Step1 Start EasySetUp and select the template suited for your application: Technosoft product -> motor technology -> feedback. type The examples included in the TML_lib package are designed for IBL2403-CAN controlling brushless motor with incremental encoder Step2 Motor and feedback setup Set the motor and feedback parameters. Use the tests from the Motor Setup dialogue to validate the correct operation of the motor and feedback Step3 Drive setup 3.a Set the control mode: position, speed or torque 3.b Tune and test the controllers associated to the selected control structure 3.c Set the Axis ID of the drive, The Axis ID value set in the Drive Setup dialogue must be used in the application to identify the drive. The address of the host, Host ID, is: - identical with the one of the drive connected to the host in the case of RS232 communication - unique when the drives and the host communicate using RS485 or CAN protocols The examples included in the TML_lib package use Axis ID = 1 and Host ID = 1. 3.d Setup the protections 3.e Select the starting mode, if available Step4: Download the setup data in the non volatile memory of the drive Step5: Reset the drive to activate the setup data Step6: Generate the setup information for TML_lib library (*.t.zip file) =================================================================================*/ namespace Ex01StartUp { class Ex01_MainFile { static int Main(string[] args) { Int32 idxSetup = -1; ushort sAxiOn_flag = 0; StringBuilder err = new StringBuilder(512); Int32 buffer_size = 512; /* Step7 Open the comunication channel: COM1, RS232, 1, 115200 */ //BAUD = 9600 , 19200,57600,115200 if (TMLLib.TS_OpenChannel(Defs.CHANNEL_NAME, Defs.CHANNEL_TYPE, Defs.HOST_ID, Defs.BAUDRATE) < 0) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(" Communication error! " + err); return Defs.FALSE; } /* Step8 Load the *.t.zip with setup data generated with EasySetUp*/ idxSetup = TMLLib.TS_LoadSetup(Defs.SETUP_FILE_01); if (idxSetup < 0) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(err); return Defs.FALSE; } /* Step9 Setup the axis based on the setup data previously loaded. From this point all commands sent to Axis_ID_01 will be validated through the SETUP_FILE_01*/ if (!TMLLib.TS_SetupAxis(Defs.AXIS_ID_01, idxSetup)) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(err); return Defs.FALSE; } /* Step10 Select the destination axis of the TML commands*/ if (!TMLLib.TS_SelectAxis(Defs.AXIS_ID_01)) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(err); return Defs.FALSE; } /* Step11 Check the drive setup table and execute the initialization of the drive (ENDINIT)*/ if (!TMLLib.TS_DriveInitialisation()) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(err); return Defs.FALSE; } /* Step12 Enable the power stage of the drive (AXISON) */ if (!TMLLib.TS_Power(TMLLib.POWER_ON)) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(err); return Defs.FALSE; } /* Wait for power stage to be enabled*/ while (sAxiOn_flag == 0) { /* Check the status of the power stage*/ if (!TMLLib.TS_ReadStatus(TMLLib.REG_SRL, out sAxiOn_flag)) { TMLLib.TS_Basic_GetLastErrorText(err, buffer_size); Console.WriteLine(err); return Defs.FALSE; } sAxiOn_flag = (ushort)((sAxiOn_flag & 1 << 15) != 0 ? 1 : 0); } /*The drive is ready to execute any motion commands*/ Console.WriteLine(" Drive/motor initialization ended.\n\n Press any key to end the example.\n\n"); Console.ReadKey(true); /* Step13 Add the motion commands required by your application*/ /* Disable the power stage of the drive (AXISOFF)*/ TMLLib.TS_Power(TMLLib.POWER_OFF); /* Step14 Close the communication channel*/ TMLLib.TS_CloseChannel(-1); return 0; } } } ------------------------------------------------------------------------------------------------ Description of TML_lib.Dll [DllImport("TML_lib.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] public static extern Int32 TS_OpenChannel(String pszDevName, Byte btType, Byte nHostID, UInt32 baudrate); /******************************************************************************************* Function: Open a communication channel. Input arguments: pszDevName: Number of the serial channel to be open (for serial ports: "COM1", "COM2", ...; for CAN devices: "1", "2", ..) btType: channel type (CHANNEL_*) with an optional protocol (PROTOCOL_*, default is PROTOCOL_TMLCAN) nHostID: Is the address of your PC computer. A value between 1 and 255 For RS232: axis ID of the drive connected to the PC serial port (usually 255) For RS485 or CAN devices: must be an unused axis ID! It is the address of your PC computer on the RS485 network. For XPORT: "IP:port" BaudRate: Baud rate serial ports: 9600, 19200, 38400, 56000 or 115200 CAN devices: 125000, 250000, 500000, 1000000 Output arguments: return: channel's file descriptor or -1 if error *******************************************************************************************/
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)