필터 지우기
필터 지우기

Create log from multiple serial object simultaneously

조회 수: 1 (최근 30일)
Nuno Martins
Nuno Martins 2011년 4월 11일
편집: Francesco Paparella 2016년 12월 14일
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
Jerry Trantow
Jerry Trantow 2014년 3월 17일
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 2016년 12월 14일
편집: Francesco Paparella 2016년 12월 14일
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?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Instrument Connection and Communication에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by