CAN Communication

5 years 4 months ago #29530843 by buchjyot
CAN Communication was created by buchjyot
Hi, I am running this code in a controller script to receive the message over CAN.

'the script starts from here'
loop2:

input = Getvalue(_DIN,15)
SetCommand(_CTPS,1,100)
'**********************************************************************
'CAN SENDING and RECIEVING LOOP STARTS HERE IF INPUT IS 1'
if input = 1 then
loop1:
wait(1000)
'**************************************************
'continously send speed data over CAN'
'************************************
Speed1 = GetValue(_S, 1) 'Read the encoder speed in RPM'
SetCommand(_VAR,1,Speed1) 'VAR 1 is now Speed'
goto loop1
end if
'**********************************************************************
wait(1000)
'**********************************************************************
goto loop2

I am not able to receive any data or message over the CAN. any idea, any troubleshoot tricks, any suggestions are welcome. your help is appreciated.

Please Log in or Create an account to join the conversation.

5 years 3 months ago - 5 years 3 months ago #29530848 by TechSupport
Replied by TechSupport on topic CAN Communication
Perhaps try with this script.

top:
if (getvalue(_CF, 1) > 0) ' if one or more frame is received
Header = getvalue(_CAN, 1)
ByteCount = getvalue(_CAN, 2)
Byte1 = getvalue(_CAN, 4)
Byte2 = getvalue(_CAN, 5)
print(Header,"\t", ByteCount,"\t",Byte1,"\t",Byte2,"\r")
end if
wait(10)
goto top

Make sure you are not connected via USB when trying to use can bus. If you are connected, then it won't work.
The following user(s) said Thank You: psammut

Please Log in or Create an account to join the conversation.

Moderators: tonysantoni
Time to create page: 0.161 seconds