comport-0.2/0000755000076500007650000000000012036675377011534 5ustar hanshanscomport-0.2/CHANGES.txt0000644000076500007650000000054110755130437013332 0ustar hanshans1.0 - 25.1.2006 released with pd_darwin makefile extension 1.0RC2 - 18.11.2005 made more C-compatible and LGPL added some code for NT and a Test SWITCH for W2000 1.0RC1 - (12.4.2005) first check in pure-data.sourceforge.net added print feature and USB devices from posted by Marc Boon 0.9beta2 (somedate before 2004) CHANGES.txt startet comport-0.2/LICENSE.txt0000644000076500007650000005760211433646655013366 0ustar hanshanscomport - PD External for the serial Ports Institute for Electronic Music and Acoustics Copyright (C) 1998-2005 Winfried Ritsch This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. (see below) --------------------------- LGPL.TXT ------------------------ GNU Lesser General Public License Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONScomport-0.2/Makefile0000644000076500007650000002652011504200264013153 0ustar hanshans## Pd library template version 1.0.6 # For instructions on how to use this template, see: # http://puredata.info/docs/developer/MakefileTemplate LIBRARY_NAME = comport # add your .c source files, one object per file, to the SOURCES # variable, help files will be included automatically SOURCES = comport.c # list all pd objects (i.e. myobject.pd) files here, and their helpfiles will # be included automatically PDOBJECTS = # example patches and related files, in the 'examples' subfolder EXAMPLES = # manuals and related files, in the 'manual' subfolder MANUAL = # if you want to include any other files in the source and binary tarballs, # list them here. This can be anything from header files, test patches, # documentation, etc. README.txt and LICENSE.txt are required and therefore # automatically included EXTRA_DIST = CHANGES.txt comport.dsp comport.dsw comport-stress-test.pd makefile_win #------------------------------------------------------------------------------# # # things you might need to edit if you are using other C libraries # #------------------------------------------------------------------------------# # -I"$(PD_INCLUDE)/pd" supports the header location for 0.43 CFLAGS = -I"$(PD_INCLUDE)/pd" -Wall -W -g LDFLAGS = LIBS = #------------------------------------------------------------------------------# # # you shouldn't need to edit anything below here, if we did it right :) # #------------------------------------------------------------------------------# # get library version from meta file LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd) CFLAGS += -DPD -DVERSION='"$(LIBRARY_VERSION)"' PD_INCLUDE = $(PD_PATH)/include # where to install the library, overridden below depending on platform prefix = /usr/local libdir = $(prefix)/lib pkglibdir = $(libdir)/pd-externals objectsdir = $(pkglibdir) INSTALL = install INSTALL_PROGRAM = $(INSTALL) -p -m 644 INSTALL_DATA = $(INSTALL) -p -m 644 INSTALL_DIR = $(INSTALL) -p -m 755 -d ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \ $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows) DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION) UNAME := $(shell uname -s) ifeq ($(UNAME),Darwin) CPU := $(shell uname -p) ifeq ($(CPU),arm) # iPhone/iPod Touch SOURCES += $(SOURCES_iphoneos) EXTENSION = pd_darwin OS = iphoneos PD_PATH = /Applications/Pd-extended.app/Contents/Resources IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin CC=$(IPHONE_BASE)/gcc CPP=$(IPHONE_BASE)/cpp CXX=$(IPHONE_BASE)/g++ ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) LIBS += -lc STRIP = strip -x DISTBINDIR=$(DISTDIR)-$(OS) else # Mac OS X SOURCES += $(SOURCES_macosx) EXTENSION = pd_darwin OS = macosx PD_PATH = /Applications/Pd-extended.app/Contents/Resources OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast # build universal 32-bit on 10.4 and 32/64 on newer ifeq ($(shell uname -r | sed 's|\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*|\1|'), 8) FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=10.4 else FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4 SOURCES += $(SOURCES_iphoneos) endif CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib # if the 'pd' binary exists, check the linking against it to aid with stripping LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd) LIBS += -lc STRIP = strip -x DISTBINDIR=$(DISTDIR)-$(OS) # install into ~/Library/Pd on Mac OS X since /usr/local isn't used much pkglibdir=$(HOME)/Library/Pd endif endif ifeq ($(UNAME),Linux) CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif ifeq ($(UNAME),GNU) # GNU/Hurd, should work like GNU/Linux for basically all externals CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif ifeq ($(UNAME),GNU/kFreeBSD) # Debian GNU/kFreeBSD, should work like GNU/Linux for basically all externals CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) CPU := $(shell uname -m) SOURCES += $(SOURCES_cygwin) EXTENSION = dll OS = cygwin PD_PATH = $(cygpath $(PROGRAMFILES))/pd OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += LDFLAGS += -Wl,--export-dynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" LIBS += -lc -lpd STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS) endif ifeq (MINGW,$(findstring MINGW,$(UNAME))) CPU := $(shell uname -m) SOURCES += $(SOURCES_windows) EXTENSION = dll OS = windows PD_PATH = $(shell cd "$(PROGRAMFILES)"/pd && pwd) OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer CFLAGS += -mms-bitfields LDFLAGS += -s -shared -Wl,--enable-auto-import LIBS += -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS) endif # in case somebody manually set the HELPPATCHES above HELPPATCHES ?= $(SOURCES:.c=-help.pd) $(PDOBJECTS:.pd=-help.pd) CFLAGS += $(OPT_CFLAGS) .PHONY = install libdir_install single_install install-doc install-exec install-examples install-manual clean dist etags $(LIBRARY_NAME) all: $(SOURCES:.c=.$(EXTENSION)) %.o: %.c $(CC) $(CFLAGS) -o "$*.o" -c "$*.c" %.$(EXTENSION): %.o $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(LIBS) chmod a-x "$*.$(EXTENSION)" # this links everything into a single binary file $(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS) chmod a-x $(LIBRARY_NAME).$(EXTENSION) install: libdir_install # The meta and help files are explicitly installed to make sure they are # actually there. Those files are not optional, then need to be there. libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples install-manual $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) test -z "$(strip $(SOURCES))" || (\ $(INSTALL_PROGRAM) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \ $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))) test -z "$(strip $(PDOBJECTS))" || \ $(INSTALL_DATA) $(PDOBJECTS) \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) # install library linked as single binary single_install: $(LIBRARY_NAME) install-doc install-exec $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_PROGRAM) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION) install-doc: $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) test -z "$(strip $(SOURCES) $(PDOBJECTS))" || \ $(INSTALL_DATA) $(HELPPATCHES) \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_DATA) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt $(INSTALL_DATA) LICENSE.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/LICENSE.txt install-examples: test -z "$(strip $(EXAMPLES))" || \ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \ for file in $(EXAMPLES); do \ $(INSTALL_DATA) examples/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples; \ done install-manual: test -z "$(strip $(MANUAL))" || \ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual && \ for file in $(MANUAL); do \ $(INSTALL_DATA) manual/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual; \ done clean: -rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) -rm -f -- $(SOURCES:.c=.$(EXTENSION)) -rm -f -- $(LIBRARY_NAME).o -rm -f -- $(LIBRARY_NAME).$(EXTENSION) distclean: clean -rm -f -- $(DISTBINDIR).tar.gz -rm -rf -- $(DISTBINDIR) -rm -f -- $(DISTDIR).tar.gz -rm -rf -- $(DISTDIR) -rm -f -- $(ORIGDIR).tar.gz -rm -rf -- $(ORIGDIR) $(DISTBINDIR): $(INSTALL_DIR) $(DISTBINDIR) libdir: all $(DISTBINDIR) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR) $(INSTALL_DATA) $(SOURCES) $(DISTBINDIR) $(INSTALL_DATA) $(HELPPATCHES) $(DISTBINDIR) test -z "$(strip $(EXTRA_DIST))" || \ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTBINDIR) # tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR) $(DISTDIR): $(INSTALL_DIR) $(DISTDIR) $(ORIGDIR): $(INSTALL_DIR) $(ORIGDIR) dist: $(DISTDIR) $(INSTALL_DATA) Makefile $(DISTDIR) $(INSTALL_DATA) README.txt $(DISTDIR) $(INSTALL_DATA) LICENSE.txt $(DISTDIR) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTDIR) test -z "$(strip $(ALLSOURCES))" || \ $(INSTALL_DATA) $(ALLSOURCES) $(DISTDIR) test -z "$(strip $(PDOBJECTS))" || \ $(INSTALL_DATA) $(PDOBJECTS) $(DISTDIR) test -z "$(strip $(HELPPATCHES))" || \ $(INSTALL_DATA) $(HELPPATCHES) $(DISTDIR) test -z "$(strip $(EXTRA_DIST))" || \ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTDIR) test -z "$(strip $(EXAMPLES))" || \ $(INSTALL_DIR) $(DISTDIR)/examples && \ for file in $(EXAMPLES); do \ $(INSTALL_DATA) examples/$$file $(DISTDIR)/examples; \ done test -z "$(strip $(MANUAL))" || \ $(INSTALL_DIR) $(DISTDIR)/manual && \ for file in $(MANUAL); do \ $(INSTALL_DATA) manual/$$file $(DISTDIR)/manual; \ done tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR) # make a Debian source package dpkg-source: debclean make distclean dist mv $(DISTDIR) $(ORIGDIR) tar --exclude-vcs -czpf ../$(ORIGDIR).orig.tar.gz $(ORIGDIR) rm -f -- $(DISTDIR).tar.gz rm -rf -- $(DISTDIR) $(ORIGDIR) cd .. && dpkg-source -b $(LIBRARY_NAME) etags: etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h showsetup: @echo "CFLAGS: $(CFLAGS)" @echo "LDFLAGS: $(LDFLAGS)" @echo "LIBS: $(LIBS)" @echo "PD_INCLUDE: $(PD_INCLUDE)" @echo "PD_PATH: $(PD_PATH)" @echo "objectsdir: $(objectsdir)" @echo "LIBRARY_NAME: $(LIBRARY_NAME)" @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)" @echo "SOURCES: $(SOURCES)" @echo "PDOBJECTS: $(PDOBJECTS)" @echo "ALLSOURCES: $(ALLSOURCES)" @echo "UNAME: $(UNAME)" @echo "CPU: $(CPU)" @echo "pkglibdir: $(pkglibdir)" @echo "DISTDIR: $(DISTDIR)" @echo "ORIGDIR: $(ORIGDIR)" comport-0.2/README.txt0000644000076500007650000000154610755130437013225 0ustar hanshanscomport - PD external for unix/windows to use the serial ports (c) 1998-2005 Winfried Ritsch (see LICENCE.txt) Institute for Electronic Music - Graz on Windows the COM0, COM1, ... are used and under Unix devices /dev/ttyS0, /dev/ttyS1, ... and new on unix /dev/USB0, ... and can be accessed via a Index. Please see testcomport.pd for more help. USE: There should be a external comport.dll for windows, comport.pd_linux for linux and so on. just copy it to the extra folder of your pd Installation or working directory. Please see testcomport.pd for more help. compile: Unix (Linux): make pd_linux, make pd_irix5, make pd_irix6, make pd_darwin should produce a comport.pd_linux, .... Windows: use nmake or just use Fast Build under MSVC++ nmake pd_nt If you have improvements or questions feel free to contact me under ritsch _at_ iem.at comport-0.2/comport-help.pd0000644000076500007650000001556411726311337014471 0ustar hanshans#N canvas 67 105 1015 636 10; #X obj 488 438 comport 1 9600; #X msg 276 421 66; #X msg 234 421 64; #X text 273 403 point; #X text 231 403 stream; #X msg 318 421 86; #X text 315 403 position; #X msg 380 421 70; #X msg 420 421 71; #X text 376 403 run; #X text 416 403 sleep; #X msg 314 61 bits 8; #X msg 340 87 stopbit 0; #X msg 400 147 parity 0; #X text 467 146 parity 1=even \, -1=odd \, 0=off; #X text 363 60 databits 5 \, 6 \, 7 \, 8; #X obj 488 412 r comctl; #X obj 694 458 s comctl; #X text 500 166 use handshake xon/off 1=on 0=off; #X text 512 186 cts/rts hardwarehandshake 1=on 0=off; #X msg 460 207 pollintervall 1; #X msg 482 229 close; #X msg 503 250 open 1; #X text 521 228 Close Serial port; #X msg 666 413 devicename /dev/ttyS1; #X text 35 511 (C) 1998-2005 IEM Winfried Ritsch GPL (see LICENSE.txt) ; #X obj 135 50 hsl 128 15 0 255 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 550 249 Open serial port by number; #X text 804 413 open the serial port by name; #X msg 606 353 dtr \$1; #X obj 575 354 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 -1 0 1; #X obj 595 374 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -258113 -1 0 1; #X msg 626 373 rts \$1; #X text 655 352 dtr output; #X text 675 372 rts output; #X msg 367 300 help; #X msg 585 332 verbose \$1; #X obj 554 334 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 -1 0 1; #X text 560 206 set poll interval for read in ms; #X msg 321 254 info; #X floatatom 569 527 10 0 0 1 baud - -; #X floatatom 644 568 3 0 0 3 parity - -; #X floatatom 669 568 3 0 0 2 stop - -; #X floatatom 694 567 3 0 0 3 data - -; #X floatatom 770 529 3 0 0 0 port - -; #X msg 544 291 devices; #X obj 141 74 % 255; #X floatatom 179 91 5 0 0 0 - - -; #X text 602 290 print available devices (wait for it...); #X obj 142 113 key; #X obj 170 130 sel 0; #X floatatom 249 147 4 0 0 0 ascii - -; #X msg 524 271 open 0; #X obj 719 533 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699 -1 0 1; #X obj 745 549 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699 -1 0 1; #X text 508 567 serial packet format:; #X text 660 517 handshaking:; #X text 466 599 flow control inputs:; #X obj 594 599 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1 0 1; #X obj 619 599 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1 0 1; #N canvas 307 43 789 479 bauds 0; #X msg 319 274 baud 57600; #X msg 357 312 baud 230400; #X msg 338 293 baud 115200; #X msg 300 255 baud 38400; #X msg 281 236 baud 19200; #X msg 262 217 baud 9600; #X msg 243 198 baud 4800; #X msg 224 179 baud 2400; #X obj 431 403 s comctl; #X msg 205 160 baud 1800; #X msg 186 141 baud 1200; #X msg 167 122 baud 600; #X msg 148 103 baud 300; #X msg 129 84 baud 200; #X msg 91 46 baud 134; #X msg 72 27 baud 110; #X msg 53 8 baud 75; #X msg 34 -11 baud 50; #X msg 15 -30 baud 0; #X msg 110 65 baud 150; #X text 368 255 this is a special baud rate that can be configured ; #X text 12 -48 standard baud rates for linux:; #X text 64 -31 0 deasserts control lines and resets the serial port ; #X text 435 312 won't work with standard setup. See setserial; #X msg 431 231 baud \$1; #X text 518 269 on-the-fly with setserial:; #X text 519 298 gives 14400 baud instead of 38400; #X text 517 284 "setserial /dev/ttyS0 spd_cust divisor 8"; #X msg 419 163 115200; #X floatatom 392 104 7 1 115200 1 divisor - -; #X obj 431 192 / 1; #X obj 392 123 sel 0; #X floatatom 431 212 7 0 0 0 - - -; #X text 482 103 (1-115200); #X obj 419 143 t b f; #X text 390 86 On Windows some other baud rates might work:; #X connect 0 0 8 0; #X connect 1 0 8 0; #X connect 2 0 8 0; #X connect 3 0 8 0; #X connect 4 0 8 0; #X connect 5 0 8 0; #X connect 6 0 8 0; #X connect 7 0 8 0; #X connect 9 0 8 0; #X connect 10 0 8 0; #X connect 11 0 8 0; #X connect 12 0 8 0; #X connect 13 0 8 0; #X connect 14 0 8 0; #X connect 15 0 8 0; #X connect 16 0 8 0; #X connect 17 0 8 0; #X connect 18 0 8 0; #X connect 19 0 8 0; #X connect 24 0 8 0; #X connect 28 0 30 0; #X connect 29 0 31 0; #X connect 30 0 32 0; #X connect 31 1 34 0; #X connect 32 0 24 0; #X connect 34 0 28 0; #X connect 34 1 30 1; #X restore 314 37 pd bauds; #X msg 420 167 xonxoff \$1; #X obj 387 167 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 -1 0 1; #X msg 440 187 rtscts \$1; #X obj 408 187 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 -1 0 1; #X text 17 -4 comport: a serial port interface; #X msg 243 176 13; #X obj 795 530 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699 -1 0 1; #X msg 565 312 ports; #X obj 820 564 print port_list; #X text 611 311 list available ports on right outlet; #X msg 275 208 48 49 50 51 52 53 54 55 56 57; #X text 137 207 send a list of bytes:; #X msg 295 228 print hello_world; #X text 196 228 send some text:; #X msg 646 393 hupcl \$1; #X obj 614 394 tgl 15 0 empty empty empty 17 7 0 10 -257985 -258113 -1 0 1; #X text 704 386 hang up connection on last close; #X text 717 398 (not on Windows); #X obj 934 520 print other; #X text 205 176 :; #X text 143 254 status list on right outlet:; #X text 257 300 print usage info:; #X obj 845 527 tgl 15 0 empty empty hupcl -6 20 1 11 -24198 -258699 -1 0 1; #X msg 452 110 1; #X msg 482 110 1.5; #X msg 513 110 2; #X text 444 127 number of stopbits (Windows only); #X msg 380 127 stopbit \$1; #X text 403 86 extra stopbit 1=on \, 0=off (linux \, MacOS); #X text 16 30 You can send bytes directly (0-255):; #X text 12 112 or from the terminal:; #X text 56 420 messages for the bird patch:; #X floatatom 870 540 10 0 0 1 rxerrors - -; #X obj 569 490 route baud dsr cts parity stop data rtscts xonxoff port open ports hupcl rxerrors; #X text 37 526 2006-2010 Martin Peach; #X msg 685 433 retries 10; #X text 754 432 how many times to retry a lost connection; #X text 761 206 (default is 1 tick 10ms); #X connect 0 1 94 0; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 5 0 0 0; #X connect 7 0 0 0; #X connect 8 0 0 0; #X connect 11 0 17 0; #X connect 12 0 17 0; #X connect 13 0 17 0; #X connect 16 0 0 0; #X connect 20 0 17 0; #X connect 21 0 17 0; #X connect 22 0 17 0; #X connect 24 0 17 0; #X connect 26 0 46 0; #X connect 29 0 17 0; #X connect 30 0 29 0; #X connect 31 0 32 0; #X connect 32 0 17 0; #X connect 35 0 0 0; #X connect 36 0 17 0; #X connect 37 0 36 0; #X connect 39 0 0 0; #X connect 45 0 17 0; #X connect 46 0 0 0; #X connect 46 0 47 0; #X connect 49 0 50 0; #X connect 50 1 51 0; #X connect 50 1 0 0; #X connect 52 0 17 0; #X connect 61 0 17 0; #X connect 62 0 61 0; #X connect 63 0 17 0; #X connect 64 0 63 0; #X connect 66 0 0 0; #X connect 68 0 17 0; #X connect 71 0 0 0; #X connect 73 0 0 0; #X connect 75 0 17 0; #X connect 76 0 75 0; #X connect 84 0 88 0; #X connect 85 0 88 0; #X connect 86 0 88 0; #X connect 88 0 17 0; #X connect 94 0 40 0; #X connect 94 1 58 0; #X connect 94 2 59 0; #X connect 94 3 41 0; #X connect 94 4 42 0; #X connect 94 5 43 0; #X connect 94 6 53 0; #X connect 94 7 54 0; #X connect 94 8 44 0; #X connect 94 9 67 0; #X connect 94 10 69 0; #X connect 94 11 83 0; #X connect 94 12 93 0; #X connect 94 13 79 0; #X connect 96 0 17 0; comport-0.2/comport-meta.pd0000644000076500007650000000027612036674125014463 0ustar hanshans#N canvas 15 49 200 200 10; #N canvas 25 49 420 300 META 1; #X text 13 41 NAME comport; #X text 10 25 AUTHOR Winfried Ritsch and others; #X text 10 10 VERSION 0.2; #X restore 10 10 pd META; comport-0.2/comport-stress-test.pd0000644000076500007650000000272110755130437016031 0ustar hanshans#N canvas 459 49 508 349 12; #N canvas 0 0 502 352 stress 0; #X obj 83 28 inlet; #X obj 73 288 outlet; #X obj 100 101 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 74 130 spigot; #X obj 74 154 bang; #X obj 74 181 random 300; #X obj 74 207 moses 256; #X text 86 238 make it send somewhat slower than full speed; #X connect 0 0 3 0; #X connect 2 0 3 1; #X connect 3 0 4 0; #X connect 4 0 5 0; #X connect 5 0 6 0; #X connect 6 0 1 0; #X coords 0 -1 1 1 85 17 1 100 100; #X restore 30 280 pd stress test; #X text 12 263 hard test:; #X text 14 27 soft test:; #X msg 116 48 bang; #X msg 191 48 stop; #X obj 117 89 random 256; #X obj 116 117 trigger bang float; #X obj 161 200 float; #X obj 161 173 delay; #X obj 52 117 bang; #X obj 274 165 metro 1000; #X msg 269 194 246; #X text 237 254 keep data coming from the arduino; #X obj 277 140 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X msg 330 196 240; #X text 362 195 stop; #X obj 149 280 comport 3; #X obj 196 150 / 10; #X msg 112 226 close; #X msg 334 223 238; #X connect 0 0 16 0; #X connect 3 0 5 0; #X connect 4 0 8 0; #X connect 5 0 6 0; #X connect 6 0 8 0; #X connect 6 1 7 1; #X connect 6 1 17 0; #X connect 7 0 16 0; #X connect 8 0 7 0; #X connect 8 0 9 0; #X connect 9 0 5 0; #X connect 10 0 11 0; #X connect 11 0 16 0; #X connect 13 0 10 0; #X connect 14 0 16 0; #X connect 16 0 0 0; #X connect 17 0 8 1; #X connect 18 0 16 0; #X connect 19 0 16 0; comport-0.2/comport.c0000644000076500007650000016430512036673747013373 0ustar hanshans/* comport - PD external for unix/windows (c) 1998-2005 Winfried Ritsch (see LICENCE.txt) Institute for Electronic Music - Graz V 1.0 MP 20060603 memset and memcpy arguments were backwards for Windows version. close_serial doesn't crash now. MP 20060618 make sure name is set up in comport_new (x->serial_device = test.serial_device) so help message works. MP 20060619 implemented status outlet MP 20060620 Add DTR and RTS control, add outputs to reflect CTS and DSR states. MP 20060621 Do all the above for Windows too. MP 20060709 All status goes out the status outlet when an info message is received MP 20060824 added clock_delay call in comport_devicename MP 20060924 added comport_enum to list available ports in Windows MP 20060925 add devices message to enumerate actual devices, info just outputs current port state MP 20061016 write_serial checks for GetOverlappedResult to avoid tx buffer overflow errors MP 20070719 added "ports" method to output list of available ports on status outlet MP 20071011 added comport_list and write_serials for list processing based on code by Thomas O Fredericks MP 20071113 modified non-windows open_serial to set the index of the port when it's opened by name MP 20080916 fixed Windows version stop bits to set and display 1, 1.5 or 2 for "stopbits" input of 1, 1.5 or 2 MP 20100201 use a buffer for writes, write takes place during clock callback comport_tick() */ #include "m_pd.h" #ifdef _MSC_VER #pragma warning( disable : 4244 ) #pragma warning( disable : 4305 ) #endif #ifdef _WIN32 #include #include #else #include #include #include /* for ioctl DTR */ #include /* for TERMIO ioctl calls */ #include #include #define HANDLE int #define INVALID_HANDLE_VALUE -1 #endif /* _WIN32 */ #include #include #include typedef struct comport { t_object x_obj; long n; /* the state of a last input */ #ifdef _WIN32 HANDLE comhandle; /* holds the comport handle */ DCB dcb; /* holds the comm pars */ DCB dcb_old; /* holds the comm pars */ COMMTIMEOUTS old_timeouts; #else int comhandle; /* holds the comport handle */ struct termios oldcom_termio; /* save the old com config */ struct termios com_termio; /* for the new com config */ #endif t_symbol *serial_device; char serial_device_prefix[FILENAME_MAX];/* the device name without the number */ short comport; /* holds the comport # */ t_float baud; /* holds the current baud rate */ t_float data_bits; /* holds the current number of data bits */ t_float parity_bit; /* holds the current parity */ t_float stop_bits; /* holds the current number of stop bits */ int xonxoff; /* nonzero if xonxoff handshaking is on */ int ctsrts; /* nonzero if ctsrts handshaking is on */ int hupcl; /* nonzero if hang-up on close is on */ short rxerrors; /* holds the rx line errors */ t_clock *x_clock; int x_hit; int x_retries; int x_retry_count; double x_deltime; int verbose; t_outlet *x_data_outlet; t_outlet *x_status_outlet; unsigned char *x_inbuf; /* read incoming serial to here */ unsigned char *x_outbuf; /* write outgoing serial from here */ int x_inbuf_len; /* length of inbuf */ int x_outbuf_len; /* length of outbuf */ int x_outbuf_wr_index; /* offset to next free location in x_outbuf */ } t_comport; #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef ON #define ON 1 #define OFF 0 #endif /* Serial Port Return Values */ #define NODATAAVAIL -1 #define RXERRORS -2 #define RXBUFOVERRUN -4 #define TXBUFOVERRUN -5 #define COMPORT_MAX 99 #define USE_DEVICENAME 9999 /* use the device name instead of the number */ #define COMPORT_BUF_SIZE 16384 /* this should be the largest possible packet size for a USB com port */ #ifdef _WIN32 /* we don't use the table for windos cos we can set the number directly. */ /* This may result in more possible baud rates than the table contains. */ /* static long baudspeedbittable[] = { CBR_115200, CBR_57600, CBR_56000, CBR_38400, CBR_19200, CBR_14400, CBR_9600, CBR_4800, CBR_2400, CBR_1800, CBR_1200, CBR_600, CBR_300, CBR_110 }; */ #else /* _WIN32 */ #ifdef IRIX #define OPENPARAMS (O_RDWR|O_NDELAY|O_NOCTTY) #define TIONREAD FIONREAD /* re map the IOCTL function */ #define BAUDRATE_230400 -1 #define BAUDRATE_115200 -1 #define BAUDRATE_57600 -1 #define BAUDRATE_38400 B38400 #else /* IRIX */ #define OPENPARAMS (O_RDWR|O_NDELAY|O_NOCTTY) #define BAUDRATE_230400 B230400 #define BAUDRATE_115200 B115200 #define BAUDRATE_57600 B57600 #define BAUDRATE_38400 B38400 #endif /* else IRIX */ static long baudspeedbittable[] = { BAUDRATE_230400, BAUDRATE_115200, /* CPU SPECIFIC */ BAUDRATE_57600, /* CPU SPECIFIC */ BAUDRATE_38400, /* CPU SPECIFIC */ B19200, B9600, B4800, B2400, B1800, B1200, B600, B300, B200, B150, B134, B110, B75, B50, B0 }; struct timeval null_tv; #define BAUDRATETABLE_LEN 19 static long baudratetable[] = { 230400L, 115200L, 57600L, 38400L, 19200L, 9600L, 4800L, 2400L, 1800L, 1200L, 600L, 300L, 200L, 150L, 134L, 110L, 75L, 50L, 0L }; /* holds the baud rate selections */ #endif /* else _WIN32 */ /* From man cfsetospeed: cfsetospeed() sets the output baud rate stored in the termios structure pointed to by termios_p to speed, which must be one of these constants: B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 B38400 B57600 B115200 B230400 The zero baud rate, B0, is used to terminate the connec­ tion. If B0 is specified, the modem control lines shall no longer be asserted. Normally, this will disconnect the line.*/ t_class *comport_class; static void comport_pollintervall(t_comport *x, t_floatarg g); static void comport_retries(t_comport *x, t_floatarg g); static void comport_tick(t_comport *x); static float set_baudrate(t_comport *x, t_float baud); static float set_bits(t_comport *x, int nr); static float set_parity(t_comport *x,int n); static float set_stopflag(t_comport *x, t_float nr); static int set_ctsrts(t_comport *x, int nr); static int set_dtr(t_comport *x, int nr); static int set_rts(t_comport *x, int nr); static int set_xonxoff(t_comport *x, int nr); static int set_serial(t_comport *x); static int write_serial(t_comport *x, unsigned char serial_byte); static int write_serials(t_comport *x, unsigned char *serial_buf, int buf_length); static int comport_get_dsr(t_comport *x); static int comport_get_cts(t_comport *x); #ifdef _WIN32 static HANDLE open_serial(unsigned int com_num, t_comport *x); static HANDLE close_serial(t_comport *x); #else static int set_hupcl(t_comport *x, int nr); static int open_serial(unsigned int com_num, t_comport *x); static int close_serial(t_comport *x); static long get_baud_ratebits(t_float *baud); #endif static void comport_pollintervall(t_comport *x, t_floatarg g); static void comport_tick(t_comport *x); static void comport_float(t_comport *x, t_float f); static void comport_list(t_comport *x, t_symbol *s, int argc, t_atom *argv); static void *comport_new(t_symbol *s, int argc, t_atom *argv); static void comport_free(t_comport *x); static void comport_baud(t_comport *x,t_floatarg f); static void comport_bits(t_comport *x,t_floatarg f); static void comport_parity(t_comport *x,t_floatarg f); static void comport_stopbit(t_comport *x,t_floatarg f); static void comport_rtscts(t_comport *x,t_floatarg f); static void comport_dtr(t_comport *x,t_floatarg f); static void comport_rts(t_comport *x,t_floatarg f); static void comport_xonxoff(t_comport *x,t_floatarg f); static void comport_hupcl(t_comport *x,t_floatarg f); static void comport_close(t_comport *x); static void comport_open(t_comport *x, t_floatarg f); static void comport_devicename(t_comport *x, t_symbol *s); static void comport_print(t_comport *x, t_symbol *s, int argc, t_atom *argv); static void comport_output_status(t_comport *x, t_symbol *selector, t_float output_value); static void comport_output_port_status(t_comport *x); static void comport_output_dsr_status(t_comport *x); static void comport_output_cts_status(t_comport *x); static void comport_output_baud_rate(t_comport *x); static void comport_output_parity_bit(t_comport *x); static void comport_output_stop_bits(t_comport *x); static void comport_output_data_bits(t_comport *x); static void comport_output_rtscts(t_comport *x); static void comport_output_xonxoff(t_comport *x); static void comport_output_hupcl(t_comport *x); static void comport_output_rxerrors(t_comport *x); static void comport_enum(t_comport *x); static void comport_info(t_comport *x); static void comport_devices(t_comport *x); static void comport_ports(t_comport *x); static void comport_verbose(t_comport *x, t_floatarg f); static void comport_help(t_comport *x); void comport_setup(void); /* --------- sys independent serial setup helpers ---------------- */ /* ------------ sys dependent serial setup helpers ---------------- */ /* --------------------- NT ------------------------------------ */ #ifdef _WIN32 static float set_baudrate(t_comport *x,t_float baud) { x->dcb.BaudRate = (DWORD)baud ;//!!!try directly setting any baud rate...was get_baud_ratebits(&baud); return baud; } /* bits are 5,6,7,8(default) */ static float set_bits(t_comport *x, int nr) { if(nr < 4 && nr > 8) nr = 8; /* number of bits/byte, 4-8 */ return x->dcb.ByteSize = nr; } /* 1 ... Parity even, -1 parity odd , 0 (default) no parity */ static float set_parity(t_comport *x,int n) { switch(n) { case 1: x->dcb.fParity = TRUE; /* enable parity checking */ x->dcb.Parity = 2; /* 0-4=no,odd,even,mark,space */ return 1; case -1: x->dcb.fParity = TRUE; /* enable parity checking */ x->dcb.Parity = 1; /* 0-4=no,odd,even,mark,space */ return -1; default: x->dcb.fParity = FALSE; /* enable parity checking */ x->dcb.Parity = 0; /* 0-4=no,odd,even,mark,space */ } return 0; } /* Windows lets you have three different stop bit styles: 1,1.5 and 2 */ /* The message argument is the number of stop bits */ static float set_stopflag(t_comport *x, t_float nr) { if(nr == 1) { x->dcb.StopBits = 0; /* ONESTOPBIT = 0 */ return nr; } if(nr == 2) { x->dcb.StopBits = 2; /* TWOSTOPBITS = 2 */ return nr; } if(nr == 1.5) { x->dcb.StopBits = 1; /* ONE5STOPBITS = 1 */ return nr; } post("comport stopbit number (%g) out of range (0, 1.5, 2)", nr); return 0; } /* never tested */ static int set_ctsrts(t_comport *x, int nr) { if(nr == 1) { x->dcb.fOutxCtsFlow = TRUE; /* CTS output flow control */ x->dcb.fRtsControl = RTS_CONTROL_ENABLE; /* RTS flow control */ return 1; } x->dcb.fOutxCtsFlow = FALSE; /* CTS output flow control */ x->dcb.fRtsControl = RTS_CONTROL_DISABLE; /* RTS flow control */ return 0; } static int set_dtr(t_comport *x, int nr) { HANDLE fd = x->comhandle; BOOL status; DWORD dwFunc = (nr==0)?CLRDTR:SETDTR; if (fd == INVALID_HANDLE_VALUE) return -1; status = EscapeCommFunction(fd, dwFunc); if (status != 0) return nr; return -1; /* didn't work, GetLastError tells why */ } static int set_rts(t_comport *x, int nr) { HANDLE fd = x->comhandle; BOOL status; DWORD dwFunc = (nr==0)?CLRRTS:SETRTS; if (fd == INVALID_HANDLE_VALUE) return -1; status = EscapeCommFunction(fd, dwFunc); if (status != 0) return nr; return -1; /* didn't work, GetLastError tells why */ } static int set_xonxoff(t_comport *x, int nr) { /* x->dcb.fTXContinueOnXoff = FALSE; XOFF continues Tx */ if(nr == 1) { x->dcb.fOutX = TRUE; /* XON/XOFF out flow control */ x->dcb.fInX = TRUE; /* XON/XOFF in flow control */ return 1; } x->dcb.fOutX = FALSE; /* XON/XOFF out flow control */ x->dcb.fInX = FALSE; /* XON/XOFF in flow control */ return 0; } static int set_serial(t_comport *x) { if (SetCommState(x->comhandle, &(x->dcb))) return 1; /* Didn't work. Get the actual state of the device */ GetCommState(x->comhandle, &(x->dcb)); x->baud = x->dcb.BaudRate; x->data_bits = x->dcb.ByteSize; x->parity_bit = x->dcb.fParity; /* ONESTOPBIT=0, ONE5STOPBITS=1, TWOSTOPBITS=2*/ if(x->dcb.StopBits == 0) x->stop_bits = 1; else if(x->dcb.StopBits == 1) x->stop_bits = 1.5; else if(x->dcb.StopBits == 2) x->stop_bits = 2; x->xonxoff = (x->dcb.fOutX)?1:0; x->ctsrts = (x->dcb.fOutxCtsFlow)?1:0; return 0; } static int set_hupcl(t_comport *x, int nr) { // this is a dummy function since Windows doesn't use HUPCL, AFAIK hans@eds.org } static HANDLE open_serial(unsigned int com_num, t_comport *x) { HANDLE fd; COMMTIMEOUTS timeouts; char buffer[MAX_PATH]; float *baud = &(x->baud); DWORD dw; int i; char *errStr; if (com_num != USE_DEVICENAME) { if(com_num < 1 || com_num >= COMPORT_MAX) { post("comport number %d out of range (1-%d)", com_num, COMPORT_MAX); return INVALID_HANDLE_VALUE; } #ifdef _MSC_VER sprintf_s(buffer, MAX_PATH, "%s%d", x->serial_device_prefix, com_num); #else sprintf(buffer, "%s%d", x->serial_device_prefix, com_num); #endif x->serial_device = gensym(buffer); } else { #ifdef _MSC_VER sprintf_s(buffer, MAX_PATH, "\\\\.\\%s", x->serial_device->s_name); /* assume the slashes were not prefixed by user */ #else sprintf(buffer, "\\\\.\\%s", x->serial_device->s_name); /* assume the slashes were not prefixed by user */ #endif x->serial_device = gensym(buffer); } post("Opening %s", &x->serial_device->s_name[4]);/* skip slashes and dot */ fd = CreateFileA( x->serial_device->s_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); if(fd == INVALID_HANDLE_VALUE) { dw = GetLastError(); switch (dw) { case 2: errStr = "ERROR_FILE_NOT_FOUND"; break; case 3: errStr = "ERROR_PATH_NOT_FOUND"; break; case 5: errStr = "ERROR_ACCESS_DENIED"; break; case 53: errStr = "ERROR_BAD_NETPATH"; break; case 123: errStr = "ERROR_INVALID_NAME"; break; default: errStr = " "; break; } pd_error(x, "[comport]: could not open device %s:\n failure(%ld) %s\n", &x->serial_device->s_name[4], dw, errStr); return INVALID_HANDLE_VALUE; } /* Save the Current Port Configuration */ if (!GetCommState(fd, &(x->dcb_old))) { pd_error(x, "[comport]: could not get old dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); return INVALID_HANDLE_VALUE; } memset(&(x->dcb), 0, sizeof(DCB)); if (!GetCommState(fd, &(x->dcb))) { pd_error(x, "[comport]: could not get new dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); return INVALID_HANDLE_VALUE; } x->dcb.fBinary = TRUE; /* binary mode, no EOF check */ /* x->dcb.fOutxDsrFlow = FALSE; DSR output flow control */ /* x->dcb.fDtrControl = DTR_CONTROL_DISABLE; DTR flow control type */ /* x->dcb.fDsrSensitivity = FALSE; DSR sensitivity */ x->dcb.fErrorChar = FALSE; /* enable error replacement */ /* x->dcb.fNull = FALSE; enable null stripping */ /* DWORD x->dcb.fAbortOnError:1; abort reads/writes on error */ /* char x->dcb.XonChar; Tx and Rx XON character */ /* char x->dcb.XoffChar; Tx and Rx XOFF character */ /* char x->dcb.ErrorChar; error replacement character */ /* char x->dcb.EofChar; end of input character */ /* char x->dcb.EvtChar; received event character */ set_bits(x, x->data_bits); /* CS8 */ set_stopflag(x, x->stop_bits); /* ~CSTOPB */ set_ctsrts(x, x->ctsrts); /* ~CRTSCTS;*/ set_xonxoff(x, x->xonxoff); /* (IXON | IXOFF | IXANY) */ set_baudrate(x, *baud); x->comhandle = fd; if (com_num == USE_DEVICENAME) { /* extract index from device name */ for (i = 0; x->serial_device->s_name[i] != 0; ++i) if ((x->serial_device->s_name[i] >= '0') && (x->serial_device->s_name[i] <= '9')) com_num = atoi(&x->serial_device->s_name[i]); } if(set_serial(x)) { post("[comport] opened serial line device %d (%s)\n", com_num, &x->serial_device->s_name[4]); } else { pd_error(x, "[comport] could not set params to control dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); return INVALID_HANDLE_VALUE; } if (!GetCommTimeouts(fd, &(x->old_timeouts))) { post("[comport] Couldn't get old timeouts for serial device (%d)", GetLastError()); } /* setting new timeouts for read to immediately return */ timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; if (!SetCommTimeouts(fd, &timeouts)) { post("Couldn't set timeouts for serial device (%d)", GetLastError()); return INVALID_HANDLE_VALUE; } if (!SetupComm(x->comhandle, 4096L, 4096L))/* try to get big buffers to avoid overruns*/ { post("[comport] Couldn't do SetupComm (%d)", GetLastError()); } x->comport = com_num;/* output on next tick */ return fd; } static HANDLE close_serial(t_comport *x) { if(x->comhandle != INVALID_HANDLE_VALUE) { if (!SetCommState(x->comhandle, &(x->dcb_old))) { post("[comport] ** ERROR ** couldn't reset params to DCB of device %s\n", &x->serial_device->s_name[4]); } if (!SetCommTimeouts(x->comhandle, &(x->old_timeouts))) { post("[comport] Couldn't reset old_timeouts for serial device"); } CloseHandle(x->comhandle); post("[comport] closed %s", &x->serial_device->s_name[4]); } return INVALID_HANDLE_VALUE; } static int comport_get_dsr(t_comport *x) { short dsr_state = 0; if(x->comhandle != INVALID_HANDLE_VALUE) { DWORD modemStat; /* get the DSR input state and if it's changed, output it */ BOOL status = GetCommModemStatus(x->comhandle, &modemStat); if (status) { dsr_state = ((modemStat&MS_DSR_ON)!=0);/* read the DSR input line */ } else { ;/* call GetLastError, only once so as not to hang pd */ } } return dsr_state; } int comport_get_cts(t_comport *x) { short cts_state = 0; if (x->comhandle != INVALID_HANDLE_VALUE) { DWORD modemStat; /* get the DSR input state and if it's changed, output it */ BOOL status = GetCommModemStatus(x->comhandle, &modemStat); if (status) { cts_state = ((modemStat&MS_CTS_ON)!=0);/* read the CTS input line */ } else { ;/* call GetLastError, only once so as not to hang pd */ } } return cts_state; } #else /* NT */ /* ----------------- POSIX - UNIX ------------------------------ */ static long get_baud_ratebits(t_float *baud) { int i = 0; while(i < BAUDRATETABLE_LEN && baudratetable[i] > *baud) i++; if(baudratetable[i] != *baud) post("[comport]: %d not valid, using closest value: ", *baud, baudratetable[i]); /* nearest Baudrate finding */ if(i==BAUDRATETABLE_LEN || baudspeedbittable[i] < 0) { post("*Warning* The baud rate %d is not supported or out of range, using 9600\n",*baud); i = 8; } *baud = baudratetable[i]; return baudspeedbittable[i]; } static float set_baudrate(t_comport *x, t_float baud) { struct termios *tio = &(x->com_termio); speed_t baudbits = get_baud_ratebits(&baud); if (x->verbose > 0) post("[comport] set_baudrate: Setting baud rate to %g with baudbits 0x%X", baud, baudbits); if( cfsetispeed(tio, baudbits) != 0 ) post("[comport]: ERROR failed to set bitrate: %d", baudbits); if( cfsetospeed(tio, baudbits) != 0 ) post("[comport]: ERROR failed to set bitrate: %d", baudbits); return baud; } /* bits are 5,6,7,8(default) */ static float set_bits(t_comport *x, int nr) { struct termios *tio = &(x->com_termio); tio->c_cflag &= ~CSIZE; switch(nr) { case 5: tio->c_cflag |= CS5; return 5; case 6: tio->c_cflag |= CS6; return 6; case 7: tio->c_cflag |= CS7; return 7; default: tio->c_cflag |= CS8; } return 8; } /* 1 ... Parity even, -1 parity odd , 0 (default) no parity */ static float set_parity(t_comport *x,int n) { struct termios *tio = &(x->com_termio); switch(n) { case 1: tio->c_cflag |= PARENB; tio->c_cflag &= ~PARODD; return 1; case -1: tio->c_cflag |= PARENB | PARODD; return -1; default: tio->c_cflag &= ~PARENB; } return 0; } /* activate second stop bit with 1, 0(default)*/ static float set_stopflag(t_comport *x, t_float f_nr) { int nr = (int)f_nr; struct termios *tio = &(x->com_termio); if(nr == 1) { tio->c_cflag |= CSTOPB; return 1; } else tio->c_cflag &= ~CSTOPB; return 0; } /* never tested */ static int set_ctsrts(t_comport *x, int nr) { struct termios *tio = &(x->com_termio); if(nr == 1) { tio->c_cflag |= CRTSCTS; return 1; } tio->c_cflag &= ~CRTSCTS; return 0; } static int set_dtr(t_comport *x, int nr) { int fd = x->comhandle; int status; if (fd == INVALID_HANDLE_VALUE) return -1; ioctl(fd, TIOCMGET, &status); if (nr == 0) status &= ~TIOCM_DTR; else status |= TIOCM_DTR; ioctl(fd, TIOCMSET, &status); return (nr !=0); } static int set_rts(t_comport *x, int nr) { int fd = x->comhandle; int status; if (fd == INVALID_HANDLE_VALUE) return -1; ioctl(fd, TIOCMGET, &status); if (nr == 0) status &= ~TIOCM_RTS; else status |= TIOCM_RTS; ioctl(fd, TIOCMSET, &status); return (nr !=0); } static int set_xonxoff(t_comport *x, int nr) { struct termios *tio = &(x->com_termio); if(nr == 1) { tio->c_iflag |= (IXON | IXOFF | IXANY); return 1; } tio->c_iflag &= ~IXON & ~IXOFF & ~IXANY; return 0; } static int set_hupcl(t_comport *x, int nr) { struct termios settings; int result; result = tcgetattr(x->comhandle, &settings); if (result < 0) { perror ("error in tcgetattr"); return 0; } settings.c_iflag &= ~HUPCL; if(nr) settings.c_iflag |= HUPCL; result = tcsetattr(x->comhandle, TCSANOW, &settings); if (result < 0) { pd_error(x,"[comport] could not set HUPCL"); return 0; } x->hupcl = nr; return 1; } static int open_serial(unsigned int com_num, t_comport *x) { int fd; unsigned int i; struct termios *old = &(x->oldcom_termio); struct termios *new = &(x->com_termio); float *baud = &(x->baud); glob_t glob_buffer; /* if com_num == USE_DEVICENAME, use device name directly, else try port # */ if((com_num != USE_DEVICENAME)&&(com_num >= COMPORT_MAX)) { post("[comport] ** WARNING ** port %d not valid, must be between 0 and %d", com_num, COMPORT_MAX - 1); return INVALID_HANDLE_VALUE; } /* post("[comport] globbing %s",x->serial_device_prefix);*/ /* get the device path based on the port# and the glob pattern */ switch( glob( x->serial_device_prefix, 0, NULL, &glob_buffer ) ) { case GLOB_NOSPACE: pd_error(x,"[comport] out of memory for \"%s\"",x->serial_device_prefix); break; #ifdef GLOB_ABORTED case GLOB_ABORTED: pd_error(x,"[comport] aborted \"%s\"",x->serial_device_prefix); break; #endif #ifdef GLOB_NOMATCH case GLOB_NOMATCH: pd_error(x,"[comport] no serial devices found for \"%s\"", x->serial_device_prefix); break; #endif } if (com_num == USE_DEVICENAME) { /* if possible, find the index of the devicename */ for (i = 0; i < glob_buffer.gl_pathc; ++i) { if (0 == strcmp(x->serial_device->s_name, glob_buffer.gl_pathv[i])) { com_num = i; break; } } } else if(com_num < glob_buffer.gl_pathc) x->serial_device = gensym(glob_buffer.gl_pathv[com_num]); else { post("[comport] ** WARNING ** port #%d does not exist! (max == %d)", com_num,glob_buffer.gl_pathc - 1); return INVALID_HANDLE_VALUE; } globfree( &(glob_buffer) ); if((fd = open(x->serial_device->s_name, OPENPARAMS)) == INVALID_HANDLE_VALUE) { pd_error(x, "[comport] ** ERROR ** could not open device %s:\n failure(%d): %s\n", x->serial_device->s_name,errno,strerror(errno)); return INVALID_HANDLE_VALUE; } /* set no wait on any operation */ fcntl(fd, F_SETFL, FNDELAY); /* Save the Current Port Configuration */ if(tcgetattr(fd, old) == -1 || tcgetattr(fd, new) == -1) { pd_error(x,"[comport] ** ERROR ** could not get termios-structure of device %s\n", x->serial_device->s_name); close(fd); return INVALID_HANDLE_VALUE; } /* Setup the new port configuration...NON-CANONICAL INPUT MODE .. as defined in termios.h */ /* enable input and ignore modem controls */ new->c_cflag |= (CREAD | CLOCAL); /* always nocanonical, this means raw i/o no terminal */ new->c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* no post processing */ new->c_oflag &= ~OPOST; /* setup to return after 0 seconds ..if no characters are received TIME units are assumed to be 0.1 secs */ /* not needed anymore ??? in new termios in linux new->c_cc[VMIN] = 0; new->c_cc[VTIME] = 0; */ /* defaults, see input */ set_bits(x, x->data_bits); /* CS8 */ set_stopflag(x, x->stop_bits); /* ~CSTOPB */ set_ctsrts(x, x->ctsrts); /* ~CRTSCTS;*/ set_xonxoff(x, x->xonxoff); /* (IXON | IXOFF | IXANY) */ set_baudrate(x, *baud); x->x_retry_count = 0; /* reset retry counter */ if(tcsetattr(fd, TCSAFLUSH, new) != -1) { post("[comport] opened serial line device %d (%s)\n", com_num,x->serial_device->s_name); } else { pd_error(x,"[comport] ** ERROR ** could not set params to ioctl of device %s\n", x->serial_device->s_name); close(fd); return INVALID_HANDLE_VALUE; } x->comport = com_num; /* output at next comport_tick */ return fd; } static int close_serial(t_comport *x) { struct termios *tios = &(x->com_termio); HANDLE fd = x->comhandle; if(fd != INVALID_HANDLE_VALUE) { tcsetattr(fd, TCSANOW, tios); close(fd); post("[comport] closed port %i (%s)", x->comport, x->serial_device->s_name); } return INVALID_HANDLE_VALUE; } static int set_serial(t_comport *x) { if(tcsetattr(x->comhandle, TCSAFLUSH, &(x->com_termio)) == -1) return 0; return 1; } static int comport_get_dsr(t_comport *x) { short dsr_state = 0; if (x->comhandle != INVALID_HANDLE_VALUE) { int status;/*dsr outlet*/ /* get the DSR input state and if it's changed, output it */ ioctl(x->comhandle, TIOCMGET, &status);/*dsr outlet*/ dsr_state = ((status&TIOCM_LE)!=0);/* read the DSR input line */ } return dsr_state; } int comport_get_cts(t_comport *x) { short cts_state = 0; if (x->comhandle != INVALID_HANDLE_VALUE) { int status;/*cts outlet*/ /* get the CTS input state and if it's changed, output it */ ioctl(x->comhandle, TIOCMGET, &status); cts_state = ((status&TIOCM_CTS)!=0);/* read the CTS input line */ } return cts_state; } #endif /* else NT */ /* ------------------- serial pd methods --------------------------- */ static void comport_pollintervall(t_comport *x, t_floatarg g) { if (g < 1) g = 1; x->x_deltime = g; } static void comport_retries(t_comport *x, t_floatarg g) { if (g < 0) g = 0; x->x_retries = g; } static void comport_tick(t_comport *x) { #ifdef _WIN32 HANDLE fd = x->comhandle; #else int fd = x->comhandle; #endif /* _WIN32 */ int err; x->x_hit = 0; if(fd != INVALID_HANDLE_VALUE) { /* while there are bytes, read them and send them out, ignore errors (!??) */ #ifdef _WIN32 DWORD dwRead; OVERLAPPED osReader; DWORD dwX; DWORD whicherr = 0; err = 0; /* initialize all fields off osReader to zero to avoid gcc warnings about */ /* missing initializer if we just do osReader ={0} */ osReader.hEvent = 0; osReader.Internal = 0; osReader.InternalHigh = 0; osReader.Offset = 0; osReader.OffsetHigh = 0; /*osReader.Pointer = 0; seems MinGW doesn't knoow about this one */ osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if(ReadFile(x->comhandle, x->x_inbuf, x->x_inbuf_len, &dwRead, &osReader)) { if(dwRead > 0) { for(dwX = 0; dwX < dwRead ;dwX++) { outlet_float(x->x_data_outlet, (t_float) x->x_inbuf[dwX]); } } } else { err = -1; whicherr = GetLastError(); } CloseHandle(osReader.hEvent); #else fd_set com_rfds; int count = 0; int i; int whicherr = 0; FD_ZERO(&com_rfds); FD_SET(fd,&com_rfds); while((err = select(fd+1, &com_rfds, NULL, NULL, &null_tv)) > 0) { ioctl(fd, FIONREAD, &count); /* load count with the number of bytes in the receive buffer... */ if (count > x->x_inbuf_len) count = x->x_inbuf_len; /* ...but no more than the buffer can hold */ /*err = read(fd,(char *) &serial_byte,1);*/ err = read(fd,(char *)x->x_inbuf, count);/* try to read count bytes */ if (err > 0) { for (i = 0; i < err; ++i ) { outlet_float(x->x_data_outlet, (t_float) x->x_inbuf[i]); } } else if (err == 0 && count == 0) { /* if both ioctl() and read() return a 0 count, assume * that we lost the connection to the serial port. * otherwise there is a race condition when the serial * port gets interrupted, like if the USB gets yanked * out or a bluetooth connection drops */ if(x->x_retry_count < x->x_retries) { t_atom retrying_atom; SETFLOAT(&retrying_atom, x->x_retry_count); outlet_anything(x->x_status_outlet, gensym("retrying"), 1, &retrying_atom); pd_error(x, "[comport]: lost connection to port %i (%s), retrying...", x->comport, x->serial_device->s_name); if (!x->x_hit) clock_delay(x->x_clock, 1000); /* retry every second */ x->x_retry_count++; return; } else { pd_error(x, "[comport]: Giving up on port %i (%s)!", x->comport, x->serial_device->s_name); comport_close(x); } } else whicherr = errno; } #endif /* _WIN32 */ if(err < 0) { /* if a read error detected */ if(x->rxerrors < 10) /* ten times max */ post("[comport]: RXERRORS on serial line (%d)\n", whicherr); x->rxerrors++; /* remember */ } /* now if anything to send, send the output buffer */ if (0 != x->x_outbuf_wr_index) { #ifdef _WIN32 OVERLAPPED osWrite; DWORD dwWritten; DWORD dwToWrite = (DWORD)x->x_outbuf_wr_index; DWORD dwErr; DWORD numTransferred = 0L; /* initialize all fields off osWrite to zero to avoid gcc warnings about */ /* missing initializer if we just do osWrite ={0} */ osWrite.hEvent = 0; osWrite.Internal = 0; osWrite.InternalHigh = 0; osWrite.Offset = 0; osWrite.OffsetHigh = 0; /*osWrite.Pointer = 0; seems MinGW doesn't know about this one */ osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (osWrite.hEvent == NULL) { post("[comport]: Couldn't create event. Transmission aborted."); goto endsendevent; } else if (!WriteFile(x->comhandle, x->x_outbuf, dwToWrite, &dwWritten, &osWrite)) { dwErr = GetLastError(); if (dwErr != ERROR_IO_PENDING) { post("[comport]: WriteFile error: %d", (int)dwErr); goto endsendevent; } } if (!GetOverlappedResult(x->comhandle, &osWrite, &numTransferred, TRUE)) {/* wait for the character(s) to be sent */ dwErr = GetLastError(); post("[comport]: WriteFile:GetOverlappedResult error: %d", (int)dwErr); } endsendevent: CloseHandle(osWrite.hEvent); #else err = write(x->comhandle,(char *)x->x_outbuf, x->x_outbuf_wr_index); if (err != x->x_outbuf_wr_index) { pd_error(x,"[comport]: Write failed for %d bytes, error is %d",err,errno); } #endif /*_WIN32*/ x->x_outbuf_wr_index = 0; /* for now we just drop anything that didn't send */ } if (!x->x_hit) clock_delay(x->x_clock, x->x_deltime); /* default 10 ms */ } } static int write_serial(t_comport *x, unsigned char serial_byte) { if(x->comhandle == INVALID_HANDLE_VALUE) { post ("[comport]: Serial port is not open"); return 0; } else if(x->x_outbuf_wr_index < x->x_outbuf_len) { x->x_outbuf[x->x_outbuf_wr_index++] = serial_byte; return 1; } /* handle overrun error */ post ("[comport]: buffer is full"); return 0; } static int write_serials(t_comport *x, unsigned char *serial_buf, int buf_length) { int i; if(x->comhandle == INVALID_HANDLE_VALUE) { post ("[comport]: Serial port is not open"); return 0; } for (i = 0; ((i < buf_length) && (x->x_outbuf_wr_index < x->x_outbuf_len)); ++x->x_outbuf_wr_index, ++i) x->x_outbuf[x->x_outbuf_wr_index] = serial_buf[i]; if (i != buf_length) post ("[comport]: buffer is full"); return i; } static void comport_float(t_comport *x, t_float f) { unsigned char serial_byte = ((int) f) & 0xFF; /* brutal conv */ if (write_serial(x,serial_byte) != 1) { post("Write error, maybe TX-OVERRUNS on serial line"); } } static void comport_list(t_comport *x, t_symbol *s, int argc, t_atom *argv) { unsigned char temp_array[COMPORT_BUF_SIZE];/* arbitrary maximum list length */ int i, count; int result; count = argc; if (argc > COMPORT_BUF_SIZE) { post ("[comport] truncated list of %d elements to %d", argc, count); count = COMPORT_BUF_SIZE; } for(i = 0; i < count; i++) temp_array[i] = ((unsigned char)atom_getint(argv+i))&0xFF; /* brutal conv */ result = write_serials(x, temp_array, count); } static void *comport_new(t_symbol *s, int argc, t_atom *argv) { t_comport test; t_comport *x; HANDLE fd; const char *serial_device_prefix; t_float com_num = 0; t_float fbaud = 9600; #ifdef _WIN32 /* According to http://msdn2.microsoft.com/en-us/library/aa363858.aspx To specify a COM port number greater than 9, use the following syntax: "\\\\.\\COM10". This syntax works for all port numbers and hardware that allows COM port numbers to be specified. */ serial_device_prefix = "\\\\.\\COM"; #endif /* _WIN32 */ /* for UNIX, this is a glob pattern for matching devices */ #ifdef __APPLE__ serial_device_prefix = "/dev/tty.*"; #endif /* __APPLE__ */ #ifdef IRIX serial_device_prefix = "/dev/ttyd*"; #endif /* IRIX */ #ifdef __linux__ /* serial: ttyS? USB-serial: ttyUSB? USB-CDC: ttyACM? */ serial_device_prefix = "/dev/tty[ASU]*"; #endif /* __linux__ */ if(argc > 0 && argv->a_type == A_FLOAT) com_num = atom_getfloatarg(0,argc,argv); if(argc > 1) fbaud = atom_getfloatarg(1,argc,argv); /* Open the Comport for RD and WR and get a handle */ /* this line should use a real serial device */ strncpy(test.serial_device_prefix, serial_device_prefix, strlen(serial_device_prefix)+1); test.baud = fbaud; test.data_bits = 8; /* default 8 data bits */ test.parity_bit = 0;/* default no parity bit */ #ifdef _WIN32 test.stop_bits = 1;/* default 1 stop bit */ #else test.stop_bits = 0;/* default 1 stop bit */ #endif /* _WIN32 */ test.ctsrts = 0; /* default no hardware handshaking */ test.xonxoff = 0; /* default no software handshaking */ test.hupcl = 1; /* default hangup on close */ fd = open_serial((unsigned int)com_num, &test); /* Now nothing really bad could happen so we create the class */ x = (t_comport *)pd_new(comport_class); x->comport = test.comport;/* com_num */ strncpy(x->serial_device_prefix,serial_device_prefix,strlen(serial_device_prefix)+1); x->serial_device = test.serial_device; /* we need this so 'help' doesn't crash */ x->baud = test.baud; x->data_bits = test.data_bits; x->parity_bit = test.parity_bit; x->stop_bits = test.stop_bits; x->ctsrts = test.ctsrts; x->xonxoff = test.xonxoff; x->hupcl = test.hupcl; x->comhandle = fd; /* holds the comport handle */ if(fd == INVALID_HANDLE_VALUE ) { pd_error(x, "[comport] opening serial port %g failed!", com_num); } else { #ifdef _WIN32 memcpy(&(x->dcb_old), &(test.dcb_old), sizeof(DCB)); /* save the old com config */ memcpy(&(x->dcb), &(test.dcb), sizeof(DCB)); /* for the new com config */ #else /* save the old com and new com config */ bcopy(&(test.oldcom_termio),&(x->oldcom_termio),sizeof(struct termios)); bcopy(&(test.com_termio),&(x->com_termio),sizeof(struct termios)); #endif } /* allocate memory for in and out buffers */ x->x_inbuf = getbytes(COMPORT_BUF_SIZE); if (NULL == x->x_inbuf) { pd_error(x, "[comport] unable to allocate input buffer"); return 0; } x->x_inbuf_len = COMPORT_BUF_SIZE; x->x_outbuf = getbytes(COMPORT_BUF_SIZE); if (NULL == x->x_outbuf) { pd_error(x, "[comport] unable to allocate output buffer"); return 0; } x->x_outbuf_len = COMPORT_BUF_SIZE; x->x_outbuf_wr_index = 0; x->rxerrors = 0; /* holds the rx line errors */ x->x_data_outlet = outlet_new(&x->x_obj, &s_float); x->x_status_outlet = outlet_new(&x->x_obj, &s_float); x->x_hit = 0; /* Since 10ms is also the default poll time for most HID devices, * and it seems that for most uses of [comport] (i.e. arduinos and * other serial ports 115200 baud or less) that 10ms polling is * going to give the data as fast as 1ms polling with a lot less * CPU time wasted. */ x->x_deltime = 10; x->x_retries = 10; x->x_clock = clock_new(x, (t_method)comport_tick); clock_delay(x->x_clock, x->x_deltime); x->verbose = 0; return x; } static void comport_free(t_comport *x) { post("[comport] free serial..."); clock_unset(x->x_clock); clock_free(x->x_clock); x->comhandle = close_serial(x); freebytes(x->x_inbuf, x->x_inbuf_len); freebytes(x->x_outbuf, x->x_outbuf_len); } /* ---------------- use serial settings ------------- */ static void comport_baud(t_comport *x,t_floatarg f) { if(f == x->baud) { post("baudrate already %g\n",x->baud); return; } x->baud = set_baudrate(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(set_serial(x) == 0) { pd_error(x,"[comport] ** ERROR ** could not set baudrate of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif } else if(x->verbose > 0) post("set baudrate of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], x->baud); #else x->serial_device->s_name, x->baud); #endif } static void comport_bits(t_comport *x,t_floatarg f) { f = set_bits(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(set_serial(x) == 0) { pd_error(x,"[comport] ** ERROR ** could not set bits of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif return; } else if(x->verbose > 0) post("set bits of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], f); #else x->serial_device->s_name, f); #endif x->data_bits = f; } static void comport_parity(t_comport *x,t_floatarg f) { f = set_parity(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(set_serial(x) == 0) { pd_error(x,"[comport] ** ERROR ** could not set extra paritybit of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif return; } else if(x->verbose > 0) post("[comport] set extra paritybit of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], f); #else x->serial_device->s_name, f); #endif x->parity_bit = f; } static void comport_stopbit(t_comport *x, t_floatarg f) { f = set_stopflag(x, f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(set_serial(x) == 0) { #ifdef _WIN32 pd_error(,"[comport] ** ERROR ** could not set stopbits of device %s to %g\n", &x->serial_device->s_name[4], f); #else pd_error(x,"[comport] ** ERROR ** could not set extra stopbit of device %s\n", x->serial_device->s_name); #endif return; } else if(x->verbose > 0) #ifdef _WIN32 post("[comport] set stopbits of %s to %g\n", &x->serial_device->s_name[4], f); #else post("[comport] set extra stopbit of %s to %g\n", x->serial_device->s_name, f); #endif x->stop_bits = f; } static void comport_rtscts(t_comport *x,t_floatarg f) { f = set_ctsrts(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(set_serial(x) == 0) { pd_error(x,"[comport] ** ERROR ** could not set rts_cts of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif return; } else if(x->verbose > 0) post("[comport] set rts-cts of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], f); #else x->serial_device->s_name, f); #endif x->ctsrts = f; } static void comport_dtr(t_comport *x,t_floatarg f) { f = set_dtr(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(f < 0) { pd_error(x,"[comport] ** ERROR ** could not set dtr of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif } else if(x->verbose > 0) post("[comport] set dtr of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], f); #else x->serial_device->s_name, f); #endif } static void comport_rts(t_comport *x,t_floatarg f) { f = set_rts(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(f < 0) { pd_error(x,"[comport] ** ERROR ** could not set rts of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif } else if(x->verbose > 0) post("[comport] set rts of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], f); #else x->serial_device->s_name, f); #endif } static void comport_xonxoff(t_comport *x,t_floatarg f) { f = set_xonxoff(x,f); if(x->comhandle == INVALID_HANDLE_VALUE)return; if(set_serial(x) == 0) { pd_error(x,"[comport] ** ERROR ** could not set xonxoff of device %s\n", #ifdef _WIN32 &x->serial_device->s_name[4]); #else x->serial_device->s_name); #endif return; } else if(x->verbose > 0) post("[comport] set xonxoff of %s to %g\n", #ifdef _WIN32 &x->serial_device->s_name[4], f); #else x->serial_device->s_name, f); #endif x->xonxoff = f; } static void comport_hupcl(t_comport *x,t_floatarg f) { #ifndef _WIN32 set_hupcl(x,f); #endif } static void comport_close(t_comport *x) { clock_unset(x->x_clock); x->x_hit = 1; x->comhandle = close_serial(x); x->comport = -1; /* none */ if (x->x_status_outlet != NULL) outlet_float(x->x_status_outlet, (float)x->comport); } static void comport_open(t_comport *x, t_floatarg f) { if(x->comhandle != INVALID_HANDLE_VALUE) comport_close(x); x->comhandle = open_serial(f,x); clock_delay(x->x_clock, x->x_deltime); } /* dangerous but if you really have some stupid devicename ... you can open any file on systems if suid is set on pd be careful */ static void comport_devicename(t_comport *x, t_symbol *s) { x->serial_device = s; if(x->comhandle != INVALID_HANDLE_VALUE) comport_close(x); x->comhandle = open_serial(USE_DEVICENAME,x); clock_delay(x->x_clock, x->x_deltime); } static void comport_print(t_comport *x, t_symbol *s, int argc, t_atom *argv) { static char buf[256]; char *pch = buf; while(argc--) { atom_string(argv++, buf, 255); while(*pch != 0) { write_serial(x, *pch++); } if(argc > 0) { write_serial(x, ' '); } } } static void comport_enum(t_comport *x) { #ifdef _WIN32 HANDLE fd; char device_name[10]; unsigned int i; DWORD dw; for(i = 1; i < COMPORT_MAX; i++) { #ifdef _MSC_VER sprintf_s(device_name, 10, "%s%d", x->serial_device_prefix, i); #else sprintf(device_name, "%s%d", x->serial_device_prefix, i); #endif fd = CreateFileA( device_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); dw = 0L; if(fd == INVALID_HANDLE_VALUE) dw = GetLastError(); else CloseHandle(fd); if (dw == 0)post("\t%d - COM%d (free)", i, i); else if (dw == ERROR_ACCESS_DENIED)post("\t%d - COM%d (in use)", i, i); } #else unsigned int i; glob_t glob_buffer; int fd; struct termios test; /* first look for registered devices in the filesystem */ switch( glob( x->serial_device_prefix, 0, NULL, &glob_buffer ) ) { case GLOB_NOSPACE: pd_error(x,"[comport] out of memory for \"%s\"",x->serial_device_prefix); break; # ifdef GLOB_ABORTED case GLOB_ABORTED: pd_error(x,"[comport] aborted \"%s\"",x->serial_device_prefix); break; # endif /* GLOB_ABORTED */ # ifdef GLOB_NOMATCH case GLOB_NOMATCH: pd_error(x,"[comport] no serial devices found for \"%s\"",x->serial_device_prefix); break; # endif /* GLOB_NOMATCH */ } for(i=0; iserial_device_prefix, i); #else sprintf(device_name, "%s%d", x->serial_device_prefix, i); #endif fd = CreateFileA( device_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); dw = 0L; if(fd == INVALID_HANDLE_VALUE) dw = GetLastError(); else CloseHandle(fd); if ((dw == 0)||(dw == ERROR_ACCESS_DENIED)) { /* output index and name as a list */ SETFLOAT(&output_atom[0], i); SETSYMBOL(&output_atom[1], gensym(&device_name[4]));/* strip the slashes and dot */ outlet_anything( x->x_status_outlet, gensym("ports"), 2, output_atom); } } #else glob_t glob_buffer; int fd; struct termios test; /* first look for registered devices in the filesystem */ switch( glob( x->serial_device_prefix, 0, NULL, &glob_buffer ) ) { case GLOB_NOSPACE: pd_error(x,"[comport] out of memory for \"%s\"",x->serial_device_prefix); break; # ifdef GLOB_ABORTED case GLOB_ABORTED: pd_error(x,"[comport] aborted \"%s\"",x->serial_device_prefix); break; # endif /* GLOB_ABORTED */ # ifdef GLOB_NOMATCH case GLOB_NOMATCH: pd_error(x,"[comport] no serial devices found for \"%s\"",x->serial_device_prefix); break; # endif /* GLOB_NOMATCH */ } for(i = 0; (i < glob_buffer.gl_pathc) && (j < COMPORT_MAX); i++) { /* now try to open the device */ if((fd = open(glob_buffer.gl_pathv[i], OPENPARAMS)) != INVALID_HANDLE_VALUE) { /* now see if it has attributes */ if ((tcgetattr(fd, &test)) != -1) { /* output index and name as a list */ SETFLOAT(&output_atom[0], i); SETSYMBOL(&output_atom[1], gensym(glob_buffer.gl_pathv[i])); outlet_anything( x->x_status_outlet, gensym("ports"), 2, output_atom); } close (fd); } } #endif /* _WIN32 */ } static void comport_output_print(t_comport *x) { post("[comport]: available serial ports:"); comport_enum(x); } static void comport_output_status(t_comport *x, t_symbol *selector, t_float output_value) { t_atom *output_atom = getbytes(sizeof(t_atom)); SETFLOAT(output_atom, output_value); outlet_anything( x->x_status_outlet, selector, 1, output_atom); freebytes(output_atom,sizeof(t_atom)); } static void comport_output_port_status(t_comport *x) { comport_output_status(x, gensym("port"), (float)x->comport); } static void comport_output_dsr_status(t_comport *x) { comport_output_status(x, gensym("dsr"), (float)comport_get_dsr(x)); } static void comport_output_cts_status(t_comport *x) { comport_output_status(x, gensym("cts"), (float)comport_get_cts(x)); } static void comport_output_baud_rate(t_comport *x) { comport_output_status(x, gensym("baud"), x->baud); } static void comport_output_parity_bit(t_comport *x) { comport_output_status(x, gensym("parity"), x->parity_bit); } static void comport_output_stop_bits(t_comport *x) { #ifdef _WIN32 comport_output_status(x, gensym("stop"), x->stop_bits); #else comport_output_status(x, gensym("stop"), x->stop_bits+1); #endif } static void comport_output_data_bits(t_comport *x) { comport_output_status(x, gensym("data"), x->data_bits); } static void comport_output_rtscts(t_comport *x) { comport_output_status(x, gensym("rtscts"), x->ctsrts); } static void comport_output_xonxoff(t_comport *x) { comport_output_status(x, gensym("xonxoff"), x->xonxoff); } static void comport_output_hupcl(t_comport *x) { comport_output_status(x, gensym("hupcl"), x->hupcl); } static void comport_output_rxerrors(t_comport *x) { comport_output_status(x, gensym("rxerrors"), x->rxerrors); } static void comport_output_open_status(t_comport *x) { if(x->comhandle == INVALID_HANDLE_VALUE) comport_output_status(x, gensym("open"), 0); else comport_output_status(x, gensym("open"), 1); } static void comport_devices(t_comport *x) { comport_output_print(x); } static void comport_info(t_comport *x) { comport_output_open_status(x); comport_output_port_status(x); comport_output_baud_rate(x); comport_output_dsr_status(x); comport_output_cts_status(x); comport_output_parity_bit(x); comport_output_stop_bits(x); comport_output_data_bits(x); comport_output_rtscts(x); comport_output_xonxoff(x); comport_output_hupcl(x); comport_output_rxerrors(x); } /* ---------------- HELPER ------------------------- */ static void comport_verbose(t_comport *x, t_floatarg f) { x->verbose = f; if(f > 0) post("[comport] verbose is on: %d", (int) f); } static void comport_help(t_comport *x) { post("[comport] serial port %d (baud %g):", x->comport, x->baud); if(x->comport >= 0 && x->comport < COMPORT_MAX) { #ifdef WIN32 post("\tdevicename: %s", &x->serial_device->s_name[4]); #else post("\tdevicename: %s", x->serial_device->s_name); #endif } post(" Methods:"); post(" baud ... set baudrate to nearest possible baud\n" " bits ... set number of bits (7 or 8)\n" " stopbit <0|1> ... set off|on stopbit\n" " rtscts <0|1> ... set rts/cts off|on\n" " parity <0|1> ... set parity off|on\n" " xonxoff <0|1> ... set xon/xoff off|on\n" " dtr <0|1> ... set dtr off|on\n" " rts <0|1> ... set rts off|on\n" " hupcl <0|1> ... set hang-up on close off|on\n" " close ... close device\n" " open ... open device number num\n" " devicename ... set device name to d (eg. /dev/ttyS8)\n" " print ... print list of atoms on serial\n" " pollintervall ... set poll interval to t ticks\n" " verbose ... for debug set verbosity to level\n" " info ... output info on status outlet\n" " devices ... post list of available devices\n" " ports ... output list of available devices on status outlet\n" " help ... post this help"); } /* ---------------- SETUP OBJECTS ------------------ */ void comport_setup(void) { comport_class = class_new(gensym("comport"), (t_newmethod)comport_new, (t_method)comport_free, sizeof(t_comport), 0, A_GIMME, 0); class_addfloat(comport_class, (t_method)comport_float); class_addlist(comport_class, (t_method)comport_list); /* class_addbang(comport_class, comport_bang */ class_addmethod(comport_class, (t_method)comport_baud, gensym("baud"),A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_bits, gensym("bits"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_stopbit, gensym("stopbit"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_rtscts, gensym("rtscts"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_dtr, gensym("dtr"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_rts, gensym("rts"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_parity, gensym("parity"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_xonxoff, gensym("xonxoff"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_hupcl, gensym("hupcl"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_close, gensym("close"), 0); class_addmethod(comport_class, (t_method)comport_open, gensym("open"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_devicename, gensym("devicename"), A_SYMBOL, 0); class_addmethod(comport_class, (t_method)comport_print, gensym("print"), A_GIMME, 0); class_addmethod(comport_class, (t_method)comport_pollintervall, gensym("pollintervall"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_retries, gensym("retries"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_verbose, gensym("verbose"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_help, gensym("help"), 0); class_addmethod(comport_class, (t_method)comport_info, gensym("info"), 0); class_addmethod(comport_class, (t_method)comport_devices, gensym("devices"), 0); class_addmethod(comport_class, (t_method)comport_ports, gensym("ports"), 0); #ifndef _WIN32 null_tv.tv_sec = 0; /* no wait */ null_tv.tv_usec = 0; #endif /* NOT _WIN32 */ verbose(-1, "comport - PD external for unix/windows\n" "LGPL 1998-2012, Winfried Ritsch and others (see LICENSE.txt)\n" "Institute for Electronic Music - Graz"); } comport-0.2/comport.dsp0000644000076500007650000000474511213510251013710 0ustar hanshans# Microsoft Developer Studio Project File - Name="comport" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** NICHT BEARBEITEN ** # TARGTYPE "Win32 (x86) External Target" 0x0106 CFG=comport - Win32 Debug !MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE !MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl !MESSAGE !MESSAGE NMAKE /f "comport.mak". !MESSAGE !MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben !MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: !MESSAGE !MESSAGE NMAKE /f "comport.mak" CFG="comport - Win32 Debug" !MESSAGE !MESSAGE Für die Konfiguration stehen zur Auswahl: !MESSAGE !MESSAGE "comport - Win32 Release" (basierend auf "Win32 (x86) External Target") !MESSAGE "comport - Win32 Debug" (basierend auf "Win32 (x86) External Target") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" !IF "$(CFG)" == "comport - Win32 Release" # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Cmd_Line "NMAKE /f makefile_win" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "makefile_win.exe" # PROP BASE Bsc_Name "makefile_win.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Cmd_Line "NMAKE /f makefile_win" # PROP Rebuild_Opt "/a" # PROP Target_File "comport.exe" # PROP Bsc_Name "comport.bsc" # PROP Target_Dir "" !ELSEIF "$(CFG)" == "comport - Win32 Debug" # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Cmd_Line "NMAKE /f makefile_win" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "makefile_win.exe" # PROP BASE Bsc_Name "makefile_win.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Cmd_Line "NMAKE /f makefile_win" # PROP Rebuild_Opt "/a" # PROP Target_File "comport.exe" # PROP Bsc_Name "comport.bsc" # PROP Target_Dir "" !ENDIF # Begin Target # Name "comport - Win32 Release" # Name "comport - Win32 Debug" !IF "$(CFG)" == "comport - Win32 Release" !ELSEIF "$(CFG)" == "comport - Win32 Debug" !ENDIF # Begin Source File SOURCE=.\makefile_win # End Source File # End Target # End Project comport-0.2/comport.dsw0000644000076500007650000000106511213510251013707 0ustar hanshansMicrosoft Developer Studio Workspace File, Format Version 6.00 # WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! ############################################################################### Project: "comport"=.\comport.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### comport-0.2/makefile_win0000644000076500007650000000161711213510251014065 0ustar hanshans all: comport.dll VIS_CPP_PATH = "C:\Programme\Microsoft Visual Studio\Vc98" PD_INST_PATH = "C:\Programme\pd" PD_WIN_INCLUDE_PATH = /I. /I$(PD_INST_PATH)\src /I$(VIS_CPP_PATH)\include PD_WIN_C_FLAGS = /nologo /W3 /WX /DMSW /DNT /DPD /DWIN32 /DWINDOWS /Ox -DPA_LITTLE_ENDIAN PD_WIN_L_FLAGS = /nologo PD_WIN_LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel /NODEFAULTLIB:uuid \ $(VIS_CPP_PATH)\lib\libc.lib \ $(VIS_CPP_PATH)\lib\oldnames.lib \ $(VIS_CPP_PATH)\lib\kernel32.lib \ $(VIS_CPP_PATH)\lib\wsock32.lib \ $(VIS_CPP_PATH)\lib\winmm.lib \ $(PD_INST_PATH)\bin\pthreadVC.lib \ $(PD_INST_PATH)\bin\pd.lib SRC = comport.c OBJ = $(SRC:.c=.obj) .c.obj: cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c comport.dll: $(OBJ) link $(PD_WIN_L_FLAGS) /dll /export:comport_setup \ /out:comport.dll $(OBJ) $(PD_WIN_LIB) clean: del *.obj