How can I input data in real time?

I have a C++ program that spits out data from an instrument. It can not be embedded in Matlab. I need a way to stream the data into matlab/simulink in real time.
I have used a text file method, but it only runs at about 100 Hz. It seems opening and closing the file takes too long. I need my program to run at 10Khz.
Is there any way to get data into Matlab this quickly? Perhaps some type of port emulation thing? Some type of direct read and write from memory?

댓글 수: 2

Suneesh
Suneesh 2014년 2월 24일
1. Does the C++ program offer some kind of an API? You could use that from MATLAB/Simulink perhaps from an S-Function.
2. If the program is able to send out UDP or TCP/IP packets then the Instrument Control Toolbox has features that allows to receive such packets.
Note, Simulink does not run in realtime. You could run a model in "pseudo-realtime" using something like this:
This might not be applicable to you but, we do have real-time products like Real Time Windows target and xPC Target.
James116
James116 2014년 2월 25일
편집: James116 2014년 2월 25일
The c program is just something I wrote. I should have specified that I am building to an external target. The target will not accept my s functions for this particular c++ code.
Here is what I ended up doing:
-Downloaded a serial port emulator (Virtual Serial Ports Emulator, available from Cnet)
- Wrote the following code into to my C++ program:
#include <windows.h>
HANDLE hSerial;
hSerial = CreateFile( "COM2", GENERIC_WRITE, 0,0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
DCB dcbSerialParams = {0};
dcbSerialParams.BaudRate= 921600;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
DWORD dwBytesWritten = 0;
WriteFile(hSerial, &intdata, sizeof(intdata), &dwBytesWritten, NULL);
Then I used a serial receive block to get the data into simulink. I achieved about 10x the speed of the text file method. I may try TCP/IP next.
Thank you for your response

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 System Configuration에 대해 자세히 알아보기

질문:

2014년 2월 24일

편집:

2014년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by