Reputation: 21
I'm fairly new to Python and testing. I'm unable to wrap my head around that embedded systems can be tested with Python.
1) I don't understand how Python is able to communicate with the low level hardware of an embedded system.
2)How does Python communicate with C, so Python can start simulating an environment(starting SPI comm.) and receive information from the embedded system?
3) C is a low level language that is closer to the hardware, so it makes sense to me that we can control the peripherals on an embedded system. Python is a higher language and is abstracted from the hardware, so wouldn't we be unable to control the peripherals?
4)If we utilize a testing framework like Robot framework, then wouldn't we still have to set up some form of communication with the computer and embedded system in Python (maybe use Pyserial)?
Appreciate the help!
Upvotes: 1
Views: 1405
Reputation: 2082
I think I know where you come from, as I have been in your same situation. Embedded systems are a great source of "whys" and you can go down the rabbit hole pretty quickly. I'll give you some brief answers with some link to expand your curiosity.
Q0: I don't understand how Python is able to communicate with the low level hardware of an embedded system.
A0: This depends whether you are just communicating with the embedded system from an external OS which runs python, or python is run directly on the embedded system.
In the first case python will open the communication port ( being it serial, USB, bluetooth, TCP etc.. ) and start exchanging information with the system. Of course the end-point must be running something to communicate back to you. The easiest example is an Arduino sending ADC read values over the serial port and your python script reading them. Arduino <-> Python
In the second case an OS capable of running the python interpreter is directly on the embedded system (running embedded linux for instance). Now python can access all the resources of the system to control them, particularly it will have access to the peripherals and memory content. A little advanced - devmem with python
Q1: How does Python communicate with C, so Python can start simulating an environment(starting SPI comm.) and receive information from the embedded system?
A1: This question is very broad. Python can communicates with C in the sense that it can share the memory with compiled C routines, which then can do operations on the python objects, see "Glue it all together".
A second interpretation to your question is how can you run a simulation of an embedded system with python. It is possible to simulate a system with dedicated libraries (from processor vendors), qemu or HDL level (the level of details of what you can see varies greatly). Usually those libraries are written in C and the executable is loaded from python, it exposes functions to "talk" to the system being simulated, acting on stuff which would be difficult to do in the real world. You can switch on and off a button thousands of times, read and write registers on the fly and so on.
Q2: C is a low level language that is closer to the hardware, so it makes sense to me that we can control the peripherals on an embedded system. Python is a higher language and is abstracted from the hardware, so wouldn't we be unable to control the peripherals?
A2: The only situation where this question makes sense is the scenario 2 of Q0, where linux or some other OS is running. While it's true that python is a higher level language than C, most of the time when talking to the peripherals you are using system calls that boils down to the very same functions that would be used by C. If I remember correctly, for instance the serial.open()
python function is just a wrapper around (something like) fopen("/dev/tty")
C function. Both languages will issue a system call and the OS will do the work by setting up the serial port driver.
Working with bare metal C instead is a different thing, you will be responsible of every little details while talking to buses and peripherals. If you have python you have an OS by definition, hence it's better to leave it deal with these details.
Q3: If we utilize a testing framework like Robot framework, then wouldn't we still have to set up some form of communication with the computer and embedded system in Python (maybe use Pyserial)?
A3: I had a brief look at robot framework and it seems that all the communication is done through HTTP, though you might want to understand the answers 0,1 and 2, then get back here and ask something more clear. Also, robot frameworks seems related to web-testing and has nothing to do with embedded systems.
Upvotes: 3