📄 controlmotor.java
字号:
// 设置反方向软件限位 60
public void SetMDirSoftwareLimit(int axis, int LP_EP, int data) {
try {
FuncPtr SetMDSL = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_SetMDirSoftwareLimit");
SetMDSL.invoke_I(hDevice, axis, LP_EP, data,
ReturnFlags.CHECK_FALSE);
SetMDSL.close();
} catch (COMException e) {
}
}
//清除软件限位 61
public void ClearSoftwareLimit(int axis) {
try {
FuncPtr ClearSL = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_ClearSoftwareLimit");
// and then follows any [out] values
// int outVal = leis.readInt();
ClearSL.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
ClearSL.close();
} catch (COMException e) {
System.out.println("ClearSoftwareLimit false!");
}
}
// 减速停止函数 71
public void DecStop(int axis) {
try {
FuncPtr DecS = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_DecStop");
// and then follows any [out] values
// int outVal = leis.readInt();
DecS.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
DecS.close();
} catch (COMException e) {
System.out.println("DecStop false is in" + axis + "AXIS");
}
}
// 立即停止函数 72
public void InstStop(int axis) {
try {
FuncPtr InS = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_InstStop");
// and then follows any [out] values
// int outVal = leis.readInt();
InS.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
InS.close();
} catch (COMException e) {
System.out.println("InstStop false is in" + axis + "AXIS");
}
}
// 读当前速度 实际速度=读出速度值*倍率 78
public static int ReadCV(int axis) {
try {
FuncPtr ReadCV = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_ReadCV");
// and then follows any [out] values
// int outVal = leis.readInt();
int ResultCV = ReadCV.invoke_I(hDevice, axis,
ReturnFlags.CHECK_NONE);
ReadCV.close();
return ResultCV;
} catch (COMException e) {
System.out.println("Read CV false");
return 0;
}
}
// 读当前加速度 实际加速度=读出的加速度的值*125*倍率 79
public static int ReadCA(int axis) {
try {
FuncPtr ReadCA = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_ReadCV");
// and then follows any [out] values
// int outVal = leis.readInt();
int ResultCA = ReadCA.invoke_I(hDevice, axis,
ReturnFlags.CHECK_NONE);
ReadCA.close();
return ResultCA;
} catch (COMException e) {
System.out.println("Read CA false");
return 0;
}
}
//获得RR0的位状态 83
protected static void GetRR0Status(int[] pa_rr0) {
//int[] PA_RR0 = pa_rr0; // 15个成员
try {
FuncPtr Getrr0 = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_GetRR0Status");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeInt(hDevice);
for (int i = 0; i < pa_rr0.length; i++) {
leos.writeInt(pa_rr0[i]);
}
// for (int i1 = 0; i1 < lcdata.length; i1++) {
// leos.writeInt(lcdata[i1]);
// }
// leos1.wr(pci_papa_datalist);
// byte[]result=Getrr3.invoke_S(hDevice, 68,
// ReturnFlags.CHECK_NONE);
byte[] result = Getrr0.invoke("IP64:I:L4n64", 68, nbs, null,// 多接线实验
ReturnFlags.CHECK_FALSE);
// byte[] result = Getrr3.invoke("IP64:I:n64", 68, nbs, null,//多接线实验
// ReturnFlags.CHECK_NONE);
LittleEndianInputStream leis1 = new LittleEndianInputStream(
new ByteArrayInputStream(result));
// int rr = leis1.readInt();
leis1.readInt();
for (int i = 0; i < pa_rr0.length; i++)
pa_rr0[i] = leis1.readInt();
// int rr=0;
// rr++;
// 添加启动程序
// FuncPtr StartLvdv = new
// FuncPtr("C:\\windows\\system\\PCI1020.DLL",
// "PCI1020_StartLVDV");
// StartLvdv.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
// leis1.close();
leos.close();
nbs.close();
Getrr0.close();
// StartLvdv.close();
// return 1;
} catch (COMException e) {
System.out.println("FuncPtr is wrong!");
// return 0;
} catch (IOException e) {
System.out.println("NakedByteStream is wrong!");
// return 0;
}
}
//读RR1状态 外部限位驱动 84
protected static void GetRR1Status(int axis,int[] pa_rr1) {
//int[] PA_RR3 = pa_rr3; // 16个成员
try {
FuncPtr Getrr1 = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_GetRR1Status");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeInt(hDevice);
leos.writeInt(axis);
for (int i = 0; i < pa_rr1.length; i++) {
leos.writeInt(pa_rr1[i]);
}
// for (int i1 = 0; i1 < lcdata.length; i1++) {
// leos.writeInt(lcdata[i1]);
// }
// leos1.wr(pci_papa_datalist);
// byte[]result=Getrr3.invoke_S(hDevice, 68,
// ReturnFlags.CHECK_NONE);
byte[] result = Getrr1.invoke("IIP64:I:L8n64", 72, nbs, null,// 多接线实验
ReturnFlags.CHECK_FALSE);
// byte[] result = Getrr3.invoke("IP64:I:n64", 68, nbs, null,//多接线实验
// ReturnFlags.CHECK_NONE);
LittleEndianInputStream leis1 = new LittleEndianInputStream(
new ByteArrayInputStream(result));
// int rr = leis1.readInt();
leis1.readInt();
for (int i = 0; i < pa_rr1.length; i++)
pa_rr1[i] = leis1.readInt();
// int rr=0;
// rr++;
// 添加启动程序
// FuncPtr StartLvdv = new
// FuncPtr("C:\\windows\\system\\PCI1020.DLL",
// "PCI1020_StartLVDV");
// StartLvdv.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
// leis1.close();
leos.close();
nbs.close();
Getrr1.close();
// StartLvdv.close();
// return 1;
} catch (COMException e) {
System.out.println("FuncPtr is wrong!");
// return 0;
} catch (IOException e) {
System.out.println("NakedByteStream is wrong!");
// return 0;
}
}
// 读RR3的状态 绝对光码盘 86
protected static void GetRR3Status(int[] pa_rr3) {
// int[] PA_RR3 = pa_rr3; // 16个成员
try {
FuncPtr Getrr3 = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_GetRR3Status");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeInt(hDevice);
for (int i = 0; i < pa_rr3.length; i++) {
leos.writeInt(pa_rr3[i]);
}
// for (int i1 = 0; i1 < lcdata.length; i1++) {
// leos.writeInt(lcdata[i1]);
// }
// leos1.wr(pci_papa_datalist);
// byte[]result=Getrr3.invoke_S(hDevice, 68,
// ReturnFlags.CHECK_NONE);
byte[] result = Getrr3.invoke("IP64:I:L4n64", 68, nbs, null,// 多接线实验
ReturnFlags.CHECK_FALSE);
// byte[] result = Getrr3.invoke("IP64:I:n64", 68, nbs, null,//多接线实验
// ReturnFlags.CHECK_NONE);
LittleEndianInputStream leis1 = new LittleEndianInputStream(
new ByteArrayInputStream(result));
// int rr = leis1.readInt();
leis1.readInt();
for (int i = 0; i < pa_rr3.length; i++)
pa_rr3[i] = leis1.readInt();
// int rr=0;
// rr++;
// 添加启动程序
// FuncPtr StartLvdv = new
// FuncPtr("C:\\windows\\system\\PCI1020.DLL",
// "PCI1020_StartLVDV");
// StartLvdv.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
// leis1.close();
leos.close();
nbs.close();
Getrr3.close();
// StartLvdv.close();
// return 1;
} catch (COMException e) {
System.out.println("FuncPtr is wrong!");
// return 0;
} catch (IOException e) {
System.out.println("NakedByteStream is wrong!");
// return 0;
}
}
// 读RR4的状态 绝对光码盘 87
protected static void GetRR4Status(int[] pa_rr4) {
// int[] PA_RR4 = pa_rr4; // 16个成员
try {
FuncPtr Getrr4 = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_GetRR4Status");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeInt(hDevice);
for (int i = 0; i < pa_rr4.length; i++) {
leos.writeInt(pa_rr4[i]);
}
// for (int i1 = 0; i1 < lcdata.length; i1++) {
// leos.writeInt(lcdata[i1]);
// }
// leos1.wr(pci_papa_datalist);
// byte[]result=Getrr3.invoke_S(hDevice, 68,
// ReturnFlags.CHECK_NONE);
byte[] result = Getrr4.invoke("IP64:I:L4n64", 68, nbs, null,// 多接线实验
ReturnFlags.CHECK_FALSE);
// byte[] result = Getrr3.invoke("IP64:I:n64", 68, nbs, null,//多接线实验
// ReturnFlags.CHECK_NONE);
LittleEndianInputStream leis1 = new LittleEndianInputStream(
new ByteArrayInputStream(result));
// int rr = leis1.readInt();
leis1.readInt();
for (int i = 0; i < pa_rr4.length; i++)
pa_rr4[i] = leis1.readInt();
// int rr=0;
// rr++;
// 添加启动程序
// FuncPtr StartLvdv = new
// FuncPtr("C:\\windows\\system\\PCI1020.DLL",
// "PCI1020_StartLVDV");
// StartLvdv.invoke_I(hDevice, axis, ReturnFlags.CHECK_FALSE);
// leis1.close();
leos.close();
nbs.close();
Getrr4.close();
// StartLvdv.close();
// return 1;
} catch (COMException e) {
System.out.println("FuncPtr is wrong!");
// return 0;
} catch (IOException e) {
System.out.println("NakedByteStream is wrong!");
// return 0;
}
}
//设置指定轴加减速计数器偏移量 -32768~32767 18
public static void SetAccofst(int axis, int data) {
try {
FuncPtr SA = new FuncPtr("C:\\windows\\system\\PCI1020.DLL",
"PCI1020_SetAccofst");
// 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(data);
// call the generic invoke, with the NakedByteStream
// and parameters describing how to deserialize the
// NakedByteStream byte-array on the native side
SA.invoke("III:I:", 12, nbs, null, ReturnFlags.CHECK_FALSE);
// close object
leos.close();
nbs.close();
SA.close();
} catch (COMException e) {
} catch (IOException e) {
}
// slp.close();
}
//Delay(1)相当于1ms,延时函数,new080906
public static void Delay(int millisecond){
int count=millisecond*2;
try{
Thread.sleep(count);
}catch(InterruptedException ie){
}
}
// Delays(1)相当于1s,延时函数,new080906
public static void Delays(int second){
int count=second*2000;
try{
Thread.sleep(count);
}catch(InterruptedException ie){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -