Code covered by the BSD License  

Highlights from
cport

  • cportclose; function stat=cportclose(H) closes an open serial or parallel port
  • cportconfig; function stat=cportconfig(H,Name,Value,Name,Value,Name,Value...)
  • cportgetchar; function Params[ch,err]=cportstate(H,nchar) retrieves characters from a
  • cportopen; function H=cportopen(Port) opens a serial or parallel communication port
  • cportpurge; function stat=cportpurge(H) discards all characters from the output or
  • cportreset; function [stat,ErrStr]=cportreset(H) resets a previously opened communications
  • cportstate; function Params=cportstate(H) retrieves the configuration and timeout
  • cportwrite; function nW=cportwrite(H,Data,EOL) sends data to a previously opened
  • s=cportgetline(H,nMax,EOL,Tim... function s=cportgetline(H,nMax,EOL,Timeout) reads in one line of character
  • Contents.m
  • View all files

3.8

3.8 | 15 ratings Rate this file 7 Downloads (last 30 days) File Size: 174.99 KB File ID: #161

cport

by Eyal Doron

 

11 Aug 1999

The CPORT minitoolbox supplies basic functions to open, configure, read from,etc to ports.

| Watch this File

File Information
Description

The CPORT minitoolbox supplies basic functions to open, configure, read from and write to serial and parallel ports under microsoft Windows 95/98 and (maybe) NT. The toolbox is implemented using a series of MEX files and M files. Requires Windows95/98/NT and Matlab 5.x
 
Included functions:
-------------------
     cportopen - opens a serial or parallel port for use.
     cportconfig - returns/modifies the configuration of a port.
     cportwrite - writes characters to a port.
     cportgetchar - reads characters from a port.
     cportgetline - reads an entire character line from a port.
     cportreset - resets a port, retrieves error codes and strings
                    and flushes its buffers.
     cportclose - closes an open port.
 
 
Tested on Windows 95 under MATLAB 5.2

Required Products Instrument Control Toolbox
MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (21)
21 Sep 2001 Matias Bustos Santa Maria

This is just what i was looking for.

21 May 2002 Amin Habaibeh

I have tested the program. However, I have discovered when reading from RS232 that a 0x00 byte will be ignored when reading the data !

14 Apr 2003 bao pinglei

i find that i cannot read and write 'lpt1'
what is the wrong ??

27 Apr 2003 eng md

could you plz give example code lines in order to use the cportopen function to write to parallel port.

25 Jun 2003 Stepan Sutula  
31 Oct 2003 wang guodong  
17 Nov 2003 James Hough

Does it have a function for determining the number of bytes in the buffers

30 Mar 2004 Tjhang Suwandi

I already use this function, but i still can't write to lpt1. Is there a bug in this function, please help? (i'm using win98)

13 May 2004 Stas Maximov

Excellent tool when need to access serial port while running Matlab with -nojvm option (good idea for real-time simulation)!

As my two cents, the following patch might be in order to avoid possible garbage in input stream:

--- cportgetchar.c.00 1999-07-05 13:20:10.000000000 -0700
+++ cportgetchar.c 2004-05-13 13:19:11.000000000 -0700
@@ -63,7 +63,13 @@

 /* Create a matrix for the return arguments */

- CH_OUT = mxCreateString(ch);
+ if (ok) {
+ ch[nRead] = 0;
+ CH_OUT = mxCreateString(ch);
+ }
+ else {
+ CH_OUT = mxCreateString("");
+ }

   if (nlhs == 2) {
     STATUS = mxCreateDoubleMatrix(1, 1, mxREAL);

18 Jun 2004 Bob Brenson

it says time to time that matlab has no more virtual memory... Any idea why?

28 Oct 2005 Rarmundo CastaƱo

is well, i want to use a parallel port foy read & write for a s-function

21 Dec 2005 Wilson Nathan

The cport routines worked fine after a few tweaks. I'm using com1 with compiled m-files on Matlab 6.5 and Windows2000.

Issues/fixes:
- The unzipped DLLs worked fine in Matlab, but I had to recompile them for the Compiler.
- Putting the toolbox on my path did not allow Matlab's path search to correctly find both the DLL and the m (help) file, unless the toolbox was my current directory. I did add %#mex to each m file (didn't help).
- I had to add: #define MAXDWORD 1.7977e+308 to several of the .c files.
- cportgetline.m required several lines to be updates :
  % if nargin<3, EOL=sprintf'\r\n'; end
  if nargin<3, EOL= '\r\n' ; end % nbw - removed redundant sprintf

  if H==0, % nbw was: rc==0, and it was after the cportconfig statement.

  % nbw adjust config for timeout to function properly
  % cportconfig(H,'ReadIntervalTimeout',-1,'ReadTotalTimeoutMultiplier',0, 'ReadTotalTimeoutConstant',0);
  cportconfig(H,'ReadIntervalTimeout',1,'ReadTotalTimeoutMultiplier',0, 'ReadTotalTimeoutConstant',1);

  % if ch==EOL(length(EOL)) % check for EOL condition
  if (ch==EOL(length(EOL))) & (length(s)>= length(EOL)) % check for EOL condition, nbw: avoid array index errors

cportgetchar works great for rx'ing 1 char at a time; when more than 1 is requested it can return junk following the valid data.

Also, I recommend using cportconfig to init each of the serial port variables as no default or auto-init is provided.

Good toolbox overall.
nbw.

27 Dec 2005 karthik rao

HELP!!!!!

does this toolbox work for parallel port
i have a port monitor program and i tried to work with serial port using this toolbox ,and it worked fine also the portmonitor showed success
for parallel port the system was getting hung and the portmonitor program also showed an error

01 Jan 2006 umer bashir  
31 Jan 2006 SAMUEL DIEUDONNE YEBEL

Hello, I need MATLAB codes for Beveridge-Nelson and any others, in order to estimate Potential output.

18 Apr 2006 Heron Molina-Lozano  
10 Mar 2007 Jason Lu

Txk

09 Apr 2007 jorge cruz mancilla

gracias

03 Oct 2007 Simon Child

Works on Matlab 6.5, but not on Matlab 7.1

28 Mar 2008 Diego Diego

use TMTOOL

27 Jan 2010 Jimmy

Trying to use it in XP. But it cannot recognize any port (either com or ltp), although from the device manager I see the do work properly.

Any clues??

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
hardware driver Eyal Doron 22 Oct 2008 06:33:11
cport Eyal Doron 22 Oct 2008 06:33:11
tools Eyal Doron 22 Oct 2008 06:33:11
test and measurement Eyal Doron 22 Oct 2008 06:33:11
mini Eyal Doron 22 Oct 2008 06:33:11
serial port Eyal Doron 22 Oct 2008 06:33:11
hardware driver Enrique 04 Jun 2010 03:28:28

Contact us at files@mathworks.com