网站首页

产品展示 运动控制 技术培训 全球网点 资料下载 技术论坛 联系方式
当前日期为 :
站内搜索
  
  →产品目录
::
独立式运动控制器
::
1轴运动控制器
::
高功能运动控制器
::
24轴运动控制器
::
请到”资料下载”获得更多
::
64轴运动控制器
  →联系方式
 

英国翠欧运动技术公司上海代表处

电 话:021-58797659

传 真:021-58794289

邮 箱:triomotion@126.com

邮 编:200122

地 址:上海市浦东新区张扬路188号汤臣中心B栋1701房

网 址:http://www.triomotion.com
 
 
资料下载
 

TRIO产品之间CAN总线通讯程序例子

发布时间:2006年11月14日 点击:1229次

"-------------------------------------------------------------------------
" module:   trio_can_net          version: v1.0            date:  14/11/2006
" author:       wang ye
" rev date:     14 nov 2006
"=========================================================================
" revision history:
"   v1.0 original release for communicating between mc2xx each other by can net.
"
"=========================================================================
"              copyright (c)1999 trio motion technology ltd
"                 unit 2, empire way, gloucester, gl2 5hy
"         http://www.triomotion.com     email: sales@triomotion.com
"=========================================================================
"desc-ription:
"1)   set up a network of up to 16 mc2xx units on can.
"2)   each module will use the vr area from "vbase" to "vbase+180".
"3)   each module have a special area in the vr for sending.(the area is 10 datas)
"     the area start address can be gotten by the parameter "can_id" and "vbase":
"      start_address=vbase+10*(can_id-1)
"     the map of vr allocated for each module based can_id can be listed:
"            can_id                vr() memory address
"               1                  vbase->vbase+9
"  2     vbase+10->vbase+19
"  3     vbase+20->vbase+29
"  4     vbase+30->vbase+39
"  5     vbase+40->vbase+49
"  6     vbase+50->vbase+59
"  7     vbase+60->vbase+69
"  8     vbase+70->vbase+79
"  9     vbase+80->vbase+89
"  10     vbase+90->vbase+99
"  11     vbase+100->vbase+109
"  12     vbase+110->vbase+119
"  13     vbase+120->vbase+129
"  14     vbase+130->vbase+139
"  15     vbase+140->vbase+149
"  16     vbase+150->vbase+159"
"
"4)   so, you can get datas from any other mc module just by reading the corresponding vr.
"     for example: set the can_id of current module is 2, vbase=100
"     you modify the vr(110)=100, then you could read the value of vr(110)
"     from others module of this can network, if all others module set the vbase=100.  
"5)   note: each module of can networks must set different can_id.
"     the value of can_id from 1 to 16. don"t over this value.
"     as long as don"t over the limit of can_id, you can use any more mc2xx in the networks. as well as
"           set any value for can_id.
"     don"t use the area from vbase+160 to vbase+180, because it will be used by system.
"          
"=========================================================================
can_id=15 " the can identifer of trio can network
mctype=0 " if it"s mc206x, the value=1; otherwise=0

vbase=100
interval=100

gosub initcan
while true
    gosub send_proc
    gosub receive_proc
wend


initcan:
    canio_enable=off
    "init the baud rate
    can(-1,2,1)
    "init the message
    for i=0 to 15
        if mctype=1 then
            if(i=can_id-1) then
                can(-1,5,i,i+1,5,1) "send
            else
                can(-1,5,i,i+1,5,0)
            endif
        else
            if(i=can_id-1) then
                can(-1,5,i,i+1,5) "send
            else

                can(-1,5,i,i+1,5)
            endif
        endif
    next i
return

send_proc:
    if ticks<=0 then
        for i=0 to 9
            vr(vbase+160+i)=vr(vbase+10*(can_id-1)+i)
            b0=ieee_out(vr(vbase+160+i),0)
            b1=ieee_out(vr(vbase+160+i),1)
            b2=ieee_out(vr(vbase+160+i),2)
            b3=ieee_out(vr(vbase+160+i),3)
            for n=1 to 16
                if n=can_id then
                        can(-1,7,n-1,i,b0,b1,b2,b3)
                endif
            next n
            ticks=interval
        next i
    else
        for i=0 to 9
            if vr(vbase+160+i)<>vr(vbase+10*(can_id-1)+i) then
                vr(vbase+160+i)=vr(vbase+10*(can_id-1)+i)
                b0=ieee_out(vr(vbase+160+i),0)
                b1=ieee_out(vr(vbase+160+i),1)
                b2=ieee_out(vr(vbase+160+i),2)
                b3=ieee_out(vr(vbase+160+i),3)
                for n=1 to 16
                    if n=can_id then
                        can(-1,7,n-1,i,b0,b1,b2,b3)
                    endif
                next n
            endif
        next i
    endif
return

receive_proc:
    for i=0 to 15
"        if (i<>can_id) then
            if can(-1,3,i) then
                can(-1,6,i,vbase+10*17)
                id=vr(vbase+10*17)
                offset=vr(vbase+10*17+1)
                b0=vr(vbase+10*17+2)
                b1=vr(vbase+10*17+3)
                b2=vr(vbase+10*17+4)
                b3=vr(vbase+10*17+5)
                res=ieee_in(b0,b1,b2,b3)
                vr(vbase+10*(id-1)+offset)=res
            endif
"        endif
    next i
return

网站首页 | 公司简介 | 产品展示 | 运动控制 | 产品销售 | 全球网点 | 资料下载 | 技术论坛 | 联系我们
主营产品:MC302x,MC206x,Euro205x,MC224x,PCI208,以及各种子板和扩展模块
电话:021-58797659 传真:021-58794289 邮箱:triomotion@126.com 联系人:赵铁男
地址:上海市浦东新区张扬路188号汤臣英国翠欧运动技术公司上海代表处 © 版权所有 中国工控展览网 技术支持 网站管理入口 GoogleSiteMap沪ICP备08020800号