What is the best way to learn new stuff? By choosing a small project
I want to write a small monitoring program for a machine. For example, it should plot the last 5 minutes of temperature of a certain range as a graph. At the moment I do this with Excel. Yes Excel! With Datastreamer it works, but it is slow and has bugs.
I have installed a small device that sends sensor data packets via Bluetooth. I want to receive and process them.
I managed to get single strings via the serial port.
Here is the code:
sp = LibSerialPort.open("COM4", 115200)
#Examp String: "11:09:14.993: 28.69;28.69;28.71;28.65;28.69;28.59;28.63;28.69;28.75;28.77;28.79;34.11"
But how do I get a constant reading of the data that I can stop at any time? I must admit, I can’t read the documentation of LibSerialPort properly. I lack program examples to follow. Maybe there is an elegant solution for this that I don’t know. Any ideas?
I’ve made it so far that I have a jerky real time plot. Plus a log file to view everything in peace.
But I still have a question. Is there a way to check if the serial port is open? Because when I try things and run into an error or abort the process the serial port is not closed. And if I accidentally open the port again an error pop up. It would help me if I could detect it.
@Sukera – thought of you here!
Detecting whether something is connected to a serial port is a bit challenging - on linux at least, if the serial port is there (i.e. it’s mounted and the “file” exists) you can generally try to read from it, though such a read is not guaranteed to succeed (the story is similar on windows). After all, there is no notion of “connectedness”, there either is data coming in or there isn’t and “listening” on a serial port means having the correct settings to hopefully decode the changes in voltage on the physical wire into logical ones and zeros to detect that data.
I think “opening” a serial port more or less means “setting the settings I know the other end sends with”, while closing should mean resetting that to a “off” default. I can’t tell you for sure, since the API documentation for LibSerialPort gives me a 404 Though if you still have the
SerialPort object on the julia side,
isopen should probably work.
Sorry for the late replay.
This works half the way. If you kill the process it works fin.
If i throw an error in the try-block it doesn’t work. But i can live with that.
So thank you.