⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlmotor.java

📁 采用PCI1020芯片控制三个电机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package cn.com.yuzhiqiang.pcimotor;

import org.jawin.COMException;
import org.jawin.FuncPtr;
import org.jawin.ReturnFlags;
import org.jawin.io.LittleEndianInputStream;
import org.jawin.io.LittleEndianOutputStream;
import org.jawin.io.NakedByteStream;


import java.io.*;

public class ControlMotor extends PciCreat {
//	设置指定轴逻辑计数器,范围 16
	public static void SetLP(int axis, int arg) {
		try {
			FuncPtr slp = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetLP");
			// create a NakedByteStream for the serialization of Java variables
			NakedByteStream nbs = new NakedByteStream();

			// wrap it in a LittleEndianOutputStream
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);

			// and then write the Java arguments
			leos.writeInt(hDevice);
			leos.writeInt(axis);
			leos.writeInt(arg);

			// call the generic invoke, with the NakedByteStream
			// and parameters describing how to deserialize the
			// NakedByteStream byte-array on the native side
			slp.invoke("III:I:", 12, nbs, null, ReturnFlags.CHECK_FALSE);
			// close object
			leos.close();
			nbs.close();
			slp.close();
		} catch (COMException e) {
		} catch (IOException e) {
		}
		// slp.close();
	}
//读逻辑计数器 75
	public static int ReadLP(int axis) {
		try {
			FuncPtr ReadLP = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_ReadLP");
			// and then follows any [out] values
			// int outVal = leis.readInt();

			int Result_readlp = ReadLP.invoke_I(hDevice, axis,
					ReturnFlags.CHECK_NONE);

			ReadLP.close();
			return Result_readlp;
		} catch (COMException e) {
			System.out.println("Read LP false");
			return 0;
		}

		// return Result_readlp;
	}
//设置指定轴实际计数器,范围 17
	public static void SetEP(int axis, int arg) {
		try {
			FuncPtr sep = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetEP");
			// create a NakedByteStream for the serialization of Java variables
			NakedByteStream nbs = new NakedByteStream();

			// wrap it in a LittleEndianOutputStream
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);

			// and then write the Java arguments
			leos.writeInt(hDevice);
			leos.writeInt(axis);
			leos.writeInt(arg);

			// call the generic invoke, with the NakedByteStream
			// and parameters describing how to deserialize the
			// NakedByteStream byte-array on the native side
			sep.invoke("III:I:", 12, nbs, null, ReturnFlags.CHECK_FALSE);
			// close object
			leos.close();
			nbs.close();
			sep.close();
		} catch (COMException e) {
		} catch (IOException e) {
		}
	}
//读实际位置计数器 76
	public static int ReadEP(int axis) {
		try {
			FuncPtr ReadEP = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_ReadEP");
			// and then follows any [out] values
			// int outVal = leis.readInt();

			int Result_readep = ReadEP.invoke_I(hDevice, axis,
					ReturnFlags.CHECK_NONE);

			ReadEP.close();
			return Result_readep;
		} catch (COMException e) {
			System.out.println("Read EP false");
			return 0;
		}
	}

// 选择逻辑计数器或实位计数器 并设置COMP+范围-2147483648-+2147483647 20
	public static void SetCOMPP(int axis, int LP_EP, int data) {
		try {
			FuncPtr SetCOMPP = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetCOMPP");
			SetCOMPP.invoke_I(hDevice, axis, LP_EP, data,
					ReturnFlags.CHECK_FALSE);
			SetCOMPP.close();
		} catch (COMException e) {

		}
	}

// 选择逻辑计数器或实位计数器 并设置COMP-范围-2147483648-+2147483647 21
	public static void SetCOMPM(int axis, int LP_EP, int data) {
		try {
			FuncPtr SetCOMPM = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetCOMPM");
			SetCOMPM.invoke_I(hDevice, axis, LP_EP, data,
					ReturnFlags.CHECK_FALSE);
			SetCOMPM.close();
		} catch (COMException e) {

		}
	}
