Getting started - Send simple CAN message

Help and Assistance requestes

Getting started - Send simple CAN message

Postby ADuval » Fri May 18, 2018 11:19 am

Hello everyone,

Carberry and Raspberry are quiet new for me. I want to use it for my professional project (I need to send and receive CAN and LIN messages to the electronics parts of the car).
The thing is, I have a lot of questions and without the answer, it is harder to keep going. I will describe the step I did from the beginning til now and ask my questions step by step. I hope someone will be able to help me.

The raspberry is connected to an other screen/keyboard/mouse. I don't use Putty to control it from my computer.
I followed the step as described here : http://www.carberry.it/wiki/carberry/rp ... n_yourself
Then I connected the carberry to the raspberry and turned it on by sending 12V to the two red cables of the carberry (power and ignition).
Someone from the carberry support explained me that I have to create a socket in order to communicate with th ecarberry.
:?: First question : why do I need to do that, why can't I just send information to UART or just run a python file for example?
Below you can find a txt what I wrote in my raspberry in order to open a socket:

#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 7070
BUFFER_SIZE = 1024
MESSAGE = "AT\r\n"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()

print "received data:", data

:?: It is a .sh , do I need to write everything in .sh or can I use python (I am a little bit lost with all the language possibilities)
When I run it, I received the answer "OK"
Then I wanted to simulate CAN message. I have a dashboard that I want to turn on using CAN messages.
I read this : http://www.carberry.it/wiki/carberry/cmds/subsys/canbus and try to write the document
Then I try this :

#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 7070
BUFFER_SIZE = 1024
MESSAGE1 = "CAN MODE USER"
MESSAGE2 = "CAN USER OPEN CH1 500k"
MESSAGE3 = "CAN USER TX CH1 1397 134198320032"

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((TCP_IP,TCP_PORT))

s.send(MESSAGE1)
data = s.recv(BUFFER_SIZE)
print"received data:",data
s.send(MESSAGE2)
data = s.recv(BUFFER_SIZE)
print"received data:",data
s.send(MESSAGE3)
data = s.recv(BUFFER_SIZE)
print"received data:",data

s.close()

The dashboard doesn't turn on.
:?: Did someone already try to simulate CAN Message like that? How do I choose between ch1 and ch2? DO I have to send the message in hex or dec format?

Thanks for helping

Aurélie
ADuval
 
Posts: 8
Joined: Fri May 18, 2018 10:07 am

Re: Getting started - Send simple CAN message

Postby AChaalane » Tue May 22, 2018 5:07 pm

I am doing the same work but using Carberry as a LIN Bus Tranceiver. The script that you are using to communicate with Carberry is in Python. You can write it in a txt.py file (not .sh file) and run it in terminal. There are many client socket examples in the internet (in python, C, java..) that you can use to communicate with Carberry, so choose the language that you want.

Asma
AChaalane
 
Posts: 9
Joined: Wed Apr 18, 2018 10:38 am
Location: France

Re: Getting started - Send simple CAN message

Postby ADuval » Fri May 25, 2018 11:04 am

Thanks for your answer AChaalane, I will write it in python so.

I finally found what was wrong with my script, thanks to carberry support.
I had to use the cmd ALIGN RIGHT and write in hex format :

#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 7070
BUFFER_SIZE = 1024

MESSAGE0 = "CAN MODE USER\r\n"
MESSAGE1 = "CAN USER ALIGN RIGHT\r\n"
MESSAGE2 = "CAN USER OPEN CH1 500k\r\n"
MESSAGE3 = "CAN USER TX CH1 0575 C6200020\r\n"

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((TCP_IP,TCP_PORT))

s.send(MESSAGE0)
data = s.recv(BUFFER_SIZE)
print"received data:",data
s.send(MESSAGE1)
data = s.recv(BUFFER_SIZE)
print"received data:",data
s.send(MESSAGE2)
data = s.recv(BUFFER_SIZE)
print"received data:",data
s.send(MESSAGE3)
data = s.recv(BUFFER_SIZE)
print"received data:",data

s.close()
ADuval
 
Posts: 8
Joined: Fri May 18, 2018 10:07 am


Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests

cron