Accelerate fwrite in serial port communication

1 次查看(过去 30 天)
Hi,
I need to use fwrite to send a trigger to a program. I am looking for the fastest way in matlab (no java) to send a packet, when the packet size doesn't matter. Currently fwrite performs in ~0.1 sec. To test speed I send a packet from one computer to another computer and then send a packet back and measure the time. I exclude the run time of the fwrite in computer 2 and get my final times. My code is:
port = serial('COM1','BaudRate',9600);
port.Timeout = 1e3;
port.DataBits = 8;
fopen(port);
numIter = 100;
time = zeros(numIter,1);
for n = 1:numIter
timer = tic;
fwrite(port,1,'uint8');
fread(port,1);
time(n) = toc(timer);
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2015-8-6
My prediction: you are not using true serial ports, and are instead using USB (at least on the MATLAB side)
  1 个评论
Noam
Noam 2015-8-6
You are right. I am using a usb2RS232 converter. Ill try to connect it to a real COM port.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 AI for Wireless 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by