//设置外部越限信号有效及停止方式 62	
	public static void SetLMTEnable(int axis, int stopmode) {
		try {
			FuncPtr SLE = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetLMTEnable");
			// create a NakedByteStream for the serialization of Java variables
			NakedByteStream nbs = new NakedByteStream();

			// wrap it in a LittleEndianOutputStream
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);

			// and then write the Java arguments
			leos.writeInt(hDevice);
			leos.writeInt(axis);
			leos.writeInt(stopmode);

			// call the generic invoke, with the NakedByteStream
			// and parameters describing how to deserialize the
			// NakedByteStream byte-array on the native side
			SLE.invoke("III:I:", 12, nbs, null, ReturnFlags.CHECK_FALSE);
			// close object
			leos.close();
			nbs.close();
			SLE.close();
		} catch (COMException e) {
			System.out.println("SetLMTEnable FuncPtr is wrong!"+axis);
		} catch (IOException e) {
			System.out.println("SetLMTEnable NakedByteStream is wrong!"+axis);
		}
	}
//PCI1020_InitLVDV 初始化指定轴定长或连续驱动 23
//PCI1020_StartLVDV 启动单轴直线S曲线驱动 24
	public static void RunLVDV(int axis, int[] papa_DL, int[] papa_LC) {
		int[] datalist = papa_DL; // {1,1,300,125,125,1000,1000};
		int[] lcdata = papa_LC; // {0,0,0,0,1,0,60000};
		try {
			FuncPtr InitLvdv = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_InitLVDV");
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(hDevice);
			for (int i = 0; i < datalist.length; i++) {
				leos.writeInt(datalist[i]);
			}
			for (int i1 = 0; i1 < lcdata.length; i1++) {
				leos.writeInt(lcdata[i1]);
			}
			// leos1.wr(pci_papa_datalist);

			InitLvdv.invoke("IP28P28:I:", 60, nbs, null,
					ReturnFlags.CHECK_FALSE);
			// LittleEndianInputStream leis1 = new LittleEndianInputStream(new
			// ByteArrayInputStream(result1));
			// int rr=leis1.readInt();
			// rr++;
			// 添加启动程序
			FuncPtr StartLvdv = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_StartLVDV");
			StartLvdv.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
			leos.close();
			nbs.close();
			InitLvdv.close();
			StartLvdv.close();
		} catch (COMException e) {
			System.out.println("FuncPtr is wrong!");
		} catch (IOException e) {
			System.out.println("NakedByteStream is wrong!");
		}
	}
	
//	PCI1020_InitLVDV 初始化指定轴定长或连续驱动 23 new080903
	public static void InitLVDV(int[] papa_DL, int[] papa_LC) {
		int[] datalist = papa_DL; // {1,1,300,125,125,1000,1000};
		int[] lcdata = papa_LC; // {0,0,0,0,1,0,60000};
		try {
			FuncPtr InitLvdv = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_InitLVDV");
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(hDevice);
			for (int i = 0; i < datalist.length; i++) {
				leos.writeInt(datalist[i]);
			}
			for (int i1 = 0; i1 < lcdata.length; i1++) {
				leos.writeInt(lcdata[i1]);
			}
			// leos1.wr(pci_papa_datalist);

			InitLvdv.invoke("IP28P28:I:", 60, nbs, null,
					ReturnFlags.CHECK_FALSE);
			
			leos.close();
			nbs.close();
			InitLvdv.close();
		} catch (COMException e) {
			System.out.println("FuncPtr is wrong!");
		} catch (IOException e) {
			System.out.println("NakedByteStream is wrong!");
		}
	}
	
