Code for serial communication

1 回表示 (過去 30 日間)
s p
s p 2016 年 5 月 19 日

Hey guys, i have to write a code to communicate with an external device( a mixer) via rs232 and a raspberry. I can not try it at the moment, but i want to know, if the code will work. Every command has to end with a blank CR LF.

  • 0) do i send the mixers predefined commands correctly?
  • 1) do i set the terminator correctly?
  • 2) I want to get the name of the device. But the device is only sending after the command IN_NAME. Do i have to use fscanf or can i write name = fprintf(msd,'%s\n','IN_NAME '); ?
mypi = raspi
msd = serialdev(mypi,'/dev/ttyAMA0',9600,7,'even',1);
msd.Terminator = 'CR/LF';
fopen(msd);
fprintf(msd,'%s\n','IN_NAME ');
name=fscanf(msd);
disp(name);
%Set RPM to 100
fprintf(msd,'%s\n','OUT_SP_4 100 ');
%Start Mixer
fprintf(msd,'%s\n','START_4 ');
pause(10)
%Stop Mixer
fprintf(msd,'%s\n','STOP_4 ');
fclose(msd);
delete(msd);
clear msd

I hope you can help me :) and a BIG thanks in advance best regards

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Raspberry Pi Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by