OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

os.system in python code crashes raspberry pi terminal?

  • Thread starter Thread starter Matt goose
  • Start date Start date
M

Matt goose

Guest
I'm trying to use can bus on the raspberry pi and I'm using a waveshare dual can hat. the sample code give is this:

Code:
import os
import can

print("hello1")
os.system('sudo ip link set can0 type can bitrate 100000')
os.system('sudo ifconfig can0 up')

print("hello2")

can0 = can.interface.Bus(channel = 'can0', bustype = 'socketcan')# socketcan_native

msg = can.Message(arbitration_id=0x143, data=[0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], extended_id=False)
msg = can0.recv(10.0)
print (msg)
if msg is None:
    print('Timeout occurred, no message.')

os.system('sudo ifconfig can0 down')

with exception of the edited data being sent and the hello check. But when I run the code it runs up to the first hello1 and nothing else. when I stop the process and test any command in the terminal of the raspberry pi it returns nothing. such as typing ifconfig and enter it just leaves a blank line with no error.

I also managed to establish an ssh connection via vs code, but since executing the code it doesn't allow me to connect and just repeatedly asks for my password.

Ive tried restarting the raspberry pi, adding a ssh file to the boot folder, running the code directly off the raspberry pi using vs code, running the command in the terminal.
<p>I'm trying to use can bus on the raspberry pi and I'm using a waveshare dual can hat. the sample code give is this:</p>
<pre><code>import os
import can

print("hello1")
os.system('sudo ip link set can0 type can bitrate 100000')
os.system('sudo ifconfig can0 up')

print("hello2")

can0 = can.interface.Bus(channel = 'can0', bustype = 'socketcan')# socketcan_native

msg = can.Message(arbitration_id=0x143, data=[0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], extended_id=False)
msg = can0.recv(10.0)
print (msg)
if msg is None:
print('Timeout occurred, no message.')

os.system('sudo ifconfig can0 down')
</code></pre>
<p>with exception of the edited data being sent and the hello check. But when I run the code it runs up to the first hello1 and nothing else. when I stop the process and test any command in the terminal of the raspberry pi it returns nothing. such as typing ifconfig and enter it just leaves a blank line with no error.</p>
<p>I also managed to establish an ssh connection via vs code, but since executing the code it doesn't allow me to connect and just repeatedly asks for my password.</p>
<p>Ive tried restarting the raspberry pi, adding a ssh file to the boot folder, running the code directly off the raspberry pi using vs code, running the command in the terminal.</p>
 

Latest posts

M
Replies
0
Views
1
Meliodas Dragon
M
Top