//	PCI1020_StartLVDV 启动单轴直线S曲线驱动 24	new080903
	public static void StartLVDV(int axis) {		
		try {	
			FuncPtr StartLvdv = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
			"PCI1020_StartLVDV");
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(hDevice);			
			
			StartLvdv.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
			leos.close();
			nbs.close();			
			StartLvdv.close();
		} catch (COMException e) {
			System.out.println("FuncPtr is wrong!");
		} catch (IOException e) {
			System.out.println("NakedByteStream is wrong!");
		}
	}	

//	PCI1020_SetInteruptBit 设置中断位 55 new080903
	public static void SetInteruptBit(int axis,int[] para_Int){
		int[] bitint= para_Int;//RR5,16位
		try {
			FuncPtr SetInteruptBit = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetInteruptBit");
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(hDevice);
			leos.writeInt(axis);
			for (int i = 0; i < bitint.length; i++) {
				leos.writeInt(bitint[i]);
			}
			SetInteruptBit.invoke("IP64:I:L4n64", 68, nbs, null, ReturnFlags.CHECK_FALSE);//?????
//			byte[] result = Getrr0.invoke("IP64:I:L4n64", 68, nbs, null,// 多接线实验
//			ReturnFlags.CHECK_FALSE);
			leos.close();
			nbs.close();
			SetInteruptBit.close();
		} catch (COMException e) {
			System.out.println("FuncPtr is wrong!");
		} catch (IOException e) {
			System.out.println("NakedByteStream is wrong!");
		}
	}
	
//PCI1020_InitDeviceInt 初始化中断
	public static void InitDeviceInt(){		
		try {
			FuncPtr InitDeviceInt = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_InitDeviceInt");
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(hDevice);
			leos.writeInt(hEvent);				
//			InitDeviceInt.invoke(0, nbs, null, ReturnFlags.CHECK_FALSE);//?????
			leos.close();
			nbs.close();
			InitDeviceInt.close();
		} catch (COMException e) {
			System.out.println("FuncPtr is wrong!");
		} catch (IOException e) {
			System.out.println("NakedByteStream is wrong!");
		}
	}
	
//PCI1020_ReleaseDeviceInt 释放设备中的中断资源
	public static void ReleaseDeviceInt(){		
		try {
			FuncPtr ReleaseDeviceInt = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_ReleaseDeviceInt");
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(hDevice);						
//			InitDeviceInt.invoke(0, nbs, null, ReturnFlags.CHECK_FALSE);//?????
			leos.close();
			nbs.close();
			ReleaseDeviceInt.close();
		} catch (COMException e) {
			System.out.println("FuncPtr is wrong!");
		} catch (IOException e) {
			System.out.println("NakedByteStream is wrong!");
		}
	}
	
	
//设置编码器输入信号类型 22
	public static void SetEncoderSignalType(int axis, int type) {
		try {
			FuncPtr sest = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetEncoderSignalType");
			// create a NakedByteStream for the serialization of Java variables
			NakedByteStream nbs = new NakedByteStream();

			// wrap it in a LittleEndianOutputStream
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);

			// and then write the Java arguments
			leos.writeInt(hDevice);
			leos.writeInt(axis);
			leos.writeInt(type);

			// call the generic invoke, with the NakedByteStream
			// and parameters describing how to deserialize the
			// NakedByteStream byte-array on the native side
			sest.invoke("III:I:", 12, nbs, null, ReturnFlags.CHECK_FALSE);
			// close object
			leos.close();
			nbs.close();
			sest.close();
		} catch (COMException e) {
		} catch (IOException e) {
		}
	}
//设置正方向软件限位 59
	public void SetPDirSoftwareLimit(int axis, int LP_EP, int data) {
		try {
			FuncPtr SetPDSL = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
					"PCI1020_SetPDirSoftwareLimit");
			SetPDSL.invoke_I(hDevice, axis, LP_EP, data,
					ReturnFlags.CHECK_FALSE);
			SetPDSL.close();
		} catch (COMException e) {
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -