Create log from multiple serial object simultaneously

2 views (last 30 days)
Hello,
I have a GPS receiver and a wind sensor, both connected to my computer via serial port (adapted to usb). My main objective is to log the time and date string and the 3 axis speed measured by the wind sensor into a .txt file. The process of creating the serial objects is pretty straightforward. In order to obtain the data on request ('real time') I set the ReadAsyncMode on both objects to manual. The GPS receiver is providing data at 4Hz, while the wind sensor will be working in an higher frequency, 20Hz or 32Hz. I also used a terminator character to each string in order to retrieve only one line at once. In order to test the connections i created one loop, to sample N data strings from one of the devices and measure the time with tic toc. This allowed me to retrieve the frequency in which each device is working in. In this test loop I tried both fscanf(serial_obj) and fgetl(serial_obj) functions and the fprintf to log data in the .txt file. Separately, they both work perfectly. But my objective is to log them at the same time, where each line will have the GPS string and the wind sensor string at that given time. When I try to log both serial objects as:
fprintf(file_name, [fscanf(gps), fscanf(rms)])
inside a loop, the time needed to log that data is much higher than it should be. Even if I try to log data as:
fprintf(file_name, [fscanf(gps), fscanf(rms), fscanf(rms), fscanf(rms), fscanf(rms), fscanf(rms)])
given that the wind sensor frequency is 5 times higher than the GPS receiver, I get much lower speeds. Logging each device in separate Matlab windows gives correct acquisition frequencies.
I would appreciate any advice (since it's within Matlab and not other program).
Thanks in advance.
  2 Comments
Jerry Trantow
Jerry Trantow on 17 Mar 2014
Did you ever figure this out? I'm having a similar problem with two serial ports. I attach two serial port objects to a rx callback to service them after a certain number of characters. Each works by itself, but when they are both receiving chars I am dropping characters.
Francesco Paparella
Francesco Paparella on 14 Dec 2016
Edited: Francesco Paparella on 14 Dec 2016
I have a similar problem for the communication with two serial ports as well. Each port works fine when tested alone while, when tested together, one of the ports has a significant delay in the transmission of the data..does anybody have a solution to this?

Sign in to comment.

Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!