beaglebone serial port interruption - serial-port

I need to set an interruption for the serial (uart) port in Beaglebone, in such a way that when the serial port receives any info an interruption (function) is automatically activated doing something with the received data.
I have searched methods to do so, but no success. I have worked with interruption for uart ports in microcontrollers, and I though I could do the same in Beaglebone.
Any suggestion to do it?
Thanks in advance.

Use the
select() or poll()
system call to do a polling on the tty file. As soon as any data arrives on the device file, you take the data and do the stuff you intend to do.
Or you can run a dedicated thread which continuously polls the uart and deals with the data.

Related

How can the master figure out if an I2C slave is busy without interrupting time-sensitive code on the slave?

So I have a device set as the I2C master, and the rest of the devices on the bus are set as slaves. The master sends a command to each slave, and the slave executes this task (running motors, etc, important time-sensitive code). I would like to be able to know when the slave is finished executing its task. The only way I can see to do this is to constantly have the master poll the slave, but this creates an issue, because every time the master polls the slave, it triggers and i2c interrupt on the slave and quits running the motor code for a short amount of time.
Is there anyway to solve this? I was thinking of setting all devices as a master, so then when each device finishes it task, it can send the data over saying that it is done, without the need for polling. The issue with this is I'm worried about data collision over the bus with devices possibly trying to talk at the same time.
What is the correct way to solve this issue?
Let the slave disable its I2C interface while it's running a time-critical task, and re-enable afterwards. Then, the master can poll as often as it wants to, it would get no ACK from the busy slave, and the slave won't get any interrupts either.

serial port is hostage of writer thread

I have two real-time threads(linux)
First one is to send bytes over serial port (kernel space)
Second one is to read the same bytes(because i used loop-back device) from serial port.
First thread sends data continuously and asynchronously, however;
second thread cannot open the serial port to read..
I used semaphores, but my problem i guess.. is not the synchronization issue,
my problem is serial port still in the hand of first thread.
How can I overcome this issue..
I am open to your suggestions,
Best Regards

Is is possible to simultaneously use Arduino serial monitor while receiving data from Processing?

I am attempting to send some data from Processing to my Arduino over the serial connection so that the Arduino can control an LED strip. Could I view the serial monitor while this transfer was taking place?
It is irking me that I cannot use any Serial.println statements (for debugging) while Processing is communicating with the Arduino. Everytime I try I get
Serial port 'COM3' already in use. Try quitting any programs that may be using it.
Is there a way for this serial communication to take place while I view the serial monitor at the same time?
The fact that the error message mentions COM3 suggests you are running on Windows. Unfortunately Windows doesn't allow multiple processes to simultaneously connect to the same serial port. This is different from Unix-based systems which do allow simultaneous serial port connections.
Using a Linux host, I have used a Python script send commands whilst monitoring results on the serial monitor. I seem to recall I had to open the serial monitor first and then run the other program.
Unfortunately, I can't help you with how to achieve that in Processing.
There is an application called Portmon that will allow you to monitor the serial communications on your PC.
Try 2 Serial communication,
Imagine you have already given USB as COM3 have a bluetooth device connected to your arduino Tx & Rx port, Let that be COM8. Now view COM3 in Arduino and COM8 in Processing.I could do this.

Check for Serial Port GSM Modem Connection status

I have a GSM ModeM connected to a serial port, and I use it so send SMS upon certain events.
Since it is not Plug-and-Play, I am confused as to how I'll detect its connection status. Win APIs like GetCommState will obviously not work.
I could periodically send packets of data and check whether the data is being consumed or not, but I'm wary about the risks of polling over performance and clogging up the buffers which might be in use.
So, is there any other method, or some interrupt based thing, which I could use to check whether is still connected, via a serial port, to my system?
I'd be grateful for any help on this.
Thanks.
From Windows 7 onwards, use Windows Mobile Broadband API to get information about a GSM modem.
Serial ports are very primitive communication devices, they date from the very early days of computing. It is what you plugged your ASR-33 teletype into to start banging in your Fortran program. The only reason they are still around is because they are simple, hardware vendors like them because they don't have to spend money developing and supporting a custom api to use their device.
Still, even back in the sixties did a computer have a need to find out if a teletype was attached. Which is done through the hardware handshake signals. The DSR signal, Data Set Ready, is turned on by the device when it is powered up. If you use the .NET SerialPort class then you can check that signal with the SerialPort.DsrHolding property. If you use the winapi then use GetCommModemStatus(), MS_DSR_ON flag.
That still only tells you that some device is attached. If you want to find out that it is the modem that you wrote your program for then you can interrogate it with AT commands, a protocol that's specific to modems. No vendor implements this exactly the same way but you can usually count on an identification from the modem with the ATI command. Check the programming manual for the modem for details.

Check if serial port is listening

I have an Arduino sending and receiving instructions with a Python script via a serial port.
The Arduino takes a button state and when it is pushed, it will send a message via the serial port to a Python script and await a response. (via Serial.available()). It works well enough.
However, if the Python script has crashed for whatever reason (ideally it will run in the background, so it can't be easily checked), the Arduino will wait forever and will be unavailable even on a script restart.
Is there a way for my Arduino to check if there is something listening on the serial port? (and alert me with flashing lights, etc. if not) or is this not how serial works? Worst case I guess I could use a timeout, although that is not ideal.
You have a limited ability to detect if there is something listening on the other side by using the DSR/DTR pins.
When you open the serial port on the machine your scripts runs on, it should raise its DTR pin (or you should be able to convince it to do so: the documentation of the library you use to drive the COM port should tell you how).
Then, on your Arduino, you can check its DSR pin (assuming null-modem wiring with handshaking, where the PC DTR pin is wired to DSR+CD on the Arduino) at regular intervals, and handle the 'nobody connected' scenario in any way you see fit.
One problem with this approach is that your PC script may not close the serial port when it crashes/stops responding, leaving the DTR pin enabled as if everything is still OK. Also, your script may simply miss the message from the Arduino due to errors on the serial line.
For that reason, you should always implement a timeout in your receive routines: even if there is a party listening at the other end, there is no guarantee it has received your message (or that its response will reach you intact).
Re-sending the message at least once (assuming DSR is raised) if a timeout occurs makes your protocol more reliable.
The Arduino doesn't use the DSR line or any other handshaking line, so you can't do what you suggest.
I agree with mdb that timeouts are necessary, but would also add that you might want to implement simple challenge/response system that periodically checks if anyone is listening. (I like ircd's Ping-Pong analogy).

Resources