serial connection via matlab

Applications, development tools, FPGA, C, WEB
Post Reply
r.a.mccracken
Posts: 5
Joined: Fri Feb 19, 2016 5:23 pm

serial connection via matlab

Post by r.a.mccracken » Wed Jun 01, 2016 3:21 pm

Hi,

I'm communicating with my RP via serial as I don't have an ethernet connection on my MacBook. I have managed to establish a Matlab connection and can output voltage signals, however I can't get seem to acquire data. When using 'query', the response is always the last command sent. I have attached code below - any help is appreciated!

Code: Select all

 s=serial'/dev/cu.usbserial-DB00FW8L','BaudRate',115200,'DataBits',8,'Parity','none','StopBits',1,'FlowControl','none','Terminator','CR/LF');
fopen(s);
fprintf(s,'root');     % This and following 'root' are necessary to login to the RP
pause(1);
fprintf(s,'root');
pause(1);
fclose(s);
s.InputBufferSize=16384*32;

fopen(s);
fprintf(s,'generate 1 1 200000 sqr');   % This command works, output has been checked on oscilloscope.
pause(1);
query(s,'acquire 1024 8');
fclose(s);


Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: serial connection via matlab

Post by Nils Roos » Wed Jun 01, 2016 3:46 pm

According to this description, a 'query' without format specifiers reads single characters (default input format %c) from the com object until the first end of line. Thus, you only see the console echo of your command.

"acquire" outputs its results as pairs of values with a newline after each pair. So maybe instead of using 'query', you'd be better of sending the command with 'fprintf' and receiving the results with a series of 'fscanf'.

r.a.mccracken
Posts: 5
Joined: Fri Feb 19, 2016 5:23 pm

Re: serial connection via matlab

Post by r.a.mccracken » Wed Jun 01, 2016 4:03 pm

Thanks for the quick reply. Could you be more specific about the pairs of values that are put out using acquire, for example are the unsigned/signed integers, floating point numbers, strings?

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: serial connection via matlab

Post by Nils Roos » Wed Jun 01, 2016 4:24 pm

From acquire.c:

Code: Select all

printf("%7d %7d\n", (int)s[1][i], (int)s[2][i]);
The array s contains the raw ADC samples from both channels.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 91 guests