-
Notifications
You must be signed in to change notification settings - Fork 0
/
canrx_ethtx.py
40 lines (28 loc) · 916 Bytes
/
canrx_ethtx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import can
import socket
import time
#bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
def receiveOnCAN():
bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
msg = bus.recv()
return msg.data
#HOST = '169.254.214.14' #socket.gethostname()
#PORT = 5005
#s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.connect((HOST, PORT))
def sendOverEthernet(msg):
HOST = '169.254.214.14' #socket.gethostname()
PORT = 5005
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send(msg)
time.sleep(4)
#s.send('\n')
#s.send('\r')
s.close()
while 1:
can_data = receiveOnCAN()
print(can_data) #temporal
if can_data:
sendOverEthernet(can_data)