Bring Values and Sucesses To Our Customers

Home / Support and services / Technical Support

Technical support

Technical Support

Zmotion EtherCAT PCIE Card XPCIE1032H for You (11) | C# XML Configurations

XPCIE1032H is one  EtherCAT PCI Express motion control card developed by Zmotion Technology.

*XPCIE1032H Introduction Video*: https://youtu.be/B1ktSxIRa44

*XPCIIE1032H Lesson 1- Lesson 10*: https://youtu.be/0C96S5_hVf0 

*XPCIE1032H Lesson 11 Video:  https://youtu.be/ln0yPxrbaH4 

1.jpg

And one  software kernel is built.

--XPCIE1032H Card & MotionRT7 Soft Kernel--

P 1D/2D/3D PSO (high-speed hardware position comparison output): suit to vision fly-shooting, precise dispensing, laser energy control, etc.

P in PC Windows development, it can achieve real-time, and  the instruction interaction speed is faster 10 times than traditional PCI / PCIe.

Average Value

C++ LOCAL

C# LOCAL

Traditional PCI / PCIe

PLC EtherNET

Period of one command reading with 1W times

4.70us

5.3us

64us

500us-10ms

Period of one command reading with 10W times

3.90us

5.7us

65us

500us-10ms

Period of multi-command reading with 1W times

6.20us

8.85us

472us

500us-10ms

Period of multi-command reading with 10W times

5.50us

8.37us

471us

500us-10ms

The theme of this lesson is “ZPJ File & XML File Configuration and Downloading”.

[How to Transform XML File to ZML File]

[How to Download ZPJ (ZML & Basic Init) into XPCIE1032H]

