Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Controlling CR1000 using MATLAB


Tea Jun 7, 2011 08:47 PM

Hi,

I am trying to send some values (a command) from MATLAB to CR1000 but I am not sure what is the right way to do that.

I would be very grateful for any suggestion you might have.

Thanks


rajb245 Jun 22, 2011 06:00 PM

I am trying to do the same thing. My thought was that I could talk to the CR1000 over the serial interface using Matlab serial I/O (fd=serial('COM5'), then read/writing the file descriptor). I just want to be able to pull down data files from the logger and visualize them "on the fly" as the logger captures data.

Does anyone know if the serial interface to the CR1000 is documented? I can get a terminal on it and get some lists of commands by typing "H", but I was wondering if there is some better documentation.


IslandMan Jun 23, 2011 09:53 AM

If MATLAB can accept serial input you can program the CR1000 to send the data at periodic intervals, using the instantaneous or averaged data. Here is an example of sending serial data:
http://www.campbellsci.com/forum/messages.cfm?threadid=A63C24A3-D768-16A5-DD017975D65B6940


Sam Jun 26, 2011 02:07 AM

Other things you can try

* parse the "7" or "F" command responses from the terminal mode

* possibly use the xmlread instruction to pull and parse the data from the logger's web server over IP / Ethernet

-- http://www.mathworks.com/help/techdoc/import_export/f5-85862.html

-- See Web Server/API Commands in CRBasic help

* possibly use the loadlibrary function to use the BMP5.dll freely downloaded from our website

-- http://www.campbellsci.com/bmp5

-- http://www.campbellsci.com/downloads


rajb245 Jun 27, 2011 05:33 PM

Sam:

Thanks for the tips. The IP/Ethernet option you mentioned is what I decided to pursue. Matlab has a urlread function that will download a web page. I used this with the web API:
http://mylogger/?command=TableDisplay&xyz

Then I parsed the table data out of the HTML and can visualize the data in Matlab. I went down the xmlread route and tried a few HTML table parsing routines I found on the Mathworks site, both to no avail, so I'd suggest rolling your own, or I'm willing to share my code.

I now have real-time monitoring and custom visualizations of my logger data over Ethernet in MATLAB. I hope the above helps others trying to accomplish the same.


masdarmech Mar 18, 2015 11:45 AM

i know it's an old thread but just to put out the word for help:
@Rajb245,

i am also trying to establish the MATLAB-CR1000 link using the web server. it'll be great if you can share your HTML parsing code. my e-mail is:mali@masdar.ac.ae.

It'll be helpful to the MATLAB community if you can upload it on the MATLAB file exchange.

@SAM: i am trying to change some values in my datalogger using the "setvalueex" command. however, control commands require passing username and password information to the datalogger mentioned in the .csipasswd file. On a web browser, the first issuance of this command opens a dialog box requesting for credentials. Is there a way to pass this information using HTML commands that can be coded in MATLAB?


rajb245 Mar 18, 2015 02:53 PM

This is an old thread, but I'm glad you reached out. Unfortunately, I don't work for the same company and do not have access to this old code. From the documentation I wrote for it, I can give you the jist of how I accomplished reading tables over the http interface though:

1. Form the URL, something like
http://CR1000_IP/?command=TableDisplay&table=myTable&records=X

Replace the CR1000_IP, myTable, and X above with the IP address, table name, and number of records you want, respectively. You can put that URL into your browser to make sure it works correctly.

2. Call the function "urlread" on that URL, which returns a string with all the HTML code returned by the CR1000 web server.

3. Parse the HTML. What I wrote was based on matching regular expressions and was apparently inspired by this:
http://www.mathworks.com/matlabcentral/fileexchange/29642-get-html-table-data-into-matlab-via-urlread-and-without-builtin-browser

I don't recall why I didn't use the above code directly, but I suspect that it does not "just work" with the Campbell table format.


masdarmech Apr 7, 2015 07:16 AM

dear rajb,

we wrote a matlab script for handling HTML tags after reading the desired table. i wanted to ask you were you able to change the variable values from MATLAB? i am trying to use urlread command with the HTML control command mentioned in the CSI webserver manual. however, till now i haven't been able to do it.

when i try to issue the same command on a browser with the login and password added in prefix i.e. http:\\login@password:IP....., it opens a dialog box that warns me that i am trying to enter this website. i click "OK" on the dialog box and the command works.

any suggesions to resolve this problem are welcome.

thanks,


rajb245 Apr 7, 2015 02:30 PM

I never tried to change anything on the CR1000 side; I only wanted to read the tables into MATLAB and make plots that updated every second or so, giving me almost "live" plots of measured quantities.

So you try to do a urlread in MATLAB, and access the same URL in a browser, and it works differently? It sounds like pressing "OK" in the browser probably issues another HTTP GET or POST command that tells the server to run the command. Examine the HTML that comes back when you issue the urlread; it should give you a clue as to what you reply with to get the server to run the command.

I would also look at the HTTP connection data (using Wireshark to capture the packets) to see what is different between urlread and using the browser too, but that's a bit more advanced.

Maybe someone form Campbell will reply with a better solution. Since I don't have CR1000 hardware anymore, I can't really be of more assistance.


masdarmech Apr 30, 2015 04:14 PM

The code for changing variables in CR1000 using MATLAB can be found here:
http://stackoverflow.com/questions/1317931/how-do-i-provide-a-username-password-to-access-a-web-resource-using-matlab-urlre

Log in or register to post/reply in the forum.