Why doesn't it work?

2 ビュー (過去 30 日間)
Bence Salanki
Bence Salanki 2015 年 9 月 28 日
コメント済み: Bence Salanki 2015 年 9 月 29 日
Hi,
I'm trying to create a serial communication between two of my USB ports with two USB-serial adapter and a cross-over cable. I'm using the following code:
input = serial('COM3');
output = serial('COM4');
fwrite(input, 'hello');
fgets(output);
After fgets() this is what I get:
Warning: A timeout occurred before the Terminator was reached.
It seems like there is no stop bit after the characters and I don't know what to do with it. Please help me.
Thanks.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 9 月 29 日
fwrite(input, sprintf('%s\n', 'hello'));
or
fprintf(input, '%s\n', 'hello');
or
fprintf(input, 'hello'); %special case, adds \n automatically
  1 件のコメント
Bence Salanki
Bence Salanki 2015 年 9 月 29 日
Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by