|
目前最火的是什么?
是AI , AI离不开运动控制, 工业4.0也离不开.
之前也有一直使用这个卡, 不过一直没有进行二次封装,一直都是直接调用dll里面的函数, 最近项目中可能会多次用到这个卡,所以花了几天时间稍微封装了下, 封装的原则是以后还可以兼容其他卡类,只需要判断卡类型即可.
今天测试发现这个dll可以内嵌到exe里面, 牛了.
写的过程中学习到不少东西 (代码智能提示的写法,dll中指针的使用啊啥的),希望这个代码能帮到希望和硬件对接的人.
- import win.ui;
- /*DSG{{*/
- mainForm = win.form(text="DMC2410Test";right=791;bottom=363;border="dialog frame")
- mainForm.add(
- NEL={cls="plus";left=133;top=171;right=162;bottom=198;forecolor=8421376;z=11};
- ORG={cls="plus";left=90;top=171;right=119;bottom=198;forecolor=8421376;z=10};
- PEL={cls="plus";left=48;top=171;right=77;bottom=198;forecolor=8421376;z=9};
- axis={cls="combobox";left=49;top=42;right=145;bottom=68;edge=1;items={"0";"1";"2";"3"};mode="dropdown";z=2};
- button={cls="button";text="Go_ON";left=450;top=104;right=567;bottom=130;z=14};
- cieclespeed={cls="edit";text="5";left=450;top=314;right=544;bottom=340;edge=1;z=31};
- circleGo={cls="button";text="circle_Go";left=667;top=268;right=784;bottom=322;z=18};
- circledir={cls="combobox";left=450;top=252;right=546;bottom=278;edge=1;items={"0";"1"};mode="dropdown";z=29};
- circlejuedui={cls="radiobutton";text="juedui";left=561;top=274;right=655;bottom=296;group=1;z=33};
- circlexiangdui={cls="radiobutton";text="xiangdui";left=561;top=300;right=655;bottom=322;checked=1;z=34};
- dir={cls="combobox";left=186;top=40;right=282;bottom=66;edge=1;items={"0";"1"};mode="dropdown";z=3};
- juedui={cls="radiobutton";text="juedui";left=48;top=103;right=142;bottom=125;group=1;z=15};
- juli={cls="edit";text="5";left=318;top=106;right=421;bottom=132;edge=1;z=12};
- lineON={cls="button";text="Line_ON";left=450;top=40;right=567;bottom=66;z=7};
- mainAxis={cls="combobox";left=49;top=252;right=145;bottom=278;edge=1;items={"0";"1";"2";"3"};mode="dropdown";z=19};
- maincenter={cls="edit";text="1";left=186;top=252;right=289;bottom=278;edge=1;z=23};
- maintarget={cls="edit";text="5";left=318;top=252;right=421;bottom=278;edge=1;z=25};
- nowpos={cls="edit";text="5";left=186;top=171;right=289;bottom=197;disabled=1;edge=1;readonly=1;z=17};
- secondAxis={cls="combobox";left=49;top=314;right=145;bottom=340;edge=1;items={"0";"1";"2";"3"};mode="dropdown";z=21};
- secondcenter={cls="edit";text="1";left=186;top=314;right=289;bottom=340;edge=1;z=24};
- secondtarget={cls="edit";text="5";left=318;top=314;right=421;bottom=340;edge=1;z=26};
- setPos={cls="edit";text="5";left=318;top=171;right=421;bottom=197;edge=1;z=37};
- setpos={cls="button";text="SetPos";left=450;top=171;right=567;bottom=197;z=39};
- speed={cls="edit";text="5";left=318;top=42;right=421;bottom=68;edge=1;z=1};
- static={cls="static";text="juli";left=318;top=80;right=412;bottom=103;transparent=1;z=13};
- static11={cls="static";text="speed";left=450;top=293;right=544;bottom=316;transparent=1;z=32};
- static12={cls="static";text="Limit";left=46;top=143;right=92;bottom=166;transparent=1;z=35};
- static13={cls="static";text="current pos:";left=186;top=152;right=262;bottom=171;transparent=1;z=36};
- static14={cls="static";text="set position";left=318;top=150;right=394;bottom=173;transparent=1;z=38};
- static2={cls="static";text="axis";left=49;top=14;right=143;bottom=37;transparent=1;z=4};
- static3={cls="static";text="dir";left=187;top=14;right=281;bottom=37;transparent=1;z=5};
- static4={cls="static";text="speed";left=319;top=14;right=413;bottom=37;transparent=1;z=6};
- static5={cls="static";text="mainAxis";left=49;top=229;right=143;bottom=252;transparent=1;z=20};
- static6={cls="static";text="secondAxis";left=49;top=292;right=143;bottom=315;transparent=1;z=22};
- static7={cls="static";text="center";left=186;top=229;right=280;bottom=252;transparent=1;z=27};
- static8={cls="static";text="target";left=318;top=230;right=412;bottom=253;transparent=1;z=28};
- static9={cls="static";text="dir";left=450;top=230;right=544;bottom=253;transparent=1;z=30};
- stop={cls="button";text="stop";left=667;top=40;right=784;bottom=125;z=8};
- xiangdui={cls="radiobutton";text="xiangdui";left=147;top=103;right=241;bottom=125;checked=1;z=16}
- )
- /*}}*/
- import UserDmc;
- var cardNum = UserDmc.init();
- if(cardNum>0){
- UserDmc.setPulseMode(2/* 轴0 */,2/* 轴1 */,2/* 轴2 */,2/* 轴3 */);
- UserDmc.setEL(2/* 轴0 */,2/* 轴1 */,2/* 轴2 */,2/* 轴3 */);
- UserDmc.setAxisUp(0/* 轴号 */,0.72/* 步距角 */,1/* 螺距(mm) */,20/* 细分 */);
- UserDmc.setAxisUp(1/* 轴号 */,0.72/* 步距角 */,1/* 螺距(mm) */,20/* 细分 */);
- UserDmc.setAxisUp(2/* 轴号 */,0.72/* 步距角 */,1/* 螺距(mm) */,20/* 细分 */);
- UserDmc.setAxisUp(3/* 轴号 */,0.72/* 步距角 */,1/* 螺距(mm) */,20/* 细分 */);
- var speedTab = UserDmc.setSpeedTab(
- 0/*轴号*/,
- 1/*起始速度(mm/s)*/,
- 5/*运行速度(mm/s)*/,
- null/*加速时间(s 默认0.05)*/,
- null/*减速时间(s 默认0.05)*/
- );
-
- thread.invoke(
- function(mainForm){
- import win.ui;
- import UserDmc;
-
- while(win.delay(20)){
- var a,b,c = UserDmc.getELOrg(mainForm.axis.text);
- mainForm.PEL.foreground= a?0xFFC7344A:0xFF008080;
- mainForm.ORG.foreground= b?0xFFC7344A:0xFF008080;
- mainForm.NEL.foreground= c?0xFFC7344A:0xFF008080;
- mainForm.nowpos.text = UserDmc.getPos(mainForm.axis.text);
- }
- },mainForm
- )
- }
- mainForm.lineON.oncommand = function(id,event){
- speedTab = UserDmc.setSpeedTab(
- 0/*轴号*/,
- 1/*起始速度(mm/s)*/,
- mainForm.speed.text/*运行速度(mm/s)*/,
- null/*加速时间(s 默认0.05)*/,
- null/*减速时间(s 默认0.05)*/
- );
- UserDmc.moveSV(mainForm.axis.text/*轴号*/,mainForm.dir.text/*方向:0=负向 1=正向*/,speedTab/*速度表(可为空但必须至少有一次填写)*/);
- }
- mainForm.stop.oncommand = function(id,event){
- UserDmc.stopMove(mainForm.axis.text);
- }
- mainForm.button.oncommand = function(id,event){
- speedTab = UserDmc.setSpeedTab(
- 0/*轴号*/,
- 1/*起始速度(mm/s)*/,
- mainForm.speed.text/*运行速度(mm/s)*/,
- null/*加速时间(s 默认0.05)*/,
- null/*减速时间(s 默认0.05)*/
- );
- UserDmc.moveSP(
- mainForm.axis.text/*轴号*/,
- mainForm.juli.text/*距离(mm)*/,
- mainForm.juedui.checked?true:null/*模式: null=相对运动 非null=绝对运动*/,
- speedTab/*速度表(可为空但必须至少有一次填写)*/
- );
- }
- mainForm.circleGo.oncommand = function(id,event){
- UserDmc.moveARC2(//圆弧插补
- mainForm.mainAxis.text/*主轴号*/,
- mainForm.secondAxis.text/*副轴号*/,
- mainForm.maincenter.text/*主轴圆心位置(mm)*/,
- mainForm.secondcenter.text/*副轴圆心位置(mm)*/,
- mainForm.maintarget.text/*主轴终点位置(mm)*/,
- mainForm.secondtarget.text/*副轴终点位置(mm)*/,
- mainForm.circledir.text/*方向:0=顺时针 1=逆时针*/,
- mainForm.circlejuedui.checked?true:null/*模式:null=相对位置 非null=绝对位置*/,
- mainForm.cieclespeed.text/*最大速度(mm/s)*/,
- null/*加减速时间(s,默认0.05)*/
- );
- }
- mainForm.setpos.oncommand = function(id,event){
- UserDmc.setPos(mainForm.axis.text,mainForm.setPos.text);
- }
- mainForm.show();
- return win.loopMessage();
复制代码
附件下载:
DMC2410Test.7z
(75.28 KB, 下载次数: 859)
|
|