[C# Routine Introduction & Codes]


Zmotion EtherCAT motion controller as the master station, it needs to configure the EtherCAT slave station for successful data interaction.

Now, Zmotion has already configured some XML files into controller firmware. You only need to download the ZPJ project [1] that includes EtherCAT initialization file [2], then they can be communicated.

[1]: ZPJ file is Zmotion RTSys created project file, it can include Basic program, and other EtherCAT configuration files. Generally after it is edited, download it into controller for operation. For RTSys debug details, please refer to lesson 6.

[2] : EtherCAT initialization content has already talked in lesson 2.

However, it is only valid for some mainstream EtherCAT drives. You can check it in advance in RTSys, see whether there is corresponding ZML file. After configured, XML file will be transformed as ZML file.

If your EtherCAT slave station is not in initialization file , it will appear below information:

2.png

According to this situation, please add it manually.

Therefore, today Zmotion will tell you how to configure XML file and download it into ZPJ project with one C# routine.

Step 1: transform XML file into ZML file

Step 2: add the ZML file into ZPJ project file.

Step 3: download the ZPJ file into XPCIE1032H.



( ZMOTION )
How to Transform  XML File to  ZML File

Zmotion has one small tool “ XML ParsingTools”, which can directly generate needed ZML file from XML file.

Step 1:  download and open the tool.

*XML ParsingTools Download Add.: https://www.zmotionglobal.com/download_list_14.html

Step 2:  select corresponding slave models and types .

3.png

Step 3: click left upper folder icon, then select “ Export ZML ”.

4.png

Step 5: save ZML file.



( ZMOTION )
How to Download ZPJ (ZML & Basic Init) into XPCIE1032H

After getting ZML file, you need to add it into  ZPJ project. Otherwise, it is invalid.

ZPJ project is the EtherCAT file actually, because the first step of card is to initialize EtherCAT.

Step 1: copy ZML file into EtherCAT initialization ZPJ project.

5.png

Step 2: open ZPJ in RTSys, right-click ProjectView, then click “ add to project ”.

6.png

Step 3:  connect to card by LOCAL.

7.png

Step 4:  download ZPJ to XPCIE1032H card ROM

8.png

For C#, same configuration and downloading principles.

In a word, put EtherCAT initialization file and exported ZML file into ZPJ project, then do connection, and download into XPCIE1032H card.

Below C# routine will show details.




( ZMOTION )
C# Routine Introduction &  Codes

A.       C# Routine UI

9.png


B.       C# Command

Except connection command ZAux_FastOpen that has been mentioned in above articles, the important related C# instruction is  ZAuz_ZpjDown.

ZAux_ZpjDown (handle, ZpjName, ZarName, pPass, uid, run_mode)

Generate ZAR file from ZPJ project, then download to run.

handle

Connection handle

ZpjName

ZPJ project path + file name

ZarName

The storage path of generated Zar file

pPass

Software password, bind with APP_PASS, when there is no password, pPass=NULL

uid

Bound controller unique ID, 0: no controller bound

run_mode

Download into ROM / RAM, 0 = ROM, 1 = RAM

For details, please refer to Zmotion PC Programming Manual.

Download Add.:   https://www.zmotionglobal.com/download_list_17.html

Contact Us: https://www.zmotionglobal.com/contactus.html

Including the C# library file. How to call the PC library file, please review lesson 2.


C.       C# Program Introduction & Codes

Step 1: click “connect” button to connect XPCIE1032H card to MotionRT7 software kernel.

//connect to controller
private void Btn_cn_Click(object sender, EventArgs e)
{
    int ret;
    //connect to controller
    //ret= zmcaux.ZAux_FastOpen(5,textBox1.Text,100,out g_handle);
    ret = zmcaux.ZAux_OpenEth("127.0.0.1", out g_handle);
    if (g_handle != (IntPtr)0)
    {
        MessageBox.Show("RT7 Link Succeeded!", "Note");
        timer1.Enabled = true;
    }
    else
    {
        MessageBox.Show("RT7 Link Failed!"+"Error Code"+ ret);
    }
}


Step 2: create new ZPJ project file.

//new create one ZPJ file
private void NewZpjFile_Click(object sender, EventArgs e)    
{
    try
    {
        //create "save file dialog box"  
        SaveFileDialog saveFile = new SaveFileDialog();  //
        saveFile.Filter = "ZMC Project Files(*.zpj)|*.zpj";
        saveFile.OverwritePrompt = true;  //whether to cover current file
        //if set it as true, system default content will be used
        saveFile.RestoreDirectory = true;  //restore content
        //if "save file diaglo box" succeeded, then: 
        if (saveFile.ShowDialog() == DialogResult.OK)
        {
            FileStream fs1 =new FileStream(saveFile.FileName, FileMode.Create, FileAccess.ReadWrite);  
 
            fs1.Close();
            //ZPJ file name
            m_ZpjFileName = saveFile.FileName;
            //ZPJ file path
            m_ZpjFilePath = System.IO.Path.GetDirectoryName(m_ZpjFileName); //path
            System.IO.File.Create(m_ZpjFileName).Close();
            Thread.Sleep(100);
            if (!System.IO.File.Exists(m_ZpjFileName))
            {
                MessageBox.Show("File Not Exist");
            }
            Czpj();
        }
        else
        {
            return;
        }
                           
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


Step 3: add Bas file into ZPJ project.

//add bas file
private void AddBas_Click(object sender, EventArgs e)
{
     if (!m_ZpjOPenFlag) 
    {
 
        MessageBox.Show("Please Create / Open ZPJ!");
        return;
    }
     //create / open the file dialog box
    OpenFileDialog ofd2 = new OpenFileDialog();
    ofd2.Filter = "ZMC Basic Files (*.bas)|*.bas";
    ofd2.RestoreDirectory = true;
    //if file selection succeeded, then: 
    if (ofd2.ShowDialog() == DialogResult.OK)
    {
        string fullname = ofd2.FileName;
 
        m_ZpjFilePath = System.IO.Path.GetDirectoryName(fullname); //path
 
        m_SubFileName = System.IO.Path.GetFileName(fullname);  //name
 
        m_ZpjFile_Info[num].pFileName = m_SubFileName;
        m_ZpjFile_Info[num].nAutoTask = -1;
        m_ZpjFile_Info[num].nFileType= 1;    //.bas file type is 1
 
        num++;
        SaveZpj();
        ShowFileList();
    }
}
//save ZPJ file
public void SaveZpj()
{
    //open ini file of ZPJ project
    string IniFileName = m_ZpjFilePath + "\\" + m_ZpjFileName;
    var MyIni = new IniFile(IniFileName);
 
    string LpAppname, Lpkeynum, Lpdata;
    LpAppname = "Controller";
    Lpkeynum = "TypeName ";
    String iFileName = "";
    MyIni.Write("Files", num.ToString(), LpAppname);
 
    //write FileList
    LpAppname = "FileList";
 
    //Traversal ZPJ files
    int i =0;
    for (i = 0; i < num; i++)
    {
        if (m_ZpjFile_Info[i].pFileName == "")
        {
            Lpdata = "Empty File!" + m_ZpjFile_Info[i].nAutoTask.ToString();
        }
        //sub-filename (with path)
        iFileName = m_ZpjFilePath + "\\" + m_ZpjFile_Info[i].pFileName;
        if (!System.IO.File.Exists(iFileName))
        {
            Lpdata = "File Not Exist!" + m_ZpjFile_Info[i].pFileName;
            MessageBox.Show(Lpdata);
        }
        //update sub-file ID
        Lpkeynum = "File" + (i + 1);
        Lpdata = m_ZpjFile_Info[i].pFileName;
        MyIni.Write(Lpkeynum, Lpdata, LpAppname);
        //update sub-file type
        Lpkeynum = "FileType" + (i + 1);
        Lpdata = m_ZpjFile_Info[i].nFileType.ToString();
        MyIni.Write(Lpkeynum, Lpdata, LpAppname);
        //update sub-file auto run No.
        Lpkeynum = "AutoRun" + (i + 1);
        Lpdata = m_ZpjFile_Info[i].nAutoTask.ToString();
        MyIni.Write(Lpkeynum, Lpdata, LpAppname);            
     
    }
    //delete extra keys
    Lpkeynum = "File" + (num+1);
    MyIni.DeleteKey(Lpkeynum, LpAppname);
    Lpkeynum = "FileType" + (num + 1);
    MyIni.DeleteKey(Lpkeynum, LpAppname);
    Lpkeynum = "AutoRun" + (num + 1);
MyIni.DeleteKey(Lpkeynum, LpAppname);
 
    //write OpenList
    LpAppname = "OpenList";  
    m_ZpjOPenFlag = true;
}


Step 4: add ZML file into ZPJ project

//add zml file
private void AddZml_Click(object sender, EventArgs e)
{
    if (!m_ZpjOPenFlag)
    {
        MessageBox.Show("Please Create / Open ZPJ!");
        return;
    }
    OpenFileDialog ofd2 = new OpenFileDialog();
    ofd2.Filter = "ZMC ZML Files (*.zml)|*.zml";
    ofd2.RestoreDirectory = true;
    if (ofd2.ShowDialog() == DialogResult.OK)
    {
        string fullname = ofd2.FileName;
        m_ZpjFilePath = System.IO.Path.GetDirectoryName(fullname); //path
        m_SubFileName = System.IO.Path.GetFileName(fullname);  //name
        m_ZpjFile_Info[num].pFileName = m_SubFileName;
        m_ZpjFile_Info[num].nAutoTask = -1;
        m_ZpjFile_Info[num].nFileType = 19;
        num++;
        SaveZpj();
        ShowFileList();
    }
}


Step 5: download ZPJ project into card ROM for storage when power-off

//download into rom
private void button9_Click(object sender, EventArgs e)
{
    if (!m_ZpjOPenFlag)
    {
        MessageBox.Show("Please Create / Open ZPJ!");
        return;
    }
    if (g_handle != (IntPtr)0)
    {
        ShowFileListSave();
        SaveZpj();
        String ZpjFileName = m_ZpjFilePath + "\\" + m_ZpjFileName;
        String m_ZarFileName = m_ZpjFilePath + "\\" + "ZmcZpj.Zar";
        //MessageBox.Show(ZpjFileName);
        //MessageBox.Show(m_ZarFileName);
        int iret = zmcaux.ZAux_ZpjDown(g_handle, ZpjFileName, m_ZarFileName, null, 0, 1);
        if (iret != 0)
        {
            MessageBox.Show("Error Code" + iret);
        }
    }
    else
    {
        MessageBox.Show("Controller Unconnected");
    }
}


Step 6: in RTSys, check the effect.

10.png

Copyright © 2013-2024 Shenzhen Zmotion Technology Co.,Ltd Design by Zmotion    粤ICP备13037187号 Motion Controller-Motion Control Card

Contact Us-Youtube