![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
MATLAB M-files |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SOSI Model 2 has been designed to operate with MATLAB. SOSI communicates in ASCII text directly with the MATLAB serial() function on MS-Windows® or Linux®. A zip file collection of tested m-files is located on the Downloads page. This package contains M-files of basic commands to operate and interact with SISO-M2. It also contains related M-file functions used to create more specialized SOSI-M2 functions. For example, the function serial9600() opens the serial port and returns a serial port object with its communication parameters set correctly. This is used as one of the input arguments to cmd().
The above codes are structured the following way:
*After a command is sent, a delay is required before reading a serial communication reply from SOSI-M2 in order to allow the host serial buffer to receive the reply string. A 0.05 second delay is enough time to allow the string plus terminator to arrive. Commands in which SOSI first writes to non-volitile EEPROM memory before sending a reply require a delay of 0.5 seconds before a read is performed. These commands are:.
The main body of stand-alone functions contain the following steps:
MATLAB Command Line
One may test run sub-functions from the command line before implementing a longer function. For example,
First, disable sleep mode (using the stand-alone function here): port='COM2';
setsleep(port,0) Open the serial port: spo=serial9600(port)
Display the present channel configuration: fprintf(spo,'#shc')
serialread(spo) Change the output format to print the 'x' axis as sample count: fprintf(spo,'#seoi')
serialread(spo) We are finished for now: fclose(spo)
If an M-file contained these commands, enclose the above code in a try-catch block. In the case of an error, the script would otherwise return before the ending fclose(). Placing fclose() in the catch will close the serial port.
Script Errors
If a serial port M-file initially runs but then MATLAB gives the error message:
"Port: (port) is not available. Available ports: (other port)
Use INSTRFIND to determine if other instrument objects are connected to the requested device." The serial port was not closed by a previous M-file before the last M-file tried to re-open it. The catch-try code is intended to prevent this. Restart MATLAB to free the port. Free serial port monitors are available which may be used to monitor opening and closing of the serial port and thereby aid code debugging.
MATLAB Serial Bugs
The M-file scripts have been tested working with MATLAB R12 (under Linux) and R14 (under Windows). Certain versions of MATLAB have serial communication issues which may require these steps:
R12 (MS-Windows) "MATLAB relies on the javax.comm.properties file to inform it what serial
ports are available. There have been some reported cases where the serial ports are seen only if the javax.comm.properties file is moved from it's current location: matlabroot\java\jarext\commapi\win32 to: matlabroot\sys\java\jre\win32\jre\lib Note, this dependency on the javax.comm.properties file will be removed in the next release of MATLAB. Source R13 (MS-Windows) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||