diff --git a/dserial-cli/.gitignore b/dserial-cli/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..745854e55727b0acbe71378be479008f2375731f
--- /dev/null
+++ b/dserial-cli/.gitignore
@@ -0,0 +1,2 @@
+build
+.vala-aux
diff --git a/dserial-cli/LICENSE b/dserial-cli/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..94a9ed024d3859793618152ea559a168bbcbb5e2
--- /dev/null
+++ b/dserial-cli/LICENSE
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, 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
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If 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 convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU 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
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/dserial-cli/Makefile b/dserial-cli/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..bf472c1723b49a460bf6bfd59aa2bb5c6d100e90
--- /dev/null
+++ b/dserial-cli/Makefile
@@ -0,0 +1,194 @@
+# --------------------------------------------------
+# Vala Makefile
+# --------------------------------------------------
+#
+# This Makefile provides a starting point for building
+# and testing Vala projects on Linux.
+#
+# There are two types of projects supported: executable
+# and shared library. Basic installation/uninstallation
+# support is provided as well.
+#
+# To build your project, first fill in some details below.
+# At a minimum you need to specify a name for your
+# project's target (the executable or library to be
+# produced). You may also configure what packages are
+# used to build it, how the files in your project's
+# root are organized, and of course, whether it is an
+# executable or library.
+#
+# There are three important subdirectories that this
+# Makefile uses. The names of these can be configured
+# further down, if you so desire.
+#
+# 	src/
+# 		all *.vala source files. The `find' command
+# 		is used to locate them, so feel free to create
+# 		as many subdirectories here as you wish
+#
+# 	data/
+# 		any additional data files for your project. When
+# 		installed, the contents of this folder are copied
+# 		directly to $(PREFIX)/share, so you should make
+# 		sure that the contents mirror where you want them
+# 		to be installed. For example, to create a launcher
+# 		for your program, you could put the .desktop file
+# 		in data/applications so that it would be installed
+# 		to $(PREFIX)/share/applications.
+# 		NOTE: this directory is only used for executable
+# 		projects, and is set to read-only as long as the
+# 		project is installed. To regain write access, you
+# 		must first uninstall your project from the
+# 		filesystem.
+#
+#	build/
+#		where compiled results are placed, including
+#		intermediate .c and .o files as well as the final
+#		executable or library
+#
+# To build your project, make sure your desired source
+# files are placed in src/, then run make.
+#
+# The following targets are supported:
+#
+#  	all/target: compiles the source and generates the
+#		final result in build/ (default)
+#  	compile: compiles vala down to its C source, but
+#  		doesn't generate the final result
+#  	clean: cleans all compilation results for a fresh build
+#  	install: installs this program/library
+#  	uninstall: uninstalls this program/library
+# 
+# To install the project, run `make install' with root
+# privileges. The default prefix is /usr/local, which can
+# be changed by specifying a new PREFIX variable on the
+# command-line, e.g. `make install PREFIX=/usr'. Likewise,
+# it can be uninstalled using `make uninstall` as root,
+# using the same PREFIX variable as when it was installed.
+#
+# WHAT THIS MAKEFILE DOES NOT DO:
+#
+# - dependency/version checking
+# - program configuration prior to running make
+# - internationalization
+# - anything besides compile vala and cp/rm files
+#
+# Enjoy.
+#
+
+
+
+# --------------------------------------------------
+# BEGIN PROJECT CONFIGURATION
+# --------------------------------------------------
+
+# The name of the final result.
+TARGET		:= dserial
+
+# A space-separated list of packages required by your
+# project. Names must be compatible with pkg-config, e.g.
+#    gtk+-3.0
+PKGS		:= 
+
+# Configure the project's directories.
+SRC_DIR		:= $(DIRECTORY)src/
+BUILD_DIR	:= $(DIRECTORY)build/
+DATA_DIR	:= $(DIRECTORY)data/
+
+# This is a hidden folder, simply used to help parallel builds
+VALA_AUX	:= $(DIRECTORY).vala-aux/
+
+# Set the vala compiler.
+VALAC		:= valac
+
+# Add any additional flags to pass to the vala compiler.
+VALAFLAGS	:= --pkg readline --pkg gio-2.0 -g
+
+# Set the C compiler.
+CC		:= gcc
+
+# Add any additional flags to pass to the C compiler.
+CFLAGS		:= -O -w -lreadline -lgio-2.0 -g
+
+# Add any additional flags to pass to the compiler during
+# the linking phase.
+OFLAGS		:= 
+
+# --------------------------------------------------
+# END PROJECT CONFIGURATION
+# --------------------------------------------------
+
+# Get pkg-config cflags and libs
+PKG_CFLAGS 	:= $(shell pkg-config --cflags gobject-2.0 $(PKGS))
+PKG_LIBS 	:= $(shell pkg-config --libs gobject-2.0 $(PKGS))
+
+# Locate necessary files
+VALA_FILES := $(shell find $(SRC_DIR) -type f -name "*.vala")
+C_FILES = $(subst $(SRC_DIR),$(BUILD_DIR)c/,$(VALA_FILES:.vala=.c))
+O_FILES = $(subst $(SRC_DIR),$(BUILD_DIR)o/,$(VALA_FILES:.vala=.o))
+
+# Set stamp and deps information
+# This part is needed in order to avoid re-building everything each time
+BASENAMES = $(subst $(SRC_DIR),,$(subst $(SRC_DIR)/,,$(basename $(VALA_FILES))))
+VALA_FASTVAPI_FILES = $(foreach f, $(BASENAMES), $(VALA_AUX)$(f).vapi)
+VALA_FASTVAPI_STAMPS = $(foreach f, $(BASENAMES), $(VALA_AUX)$(f).vapi.stamp)
+VALA_DEPS = $(foreach f, $(BASENAMES), $(VALA_AUX)$(f).dep)
+
+# Default installation prefix
+PREFIX = /usr/local
+
+BUILDMSG := Generating executable...
+
+.PRECIOUS: $(VALA_AUX)%.vapi.stamp $(VALA_AUX)%.dep
+
+# Fast option
+ifneq ($(INCREMENTAL), true)
+$(BUILD_DIR)$(TARGET): src/*.vala src/commands/*.vala Makefile
+	@echo '  $(BUILDMSG) ';mkdir -p $(BUILD_DIR) && $(VALAC) $(wildcard src/*.vala) $(wildcard src/*/*.vala) -X -w -o $(BUILD_DIR)$(TARGET) --pkg gio-2.0 --pkg readline --pkg posix -X -lreadline -g
+	@echo "  Done"
+# At first slower but then faster option, sometimes buggy
+else
+
+all: $(BUILD_DIR)$(TARGET)
+
+$(VALA_FASTVAPI_FILES): ;
+
+$(VALA_AUX)%.vapi.stamp: $(SRC_DIR)%.vala | $(VALA_AUX)
+	@echo '  GEN    '$(@:$(VALA_AUX)%.stamp=%); mkdir -p $(dir $@) && $(VALAC) --fast-vapi=$(@:.stamp=) $(@:$(VALA_AUX)%.vapi.stamp=$(SRC_DIR)%.vala) && touch $@
+
+$(VALA_AUX)%.dep: $(SRC_DIR)%.vala | $(VALA_FASTVAPI_STAMPS)
+	@echo '  VALAC -> dep  '$(patsubst $(VALA_AUX)%.dep,%.vala,$(subst //,/,$@)); $(VALAC) -C --deps=$@ -b $(SRC_DIR) -d $(BUILD_DIR)c $(VALAFLAGS) $(addprefix --use-fast-vapi=,$(subst $(patsubst $(VALA_AUX)%.dep,%.vapi,$(subst //,/,$@)),, $(VALA_FASTVAPI_FILES))) $(addprefix --pkg=,$(PKGS)) $<
+
+$(VALA_AUX):
+	@mkdir -p $(VALA_AUX)
+
+$(BUILD_DIR)c/%.c : | $(VALA_AUX)%.dep ;
+	@echo '  VALAC -> c  '$(@:$(BUILD_DIR)c/%=%);$(VALAC) -C -b $(SRC_DIR) -d $(BUILD_DIR)c $(VALAFLAGS) $(addprefix --use-fast-vapi=,$(subst $(VALA_AUX)$(@:$(BUILD_DIR)c/%.c=%.vapi),, $(VALA_FASTVAPI_FILES))) $(addprefix --pkg=,$(PKGS)) $(@:$(BUILD_DIR)c/%.c=$(SRC_DIR)%.vala)
+
+$(BUILD_DIR)o/%.o: $(BUILD_DIR)c/%.c
+	@echo '  CC     '$(<:$(BUILD_DIR)c/%=%); mkdir -p $(dir $@); $(CC) -c $(CFLAGS) $(PKG_CFLAGS) -o $@ $(@:$(BUILD_DIR)o/%.o=$(BUILD_DIR)c/%.c)
+
+$(BUILD_DIR)$(TARGET): $(O_FILES) $(C_FILES)
+	@echo '  $(BUILDMSG) ';$(CC) -o $(BUILD_DIR)$(TARGET) $(OFLAGS) $(O_FILES) $(PKG_LIBS) $(CFLAGS)
+	@echo '  Done.'
+endif
+
+run: $(BUILD_DIR)$(TARGET)
+	./$(BUILD_DIR)$(TARGET) interactive
+
+clean:
+	@echo '  Cleaning up...'; $(RM) -rf $(BUILD_DIR) $(VALA_AUX)
+	@echo '  Done.'
+
+install:
+	@echo '  Installing to $(PREFIX)...' && cp $(BUILD_DIR)$(TARGET) $(PREFIX)/bin/$(TARGET)
+	@echo '  Done.'
+
+uninstall:
+	@echo '  Removing $(PREFIX)/bin/$(TARGET)...'; $(RM) $(PREFIX)/bin/$(TARGET)
+	@echo '  Done.'
+
+.PHONY: all clean $(BUILD_DIR)$(TARGET) install install-EXEC install-LIB uninstall uninstall-EXEC uninstall-LIB
+
+include $(wildcard $(VALA_AUX)/*.dep)
+
diff --git a/dserial-cli/Readme.md b/dserial-cli/Readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..74402e9cf97ac899e72cbceb6b8056e89684501b
--- /dev/null
+++ b/dserial-cli/Readme.md
@@ -0,0 +1,45 @@
+DSerial-CLI
+===========
+
+DSerial-CLI is command line interface to DSerial D-Bus server. It allows changing port settings
+(baudrate, flowcontrol, data/stop bits). Features port autodetection.
+
+Allows writing data in various bases (ASCII, decimal, octal, hexadecimal and binary). It also allows
+reading in multiple bases simultaneously (see help read). Also has interactive regime to save you
+from repetitive writing.
+
+## How to install
+
+Currently only from source
+
+dependencies (for fedora): readline-devel vala
+
+Build and install with
+
+	make
+	sudo make install
+	
+Run
+
+	dserial	
+
+## Features (in no particular order)
+- Port autodetection
+- Command-line autocompletion
+- All basic serial port settings (baud, databits, stopbits, parity, flow control)
+- Interactive console (so you dont have to write dserial and port name all the time)
+- Advanced options for displaying recieved messages
+
+## Quickstart
+
+	dserial interactive
+	$ help
+	$ bind /dev/ttyUSB0
+	$ write ahoj
+	$ read
+
+## License
+This part of DSerial project is release under the terms GPL3 license or later
+as released by Free Software Foundation
+
+(c) Jakub Skořepa 2015
diff --git a/dserial-cli/dserial-autocompletion b/dserial-cli/dserial-autocompletion
new file mode 100644
index 0000000000000000000000000000000000000000..bdb31244760b5c4175f9cbb0e1ed5e6ff6f59acc
--- /dev/null
+++ b/dserial-cli/dserial-autocompletion
@@ -0,0 +1,114 @@
+#!/usr/bin/bash
+
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+_dserial()
+{
+	local cur cmd
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+
+	if [ $COMP_CWORD -ge 2 ]
+	then
+	case "${COMP_WORDS[1]}" in
+	interactive|list)
+		return 0
+		;;
+	help)
+		if [ $COMP_CWORD -eq 2 ]
+		then COMPREPLY=($(compgen -W "$(dserial help topics)" -- "${cur}"))
+		fi
+		return 0
+		;;
+	add)
+		if [ $COMP_CWORD -eq 2 ]
+		then
+			COMPREPLY=( $(compgen -f "${cur}") )
+			compopt -o filenames
+		fi
+		return 0
+		;;
+	info)
+		if [ $COMP_CWORD -eq 2 ]
+		   then COMPREPLY=($(compgen -W "$(dserial list)" -- "${cur}"))
+		fi
+		return 0
+		;;
+	get)
+		if [ $COMP_CWORD -eq 2 ]
+		then COMPREPLY=($(compgen -W "$(dserial list)" -- "${cur}"))
+		elif [ $COMP_CWORD -eq 3 ]
+		then COMPREPLY=($(compgen -W "$(dserial help readoptions)" -- "${cur}"))
+		fi
+		return 0
+		;;
+	set)
+		if [ $COMP_CWORD -eq 2 ]
+		then COMPREPLY=($(compgen -W "$(dserial list)" -- "${cur}"))
+		elif [ $COMP_CWORD -eq 3 ]
+		then COMPREPLY=($(compgen -W "$(dserial help options)" -- "${cur}"))
+		elif [ $COMP_CWORD -eq 4 ]
+		then COMPREPLY=($(compgen -W "$(dserial values ${COMP_WORDS[3]} ${COMP_WORDS[2]})" -- "${cur}"))
+		fi
+		return 0
+		;;
+	values)
+		if [ $COMP_CWORD -eq 2 ] ;then
+			COMPREPLY=($(compgen -W "$(dserial help options)" -- "${cur}"))
+		elif [ $COMP_CWORD -eq 3 ] ;then
+			if [ "${COMP_WORDS[2]}" == "baudrate" -o "${COMP_WORDS[2]}" == "databits" -o "${COMP_WORDS[2]}" == "stopbits" ]
+			then COMPREPLY=($(compgen -W "$(dserial list)" -- "${cur}"))
+			fi
+		fi
+		return 0
+		;;
+	open|close|write|destroy)
+		if [ $COMP_CWORD -eq 2 ]
+		then COMPREPLY=($(compgen -W "$(dserial list)" -- "${cur}"))
+		fi
+		return 0
+		;;
+	read)
+		if [ $COMP_CWORD -eq 2 ]
+		then COMPREPLY=($(compgen -W "$(dserial list)" -- "${cur}"))
+		elif [ $COMP_CWORD -eq 3 ]
+		then COMPREPLY=($(for p in X x c s d b
+				do
+					if [[ ${cur} != *"$p"* ]]
+						then printf "%s%s\n" "${cur}" "$p";
+					fi
+				done
+				))
+		fi
+		return 0
+		;;
+	*)
+		return 0
+		;;
+	esac
+	fi
+
+	COMPREPLY=($(compgen -W "$(dserial help commands)" -- "${cur}"))
+	return 0
+}
+complete -F _dserial dserial
diff --git a/dserial-cli/src/bigint.vala b/dserial-cli/src/bigint.vala
new file mode 100644
index 0000000000000000000000000000000000000000..f8aae074719cb0e080e3bef5f18097a83168dbb5
--- /dev/null
+++ b/dserial-cli/src/bigint.vala
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class UInt16 {
+	public uint16 v;
+	public UInt16(uint16 v) {
+		this.v = v;
+	}
+}
+
+public class BigInt { // base 256
+	public Array<UInt16> number;
+	public BigInt() {
+		number = new Array<UInt16>();
+		number.append_val(new UInt16(0));
+	}
+
+	public void carry(uint n) {
+		for(uint i = n; i < number.length; i++) {
+			if(number.data[i].v >= 256) {
+				if(i == number.length-1) {
+					number.append_val(new UInt16(0));
+				}
+				number.data[i+1].v += (number.data[i].v&0xff00)>>8;
+				number.data[i].v &= 0xff;
+			} else {
+				return;
+			}
+		}
+	}
+
+	public void copy_from(BigInt n) {
+		number = new Array<UInt16>();
+		for(int i = 0; i < n.number.length; i++) {
+			number.append_val(new UInt16(n.number.data[i].v));
+		}
+	}
+
+	public void add(BigInt n) {
+		for(int i = 0; i < n.number.length - number.length; i++) {
+			number.append_val(new UInt16(0));
+		}
+		for(int i = 0; i < n.number.length; i++) {
+			number.data[i].v += n.number.data[i].v;
+			carry(i);
+		}
+	}
+
+	public void add_uint8(uint8 n) {
+		number.data[0].v += n;
+		carry(0);
+	}
+
+	public void hex_print() {
+		for(uint i = number.length; i>0; i--) {
+			if(number.data[i-1].v<16) stdout.printf("0");
+			stdout.printf("%X ",number.data[i-1].v);
+		}
+	}
+
+	public void times_uint8(uint8 n) {
+		for(uint i = number.length; i > 0; i--) {
+			number.data[i-1].v *= n;
+			carry(i-1);
+		}
+	}
+}
diff --git a/dserial-cli/src/commands/AddCommand.vala b/dserial-cli/src/commands/AddCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..08170ee9f8ab83a7836c5af2cba4b2b756a0adf2
--- /dev/null
+++ b/dserial-cli/src/commands/AddCommand.vala
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class AddCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		if(args.length == 0) {
+			return error(Err.TYPE_NOT_SPECIFIED);
+		}
+        if(args.length == 1) {
+			return error(Err.NAME_NOT_SPECIFIED);
+		}
+        
+        if(args[0] == "fake") {
+            Serial.create_fake_port(args[0]);
+            stdout.printf("Warning: this action is not implemented in DSerial server\n");
+        } else if(args[0] == "file") {
+            Serial.create_file_port(args[0]);
+            stdout.printf("Warning: this action is not implemented in DSerial server\n");
+        } else {
+            return error(Err.WRONG_TYPE);
+        }
+		return 0;
+	}
+
+	public string name()
+	{
+		return "add";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+        if(args.length == 0)
+            return {"fake", "file"};
+		else if(args.length == 1)
+			return null; // => complete filename
+		else
+			return {}; // => complete nothing
+	}
+}
diff --git a/dserial-cli/src/commands/AutodetectCommand.vala b/dserial-cli/src/commands/AutodetectCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..ea5e9336d151d9caa7306d1af729182d473864e4
--- /dev/null
+++ b/dserial-cli/src/commands/AutodetectCommand.vala
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class AutodetectCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		Serial.autodetect();
+		return 0;
+	}
+
+	public string name()
+	{
+		return "autodetect";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		return {}; // => nothing
+	}
+}
diff --git a/dserial-cli/src/commands/BindCommand.vala b/dserial-cli/src/commands/BindCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..19c00f86e79665c38de76b8c0d1a6a8d74424265
--- /dev/null
+++ b/dserial-cli/src/commands/BindCommand.vala
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class BindCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		if(args.length == 0) {
+			return error(Err.PORT_NOT_SPECIFIED);
+		}
+		string? o = Serial.object_name(args[0]);
+		if(o == null) return error(Err.NONEXISTENT_PORT);
+		state.bound_port = new Serial.SerialClient(o);
+		return 0;
+	}
+
+	public string name()
+	{
+		return "bind";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0)
+			return Serial.get_ports();
+		else
+			return {};
+	}
+}
diff --git a/dserial-cli/src/commands/CloseCommand.vala b/dserial-cli/src/commands/CloseCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..8a6a49fc9f7d162a44665dcd08de54b3c8d6584d
--- /dev/null
+++ b/dserial-cli/src/commands/CloseCommand.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class CloseCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		Serial.SerialClient p;
+		if(state.bound_port == null){
+			if(args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p=state.bound_port;
+		}
+		p.close();
+		return 0;
+	}
+
+	public string name()
+	{
+		return "close";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0 && state.bound_port!=null)
+			return Serial.get_ports();
+		else
+			return {};
+	}
+}
diff --git a/dserial-cli/src/commands/Command.vala b/dserial-cli/src/commands/Command.vala
new file mode 100644
index 0000000000000000000000000000000000000000..137d63f956d7582da05371982e6048b09df6cc1b
--- /dev/null
+++ b/dserial-cli/src/commands/Command.vala
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class ApplicationState: Object {
+	public Serial.SerialClient? bound_port;
+	public bool running = true;
+	public Array<Command> command_list;
+	public bool interactive = false;
+
+	public static bool is_not_initialized = true;
+	public ApplicationState() {
+		assert(is_not_initialized);
+		is_not_initialized = false;
+		command_list = new Array<Command>();
+	}
+}
+
+public interface Command : Object {
+	public abstract int execute(string[] args, ApplicationState state);
+	public abstract string name();
+	public abstract string[]? args(string[] args, ApplicationState state);
+}
diff --git a/dserial-cli/src/commands/ExitCommand.vala b/dserial-cli/src/commands/ExitCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..3a2c826e09afc234f2fe17bf8058124c119dcd8d
--- /dev/null
+++ b/dserial-cli/src/commands/ExitCommand.vala
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class ExitCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		state.running = false;
+		return 0;
+	}
+
+	public string name()
+	{
+		return "exit";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		return {};
+	}
+}
diff --git a/dserial-cli/src/commands/GetCommand.vala b/dserial-cli/src/commands/GetCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..d2f8c84bf80f5b93750b844ec155aa3b1cb35c91
--- /dev/null
+++ b/dserial-cli/src/commands/GetCommand.vala
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class GetCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		Serial.SerialClient p;
+		if(state.bound_port == null){
+			if(args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p = state.bound_port;
+			p.reload_properties();
+		}
+
+		if(args.length == (state.bound_port==null?1:0)) {
+			return error(Err.SETTING_NOT_SPECIFIED);
+		}
+		var s = args[state.bound_port==null?1:0];
+
+		if(s=="name") {
+			stdout.printf("%s\n",p.name);
+		} else if(s=="baudrate") {
+			stdout.printf("%s\n",p.baudrate.to_string());
+		} else if(s=="databits") {
+			stdout.printf("%s\n",p.data_bits.to_string());
+		} else if(s=="stopbits") {
+			stdout.printf("%s\n",p.stop_bits.to_string());
+		} else if(s=="parity") {
+			stdout.printf("%s\n",p.parity.string_val());
+		} else if(s=="flowcontrol") {
+			stdout.printf("%s\n",p.flow_control.string_val());
+		} else {
+			return error(Err.UNKNOWN_SETTING);
+		}
+		return 0;
+	}
+
+	public string name()
+	{
+		return "get";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0 && state.bound_port == null)
+			return Serial.get_ports();
+		if(args.length == 0 || (args.length == 1 && state.bound_port != null)) {
+			return {"baudrate","databits","stopbits","parity","flowcontrol",
+				"autodetected","isopen","name"};
+		}
+		return {};
+	}
+}
diff --git a/dserial-cli/src/commands/HelpCommand.vala b/dserial-cli/src/commands/HelpCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..8f5b9866228acc6f84819800137f526205cdd380
--- /dev/null
+++ b/dserial-cli/src/commands/HelpCommand.vala
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class HelpCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		if(args.length == 0) {
+			if(!state.interactive)
+				stdout.printf("dserial <command> [arguments]\n\n");
+			stdout.printf("Available commands:\n");
+			stdout.printf("interactive\t\t\tEnters interactive session.\n");
+			stdout.printf("help\t\t\t\tDisplays this help\n");
+			stdout.printf("list\t\t\t\tLists registered serial ports\n");
+			stdout.printf("add <type> <name>\t\tAdds port to interface\n");
+			stdout.printf("info <port>\t\t\tDisplays port settings\n");
+			stdout.printf("get <port> <option>\t\tDisplays one port setting\n");
+			stdout.printf("set <port> <option> <value>\tSets port setting\n");
+			stdout.printf("values <option> [port]\t\tDisplays possible values for option\n");
+			stdout.printf("open <port>\t\t\tOpens port (should not be needed)\n");
+			stdout.printf("close <port>\t\t\tCloses port\n");
+			stdout.printf("write <port> <message>\t\tWrites message to port\n");
+			stdout.printf("read <port>\t\t\tContinually displays messages\n");
+			stdout.printf("help <command>\t\t\tDisplays help specific to command\n");
+			stdout.printf("help topics\t\t\tShows all help topics\n");
+			stdout.printf("autodetect\t\t\tAutodetects ports\n");
+			stdout.printf("bind <port>\t\t\tBinds port for other commands (interactive only)\n");
+			stdout.printf("unbind\t\t\t\tRemoves binding (interactive only)\n");
+			stdout.printf("exit\t\t\t\tExits interactive session (interactive only)\n");
+		}else if(args[0] == "interactive") {
+			stdout.printf("Enters interactive session.\n");
+		}else if(args[0] == "exit") {
+			stdout.printf("Synopsis: exit\n");
+			stdout.printf("Interactive only\n");
+			stdout.printf("Exits session\n");
+		}else if(args[0] == "help") {
+			stdout.printf("Synopsis: help [command]\n");
+			stdout.printf("Displays help\n");
+			stdout.printf("If passed another command then it displays help for that command\n\n");
+			stdout.printf("Other help topics:\n");
+			stdout.printf("commands\tJust lists commands available on command line (not interactive)\n");
+			stdout.printf("topics\tJust lists available help topics\n");
+			stdout.printf("options\tLists both readonly and readwrite options\n");
+			stdout.printf("readoptions\tLists only readonly options\n");
+		}else if(args[0] == "list") {
+			stdout.printf("Synopsis: list\n");
+			stdout.printf("Lists all registered ports\n");
+			stdout.printf("Format - id: name\n");
+			stdout.printf("All other commands can be passed either id or name\n");
+		}else if(args[0] == "add") {
+			stdout.printf("Synopsis: add <fake|file> <port>\n");
+			stdout.printf("You can add file interfaces or fake ports using this method.\n");
+            stdout.printf("Warning: This is not implemented in DSerial server.\n");
+		}else if(args[0] == "info") {
+			stdout.printf("Synopsis: info <port>\n");
+			stdout.printf("Displays port settings\n");
+			stdout.printf("Format:\n");
+			stdout.printf("<setting>: <value>\n");
+		}else if(args[0] == "get") {
+			stdout.printf("Synopsis: get <port> <option>\n");
+			stdout.printf("Display value of one option\n");
+			print_available_settings();
+		}else if(args[0] == "set") {
+			stdout.printf("Synopsis: set <port> <option> <value>\n");
+			stdout.printf("Sets setting\n");
+			print_available_settings();
+		}else if(args[0] == "values") {
+			stdout.printf("Synopsis: values <option> [port]\n");
+			stdout.printf("Displays available option values for options\n");
+			stdout.printf("Port is required for:\n");
+			stdout.printf("\t- baudrate\n");
+			stdout.printf("\t- databits\n");
+			stdout.printf("\t- stopbits\n");
+		}else if(args[0] == "open") {
+			stdout.printf("Synopsis: open <port>\n");
+			stdout.printf("Opens port. Should not be needed as read and write automatically does open.\n");
+		}else if(args[0] == "close") {
+			stdout.printf("Synopsis: close <port>\n");
+			stdout.printf("Closes port and makes it available for applications not using\n");
+			stdout.printf("D-Bus Serial Interface.\n");
+            stdout.printf("Port is automatically closed 2 minutes after last use.\n");
+		}else if(args[0] == "write") {
+			stdout.printf("Synopsis: write <port> <message>\n");
+			stdout.printf("Writes message to port\n");
+			stdout.printf("[TODO] If message is - then it reads message from standart input.\n\n");
+			stdout.printf("If you want to write any byte (not only ascii) you write it as follows:\n");
+			stdout.printf("$Xnumber$\n");
+			stdout.printf("X is base. One of: \n\tx (hexadecimal)\n\tb (binary)\n\t0 (octal)\n\tnothing(decimal)\n");
+			stdout.printf("number is number in that base\n\n");
+			stdout.printf("This command tells you how many bytes and what bytes it sent\n");
+			stdout.printf("If you want to send ascii $ you write $$\n");
+			stdout.printf("Number can be arbitrarily sized (up to 10^19 decimal digits)\n");
+		}else if(args[0] == "read") {
+			stdout.printf("Synopsis: read <port> [format-string] [format-length]\n");
+			stdout.printf("Reads from port\n");
+			stdout.printf("Format string consists of (one or more) folowing letters:\n");
+			stdout.printf("\tX\tprints hexadecimal numbers (uppercase)\n");
+			stdout.printf("\tx\tprints hexadecimal numbers (lowercase)\n");
+			stdout.printf("\tc\tprints characters, nonprintable chars are replaced with dot\n");
+			stdout.printf("\ts\tsame as c but also prints \\n and \\t and ignores \\r\n");
+			stdout.printf("\td\tprints decimal numbers (i is same)\n");
+			stdout.printf("\tb\tprints binary representation\n");
+			stdout.printf("\tDefault value is Xc\n");
+			stdout.printf("Format length specifies number of characters per line\n");
+			stdout.printf("Default is determined automagically from terminal width\n");
+		}else if(args[0] == "autodetect") {
+			stdout.printf("Synopsis: autodetect\n");
+			stdout.printf("Runs autodetection routine\n");
+			stdout.printf("Adds newly detected ports to list and removes now nonexisting ports\n");
+		}else if(args[0] == "bind") {
+			stdout.printf("Synopsis: bind <port>\n");
+			stdout.printf("Interactive only\n");
+			stdout.printf("Other commands requiring port automatically get this value\n");
+			stdout.printf("It also makes them faster due to preexisting connection\n");
+		}else if(args[0] == "unbind") {
+			stdout.printf("Synopsis: unbind\n");
+			stdout.printf("Interactive only\n");
+			stdout.printf("Removes binding created with bind\n");
+		}else if(args[0] == "commands") {
+			stdout.printf("interactive\nhelp\nlist\nadd\ninfo\nget\nset\n");
+			stdout.printf("values\nopen\nclose\nwrite\ndestroy\nread\nautodetect\n");
+		}else if(args[0] == "topics") {
+			foreach(string arg in this.args({}, state)) {
+				stdout.printf("%s\n",arg);
+			}
+		}else if(args[0] == "readoptions") {
+			stdout.printf("baudrate\ndatabits\nstopbits\nparity\nflowcontrol\n");
+			stdout.printf("name\n");
+		}else if(args[0] == "options") {
+			stdout.printf("baudrate\ndatabits\nstopbits\nparity\nflowcontrol\n");
+		}else {
+			stdout.printf("Unknown help topic \"%s\"\n",args[0]);
+		}
+		return 0;
+	}
+
+	public string name()
+	{
+		return "help";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0)
+		return {"interactive","help","list","add","info","get","set","values",
+			"open","close","write","read","help","commands","topics",
+			"bind","unbind","exit","autodetect","options","readoptions"};
+		return {};
+	}
+
+	private void print_available_settings() {
+		stdout.printf("Available settings:\n");
+		stdout.printf("\t- baudrate\n");
+		stdout.printf("\t- databits\n");
+		stdout.printf("\t- stopbits\n");
+		stdout.printf("\t- parity\n");
+		stdout.printf("\t- flowcontrol\n");
+		stdout.printf("\t- accessmode\n");
+		stdout.printf("\t- name (cannot be set)\n");
+	}
+}
diff --git a/dserial-cli/src/commands/InfoCommand.vala b/dserial-cli/src/commands/InfoCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..4c238619f9c16a8010f3e62acbb8adc2417b1e46
--- /dev/null
+++ b/dserial-cli/src/commands/InfoCommand.vala
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class InfoCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState a)
+	{
+		Serial.SerialClient p;
+		if(a.bound_port == null){
+			if(args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p = a.bound_port;
+			p.reload_properties();
+		}
+
+		stdout.printf("name: %s\n",p.name);
+        stdout.printf("flowcontrol: %s\n",p.flow_control.string_val());
+        stdout.printf("baudrate: %u\n",p.baudrate);
+		stdout.printf("databits: %u\n",p.data_bits);
+		stdout.printf("stopbits: %u\n",p.stop_bits);
+		stdout.printf("parity: %s\n",p.parity.string_val());
+        stdout.printf("type: %s\n",p.porttype.string_val());
+		return 0;
+	}
+
+	public string name()
+	{
+		return "info";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0 && state.bound_port!=null)
+			return Serial.get_ports();
+		else
+			return {};
+	}
+}
diff --git a/dserial-cli/src/commands/InteractiveCommand.vala b/dserial-cli/src/commands/InteractiveCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..adff0969742677bf6a882a334494f92abad08d57
--- /dev/null
+++ b/dserial-cli/src/commands/InteractiveCommand.vala
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class InteractiveCommand : Object, Command
+{
+	static const string[] cmds = { "interactive", "help", "list", "add", "info", "get", "set", "values", "open", "close", "write", "destroy", "read", "autodetect" };
+
+	static int list_index = 0;
+	static int len = 0;
+
+	private static string? my_generator(string text, int state)
+	{
+		string name;
+
+		if (state==0) {
+			list_index = 0;
+			len = text.length;
+		}
+
+		while (list_index < cmds.length) {
+			name = cmds[list_index];
+			list_index++;
+
+			if (name.has_prefix(text))
+				return name;
+		}
+
+		return null;
+	}
+
+	private static string[]? readline_completion( string text , int start,  int end)
+	{
+		string[]? matches;
+
+		matches = null;
+
+		if (start == 0)
+			matches = Readline.completion_matches (text, my_generator);
+		else
+			Readline.bind_key('\t',Readline.abort);
+
+		return (matches);
+	}
+
+	public int execute(string[] args, ApplicationState state)
+	{
+		state.interactive = true;
+		stdout.printf("dserial: Serial communication program\n");
+		stdout.printf("License: GPL3+\n");
+		stdout.printf("Version: 0.2\n");
+		stdout.printf("Write help for help\n");
+		Readline.History.read(Environment.get_variable("HOME")+"/.dserial-history");
+		Readline.attempted_completion_function = readline_completion;
+		while(state.running) {
+			var line = Readline.readline("$ ");
+			if (line == null) {
+				stdout.printf("\n");
+				run_func(state,{"exit"});
+				break;
+			}
+			Readline.History.add(line);
+
+			try {
+				string[] cmd;
+				Shell.parse_argv(line,out cmd);
+
+				int ret = run_func(state, cmd);
+				if(ret != 0 && ret != 100) {
+					stdout.printf("Error code: %d\n",ret);
+				}
+			} catch (ShellError e) {
+				if(e is ShellError.EMPTY_STRING) {
+					continue;
+				} else if(e is ShellError.BAD_QUOTING) {
+					stdout.printf("Bad quoting\n");
+				}else {
+					stdout.printf("Encountered error while parsing command\n");
+				}
+			}
+		}
+
+		Readline.History.write(Environment.get_variable("HOME")+"/.dserial-history");
+		Readline.History.truncate_file(Environment.get_variable("HOME")+"/.dserial-history",256);
+		return 0;
+	}
+
+	public string name()
+	{
+		return "interactive";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		return {};
+	}
+}
diff --git a/dserial-cli/src/commands/ListCommand.vala b/dserial-cli/src/commands/ListCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..b9c4be8540a2ac7fa8ab591417bf45a76609330c
--- /dev/null
+++ b/dserial-cli/src/commands/ListCommand.vala
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class ListCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		string[] ports = Serial.get_ports();
+		foreach(string port in ports) {
+			stdout.printf("%s\n",port);
+		}
+		return 0;
+	}
+
+	public string name()
+	{
+		return "list";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		return {};
+	}
+}
diff --git a/dserial-cli/src/commands/OpenCommand.vala b/dserial-cli/src/commands/OpenCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..ae89d8cee57f50ef4ff703be56d2deb51f631cd4
--- /dev/null
+++ b/dserial-cli/src/commands/OpenCommand.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class OpenCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState a)
+	{
+		Serial.SerialClient p;
+		if(a.bound_port == null){
+			if(args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p=a.bound_port;
+		}
+		p.open();
+		return 0;
+	}
+
+	public string name()
+	{
+		return "open";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0 && state.bound_port!=null)
+			return Serial.get_ports();
+		else
+			return {};
+	}
+}
diff --git a/dserial-cli/src/commands/ReadCommand.vala b/dserial-cli/src/commands/ReadCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..9d617ea2d5c3be5320d19c710c9240fea030b131
--- /dev/null
+++ b/dserial-cli/src/commands/ReadCommand.vala
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class ReadCommand : Object, Command
+{
+	private static MainLoop loop;
+	public int execute(string[] other_args, ApplicationState state)
+	{
+		loop = new MainLoop();
+		Serial.SerialClient p;
+		if(state.bound_port == null){
+			if(other_args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(other_args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p = state.bound_port;
+			p.reload_properties();
+		}
+		var display_fields = "Xc";
+		if(other_args.length >= (state.bound_port==null?2:1)){
+			display_fields = other_args[state.bound_port==null?1:0];
+		}
+		// format string
+		if(!display_fields.is_ascii()) return error(Err.NOT_ASCII_FORMAT_STRING);
+		FormatWrapper[] printers = new FormatWrapper[display_fields.char_count()];
+		for(int i = 0; i < display_fields.char_count(); i++) {
+			printers[i] = get_format(display_fields.get_char(i));
+			if(printers[i] == null) return error(Err.INVALID_FORMAT_CHARACTER);
+		}
+
+		int print_length = 0;
+		if(other_args.length >= (state.bound_port==null?3:2)) {
+			print_length = int.parse(other_args[state.bound_port==null?2:1]);
+			if(print_length <= 0) return error(Err.NEGATIVE_LENGTH);
+		}else{
+			int rows;
+			int cols;
+			Readline.get_screen_size(out rows, out cols);
+			int chars_per = 0;
+			for(int i = 0; i < printers.length; i++) {
+				chars_per += printers[i].width_per_char;
+			}
+			while(true){
+				print_length++;
+				if(print_length*chars_per+3*(printers.length-1) > cols){
+					print_length--;
+					break;
+				}
+			}
+			if(print_length<1)print_length = 1;
+		}
+
+		uint counter = 0;
+		uint8[print_length] tmpbuf = new uint8[print_length];
+        p.open();
+        
+        p.closing.connect(() => {
+            p.open();
+        });
+
+		p.data_recieved.connect((array) => {
+			for(int i = 0; i < array.length; i++) {
+				uint8[1] onebuf = new uint8[1];
+				onebuf[0] = array[i];
+				printers[0].a(onebuf);
+				tmpbuf[counter++] = array[i];
+				stdout.flush();
+				if(counter >= print_length) {
+					for(int x = 1; x < printers.length; x++) {
+						stdout.printf("   ");
+						printers[x].a(tmpbuf);
+					}
+					stdout.printf("\n");
+					counter = 0;
+				}
+			}
+		});
+		var action = Posix.sigaction_t();
+		action.sa_handler = (a)=> {
+			loop.quit();
+		};
+		Posix.sigaction(Posix.SIGINT,action,null);
+		loop.run();
+		stdout.printf("\n");
+		var dflact = Posix.sigaction_t();
+		Posix.sigaction(Posix.SIGINT,dflact,null);
+
+		return 0;
+	}
+
+	private delegate void FormatPrintArray(uint8[] array);
+
+	private class FormatWrapper {
+		public FormatPrintArray a;
+		public int width_per_char;
+	}
+
+	/*=====================================
+	 * Returns formatting function
+	 *=====================================*/
+	private FormatWrapper? get_format(unichar c) {
+		var fw = new FormatWrapper();
+		if(c == "X".get_char(0)) {
+			fw.a = (a) => {
+				for(int x = 0; x < a.length; x++) {
+					if(a[x]<16) stdout.printf("0");
+					stdout.printf("%X ", a[x]);
+				}
+			};
+			fw.width_per_char = 3;
+		} else if(c == "x".get_char(0)) {
+			fw.a = (a) => {
+				for(int x = 0; x < a.length; x++) {
+					if(a[x]<16) stdout.printf("0");
+					stdout.printf("%x ", a[x]);
+				}
+			};
+			fw.width_per_char = 3;
+		} else if(c == "d".get_char(0) ||
+				  c == "i".get_char(0) ) {
+			fw.a = (a) => {
+				for(int x = 0; x < a.length; x++) {
+					stdout.printf("%d ", a[x]);
+					if(a[x] < 10) stdout.printf(" ");
+					if(a[x] < 100) stdout.printf(" ");
+				}
+			};
+			fw.width_per_char = 4;
+		} else if(c == "s".get_char(0) ||
+				  c == "c".get_char(0)) {
+			fw.a = (a) => {
+				for(int x = 0; x < a.length; x++) {
+					if(a[x]>=32&&a[x]<127){
+						stdout.printf("%c", a[x]);
+					}else if(c == "s".get_char(0)) {
+						if(a[x] == 10) { // \n (LF)
+							stdout.printf("\n");
+						} else if(a[x] == 13) { // \r (CR)
+						} else if(a[x] == 9) { // \t (TAB)
+							stdout.printf("\t");
+						} else {
+							stdout.printf(".");
+						}
+					} else {
+						stdout.printf(".");
+					}
+				}
+			};
+			fw.width_per_char = 1;
+		} else if(c == "b".get_char(0)) {
+			fw.a = (a) => {
+				for(int x = 0; x < a.length; x++) {
+					for(int i = 0; i < 8; i++){
+						stdout.printf("%d",(a[x]&1<<i)!=0?1:0);
+					}
+					stdout.printf(" ");
+				}
+			};
+			fw.width_per_char = 9;
+		} else {
+			return null;
+		}
+		return fw;
+	}
+
+	public string name()
+	{
+		return "read";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0 && state.bound_port!=null)
+			return Serial.get_ports();
+		else
+			return {};
+	}
+}
diff --git a/dserial-cli/src/commands/SetCommand.vala b/dserial-cli/src/commands/SetCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..3b86012061f94738c3ee252d768f38f598490910
--- /dev/null
+++ b/dserial-cli/src/commands/SetCommand.vala
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class SetCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		if(args.length == (state.bound_port==null?1:0)) {
+			return error(Err.SETTING_NOT_SPECIFIED);
+		} else if(args.length == (state.bound_port==null?2:1)) {
+			return error(Err.VALUE_NOT_SPECIFIED);
+		}
+
+		Serial.SerialClient p;
+		if(state.bound_port == null){
+			if(args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p=state.bound_port;
+		}
+
+		var v = args[(state.bound_port==null?2:1)];
+		var s = args[(state.bound_port==null?1:0)];
+		if(s=="name") {
+			return error(Err.READONLY_SETTING);
+		} else if(s=="baudrate") {
+			var val = int.parse(v);
+			if(val == 0) return error(Err.WRONG_VALUE);
+			p.baudrate = val;
+		} else if(s=="databits") {
+			var val = int.parse(v);
+			if(val == 0) return error(Err.WRONG_VALUE);
+			if(!(val in p.available_data_bits)) return error(Err.WRONG_VALUE);
+			p.data_bits = val;
+		} else if(s=="stopbits") {
+			var val = int.parse(v);
+			if(val == 0) return error(Err.WRONG_VALUE);
+			if(!(val in p.available_stop_bits)) return error(Err.WRONG_VALUE);
+			p.stop_bits = val;
+		} else if(s=="parity") {
+			if(v == "odd") {
+				p.parity = Serial.SerialClient.Parity.odd;
+			} else if(v == "even") {
+				p.parity = Serial.SerialClient.Parity.even;
+			} else if(v == "none") {
+				p.parity = Serial.SerialClient.Parity.none;
+			} else {
+				return error(Err.WRONG_VALUE);
+			}
+		} else if(s=="flowcontrol") {
+			if(v == "software") {
+				p.flow_control = Serial.SerialClient.FlowControl.software;
+			} else if(v == "hardware") {
+				p.flow_control = Serial.SerialClient.FlowControl.hardware;
+			} else if(v == "none") {
+				p.flow_control = Serial.SerialClient.FlowControl.none;
+			} else {
+				return error(Err.WRONG_VALUE);
+			}
+		} else if(s=="autodetected") {
+			return error(Err.READONLY_SETTING);
+		} else if(s=="isopen") {
+			stdout.printf("Use open/close\n");
+			return error(Err.READONLY_SETTING);
+		} else {
+			return error(Err.UNKNOWN_SETTING);
+		}
+
+		return 0;
+	}
+
+	public string name()
+	{
+		return "set";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(state.bound_port == null) {
+			if(args.length == 0)
+				return {"baudrate","databits","stopbits","parity","flowcontrol",
+					"accessmode"};
+			if(args.length == 1) {
+				var ov = new OptionValues(args[1]);
+				if(ov.error) return {};
+				return ov.vals;
+			}
+		}else{
+			if(args.length == 0 )
+				return Serial.get_ports();
+			if(args.length == 1)
+				return OptionValues.settable_options();
+			if(args.length == 2) {
+				var ov = new OptionValues(args[1]);
+				if(ov.error) return {};
+				return ov.vals;
+			}
+		}
+		return {};
+	}
+}
diff --git a/dserial-cli/src/commands/UnbindCommand.vala b/dserial-cli/src/commands/UnbindCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..6cefe50347a62b43c8ce0ff6a80ba1fa4d0d51de
--- /dev/null
+++ b/dserial-cli/src/commands/UnbindCommand.vala
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class UnbindCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		state.bound_port = null;
+		return 0;
+	}
+
+	public string name()
+	{
+		return "unbind";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(state.bound_port == null && args.length == 0)
+			return Serial.get_ports();
+		else
+			return {};
+	}
+}
diff --git a/dserial-cli/src/commands/ValuesCommand.vala b/dserial-cli/src/commands/ValuesCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..0d45b6451725931b3b314c4d4145e8f3383f0bc6
--- /dev/null
+++ b/dserial-cli/src/commands/ValuesCommand.vala
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class ValuesCommand : Object, Command
+{
+	public int execute(string[] args, ApplicationState state)
+	{
+		if(args.length == 0) {
+			return error(Err.SETTING_NOT_SPECIFIED);
+		}
+
+		var s = args[0];
+		
+		OptionValues vals;
+		if(OptionValues.requires_port(s)) {
+			Serial.SerialClient p;
+			if(state.bound_port == null){
+				if(args.length == 1) {
+					return error(Err.PORT_NOT_SPECIFIED);
+				}
+				string? o = Serial.object_name(args[1]);
+				if(o == null) return error(Err.NONEXISTENT_PORT);
+				p = new Serial.SerialClient(o);
+			} else {
+				p=state.bound_port;
+			}
+			vals = new OptionValues(s,p);
+		}else{
+			vals = new OptionValues(s,null);
+		}
+		if(vals.unknown_setting) return error(Err.UNKNOWN_SETTING);
+		if(vals.error) return error(Err.VALUES_ERROR);
+        for(int i = 0; i < vals.vals.length; i++) {
+            stdout.printf("%s\n",vals.vals[i]);
+        }
+		return 0;
+	}
+
+	public string name()
+	{
+		return "values";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(args.length == 0) {
+			return OptionValues.settable_options();
+		}
+		string s = args[0];
+		if(args.length == 1 && s=="baudrate" || s=="databits" || s=="stopbits") {
+			return Serial.get_ports();
+		}
+		return {};
+	}
+}
diff --git a/dserial-cli/src/commands/WriteCommand.vala b/dserial-cli/src/commands/WriteCommand.vala
new file mode 100644
index 0000000000000000000000000000000000000000..3d5a2426167273017df33a9dec76d16bb86a8cff
--- /dev/null
+++ b/dserial-cli/src/commands/WriteCommand.vala
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+public class WriteCommand : Object, Command
+{
+	uint8 DOLLAR = 36;
+	uint8 ZERO = 48;
+	uint8 LETTER_BIG_A = 65;
+	uint8 LETTER_SMALL_A = 97;
+	private uint8 hex_to_num(uint8 ch) {
+		if(ch >= ZERO && ch <= ZERO+9)
+			return ch-ZERO;
+		if(ch >= LETTER_BIG_A && ch <= LETTER_BIG_A+5)
+			return ch-LETTER_BIG_A+10;
+		if(ch >= LETTER_SMALL_A && ch <= LETTER_SMALL_A+5)
+			return ch-LETTER_SMALL_A+10;
+		return -1;
+	}
+
+	public int execute(string[] args, ApplicationState state)
+	{
+		if (args.length == (state.bound_port==null?1:0)) {
+			return error(Err.NO_MESSAGE);
+		}
+
+		Serial.SerialClient p;
+		if(state.bound_port == null) {
+			if(args.length == 0) {
+				return error(Err.PORT_NOT_SPECIFIED);
+			}
+			string? o = Serial.object_name(args[0]);
+			if(o == null) return error(Err.NONEXISTENT_PORT);
+			p = new Serial.SerialClient(o);
+		} else {
+			p = state.bound_port;
+			p.reload_properties();
+		}
+
+		int start_p = state.bound_port==null?1:0;
+
+		// Build buffer
+		int char_count = -1; // minus 1 for terminating space
+		for(int i = start_p; i < args.length; i++) {
+			char_count += args[i].length + 1; // +1 for space
+		}
+
+		var buffer = new uint8[char_count];
+		int pointer = 0;
+		for(int i = start_p; i < args.length; i++) {
+			for(int x = 0; x < args[i].length; x++) {
+				buffer[pointer++] = (uint8)args[i][x];
+			}
+			if(i < args.length-1)
+				buffer[pointer++] = (uint8) 0x20;
+		}
+		
+		// Find dollars
+		var dollar_positions = new Array<int>();
+		for(int i = 0; i < char_count; i++) {
+			if(buffer[i] == DOLLAR)
+				dollar_positions.append_val(i);
+		}
+		
+		stdout.printf("Dollar_count = %u\n",dollar_positions.length);
+		
+		// Check dollar count
+		if(dollar_positions.length%2 == 1) {
+			return error(Err.NOT_MATCHING_DOLLAR_COUNT);
+		}
+		
+		var ints = new Array<BigInt>();
+		// Parse ints
+		for ( int i = 0; i < dollar_positions.length; i+=2 ) {
+			var number = new BigInt();
+			if (dollar_positions.index(i+1) == DOLLAR) {
+				number.add_uint8(DOLLAR);
+			}else{
+				// detect base
+				uint8 n_base = 10;
+				int base_pos = dollar_positions.index(i)+1;
+				if(buffer[base_pos] == 88 || buffer[base_pos] == 120) { // X x
+					n_base = 16;
+				} else if(buffer[base_pos] == 66 || buffer[base_pos] == 98) { // B b
+					n_base = 2;
+				} else if(buffer[base_pos] == ZERO) {
+					n_base = 8;
+				} else if(buffer[base_pos] >= ZERO+1 && buffer[base_pos] <= ZERO+9) {
+					n_base = 10;
+				} else {
+					return error(Err.NOT_NUMBER_BETWEEN_DOLLARS);
+				}
+				
+				// Read number
+				var exponent = new BigInt();
+				exponent.add_uint8(1);
+				for(int parser_pos = dollar_positions.index(i+1)-1; parser_pos > dollar_positions.index(i)+(n_base==10?0:1); parser_pos--) {
+					var tmpBI = new BigInt();
+					tmpBI.copy_from(exponent);
+					tmpBI.times_uint8(hex_to_num(buffer[parser_pos]));
+					number.add(tmpBI);
+					exponent.times_uint8(n_base);
+				}
+			}
+			ints.append_val(number);
+		}
+		
+		var tmp = new uint8[char_count];
+		uint8 tmp_pointer = 0;
+		uint8 dollar_pointer = 0;
+		
+		// Construct final message
+		for(int buffer_pointer = 0; buffer_pointer < char_count; buffer_pointer++) {
+			if(buffer[buffer_pointer] == DOLLAR) {
+				for(int i = (int)ints.index(dollar_pointer).number.length-1; i >= 0; i--) {
+					tmp[tmp_pointer++] = (uint8)ints.index(dollar_pointer).number.index(i).v;
+				}
+				buffer_pointer = dollar_positions.index(dollar_pointer*2+1);
+				dollar_pointer ++;
+			} else {
+				tmp[tmp_pointer++] = buffer[buffer_pointer];
+			}
+		}
+		
+
+		stdout.printf("Writing %lli bytes: \n", tmp_pointer);
+		// Print back
+        var short_buf = new uint8[tmp_pointer];
+		for(int a = 0; a < tmp_pointer; a++) {
+			if(tmp[a] < 16) stdout.printf("0");
+			stdout.printf("%x ", tmp[a]);
+            short_buf[a] = tmp[a];
+		}
+		stdout.printf("\n");
+
+		// Write
+		p.write(short_buf);
+		return 0;
+	}
+
+	public string name()
+	{
+		return "write";
+	}
+
+	public string[]? args(string[] args, ApplicationState state)
+	{
+		if(state.bound_port == null && args.length == 0) {
+			return Serial.get_ports();
+		}else{
+			return {};
+		}
+	}
+}
diff --git a/dserial-cli/src/dbus-serial-client.vala b/dserial-cli/src/dbus-serial-client.vala
new file mode 100644
index 0000000000000000000000000000000000000000..cf9c2685bff005d0f7eb8e3acbd68f7a13be3bdc
--- /dev/null
+++ b/dserial-cli/src/dbus-serial-client.vala
@@ -0,0 +1,352 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Serial {
+[DBus (name = "info.skorepa.DSerial1.controller")]
+private interface Controller : GLib.Object {
+	public abstract void autodetect() throws IOError;
+	public abstract void create_file_port(string file_name) throws IOError;
+    public abstract void create_fake_port(string file_name) throws IOError;
+    public abstract string get_path(string file_name) throws IOError;
+}
+
+[DBus (name = "org.freedesktop.DBus.Properties")]
+private interface Properties : GLib.Object {
+	public signal void properties_changed(string interf, HashTable<string, Variant> changed_properties_values,
+		string[] other_changed);
+
+    public abstract Variant get(string interface_name, string property_name) throws IOError;
+	public abstract HashTable<string, Variant> get_all(string interf) throws IOError;
+	public abstract void set(string interf, string property, Variant value) throws IOError;
+}
+
+[DBus (name = "info.skorepa.DSerial1.port")]
+private interface Methods : GLib.Object {
+	public abstract void write(uint8[] msg) throws IOError;
+	public abstract void open() throws IOError;
+	public abstract void close() throws IOError;
+	public signal void data_recieved(uint8[] msg);
+    public signal void closing();
+    public signal void data_sent(uint8[] msg);
+    public signal void disappeared();
+}
+
+
+/*=====================================
+ * Return object name for file name
+ *=====================================*/
+public static string? object_name(string file_name) {
+	try {
+        Controller c = Bus.get_proxy_sync(BusType.SESSION,"info.skorepa.DSerial1","/controller");
+        var path = c.get_path(file_name);
+        if(path == "/") return null;
+        return path;
+	} catch (Error e) {
+		return null;
+	}
+}
+
+/*=====================================
+ * List all available ports
+ *=====================================*/
+public static string[] get_ports() {
+	try {
+		Properties c = Bus.get_proxy_sync(BusType.SESSION,"info.skorepa.DSerial1","/controller");
+        return c.get("info.skorepa.DSerial1.controller", "PortList").get_strv();
+	}catch(IOError e){
+		stdout.printf("Unable to get ports: %s\n",e.message);
+	}
+	return new string[0];
+}
+
+/*=====================================
+ * Port autodetection
+ *=====================================*/
+public static void autodetect() {
+	try {
+		Controller c = GLib.Bus.get_proxy_sync (BusType.SESSION, "info.skorepa.DSerial1", "/controller");
+		c.autodetect();
+	}catch(IOError e){}
+}
+
+/*=====================================
+ * Port creation
+ *=====================================*/
+public static void create_fake_port(string file_name) {
+	try {
+		Controller c = GLib.Bus.get_proxy_sync (BusType.SESSION, "info.skorepa.DSerial1", "/controller");
+		c.create_fake_port(file_name);
+	}catch(IOError e){}
+}
+public static void create_file_port(string file_name) {
+	try {
+		Controller c = GLib.Bus.get_proxy_sync (BusType.SESSION, "info.skorepa.DSerial1", "/controller");
+		c.create_file_port(file_name);
+	}catch(IOError e){}
+}
+
+private class PropertiesAccessor : GLib.Object {
+	Properties properties;
+	HashTable<string, Variant> cache;
+	string iface;
+
+	public PropertiesAccessor(GLib.BusType t, string _iface, string object) { // info.skorepa.DSerial1.port	/info/skorepa/serial/dev/ttyUSB0
+		iface = _iface;
+		try {
+			properties = GLib.Bus.get_proxy_sync<Properties>(t,"info.skorepa.DSerial1",object);
+			properties.properties_changed.connect(on_property_changed);
+		} catch (IOError e) {}
+		reload();
+	}
+
+	public void set_val(string k, Variant v) {
+		try {
+			properties.set(iface,k,v);
+		} catch (IOError e) {}
+		finally {
+			cache.replace(k,v);
+		}
+	}
+
+	public Variant get_val(string k) {
+		return cache.get(k);
+	}
+
+	private void on_property_changed(string interf, HashTable<string, Variant> changed, string[] other_changed) {
+		List<string> keys = changed.get_keys();
+		GLib.Func<string> foreach_f = (k)=>{
+			var v = changed.get(k);
+			cache.replace(k,v);
+			property_changed(k,v);
+		};
+		keys.foreach(foreach_f);
+	}
+
+	public signal void property_changed(string name, Variant value);
+	public void reload() {
+		try {
+			cache = properties.get_all(iface);
+		} catch (IOError e) {}
+	}
+}
+
+public class SerialClient {
+	PropertiesAccessor properties;
+	Methods methods;
+
+	/*=====================================
+	 * Constructor
+	 *=====================================*/
+	public SerialClient(string port_object) {
+		stdout.flush();
+		properties = new PropertiesAccessor(GLib.BusType.SESSION, "info.skorepa.DSerial1.port", port_object);
+		try {
+			stdout.flush();
+			methods = GLib.Bus.get_proxy_sync (GLib.BusType.SESSION, "info.skorepa.DSerial1", port_object);
+		} catch (IOError e) {}
+        
+		methods.data_recieved.connect((t, msg) => {
+			this.data_recieved(msg);
+		});
+        methods.data_sent.connect((t, msg) => {
+			this.data_sent(msg);
+		});
+        methods.closing.connect((t) => {
+            this.closing();
+        });
+        methods.disappeared.connect((t) => {
+            this.disappeared();
+        });
+	}
+
+	public void reload_properties() {
+		properties.reload();
+	}
+    
+    /*=====================================
+	 * Flow Control
+	 *=====================================*/
+    public enum FlowControl {
+		none = 0, hardware, software;
+		public string string_val()
+        {
+                return ((EnumClass)typeof (Parity).class_ref()).get_value(this).value_nick;
+        }
+	}
+    public FlowControl flow_control {
+        get {
+            uint8 v = properties.get_val("FlowControl").get_byte();
+            if(v == 2) return FlowControl.hardware;
+            if(v == 3) return FlowControl.software;
+            return FlowControl.none;
+        }
+        set {
+            if(value == FlowControl.none) properties.set_val("FlowControl", 1);
+            else if(value == FlowControl.hardware) properties.set_val("FlowControl", 2);
+            else if(value == FlowControl.software) properties.set_val("FlowControl", 3);
+        }
+    }
+    
+    /*=====================================
+	 * Port name
+	 *=====================================*/
+	string _name;
+	public string name {
+		get {
+			_name = (string)properties.get_val("Name");
+			return _name;
+		}
+	}
+
+	/*=====================================
+	 * Baudrates
+	 *=====================================*/
+	int32[] _available_baudrates = {};
+	public int32[] available_baudrates {
+		get{
+			_available_baudrates = {}; //(int32[])properties.get_val("AvailableBaudrates");
+			return _available_baudrates;
+		}
+	}
+
+	public int32 baudrate {
+		get {return (int32)properties.get_val("Baudrate");}
+		set {properties.set_val("Baudrate",value);}
+	}
+	
+	/*=====================================
+	 * Data bits
+	 *=====================================*/
+	int[] _available_data_bits = {};
+	public int[] available_data_bits {
+		get {
+			_available_data_bits = {5,6,7,8};
+			return _available_data_bits;
+		}
+	}
+
+	public int data_bits {
+		get {return (uint8)properties.get_val("DataBits");}
+		set {properties.set_val("DataBits",value);}
+	}
+
+	/*=====================================
+	 * Stop bits
+	 *=====================================*/
+	int[] _available_stop_bits;
+	public int[] available_stop_bits {
+		get {
+			_available_stop_bits = {1,2};
+			return _available_stop_bits;
+		}
+	}
+
+	public int stop_bits {
+		get {return (uint8)properties.get_val("StopBits");}
+		set {properties.set_val("StopBits",value);}
+	}
+
+	/*=====================================
+	 * Parity
+	 *=====================================*/
+	public enum Parity {
+		none = 0, even, odd, space, mark;
+		public string string_val()
+        {
+                return ((EnumClass)typeof (Parity).class_ref()).get_value(this).value_nick;
+        }
+	}
+
+	public Parity parity {
+		get {
+			uint8 v = properties.get_val("Parity").get_byte();
+			if(v == 2) return Parity.even;
+            if(v == 3) return Parity.odd;
+            if(v == 4) return Parity.space;
+            if(v == 5) return Parity.mark;
+			return Parity.none;
+		}
+		set {
+            if(value == Parity.none) properties.set_val("Parity",1);
+            if(value == Parity.even) properties.set_val("Parity",2);
+            if(value == Parity.odd)  properties.set_val("Parity",3);
+            if(value == Parity.space)properties.set_val("Parity",4);
+            if(value == Parity.mark) properties.set_val("Parity",5);
+		}
+	}
+    
+    /*=====================================
+	 * Type
+	 *=====================================*/
+    public enum PortType {
+        autodetected, fake, file;
+        public string string_val()
+        {
+                return ((EnumClass)typeof (Parity).class_ref()).get_value(this).value_nick;
+        }
+    }
+    
+    public PortType porttype {
+		get {
+			uint8 v = properties.get_val("Type").get_byte();
+			if(v == 0) return PortType.autodetected;
+            if(v == 1) return PortType.fake;
+            return PortType.file;
+		}
+	}
+
+	/*=====================================
+	 * Message sender
+	 *=====================================*/
+	public void write(uint8[] msg) {
+		try {
+			methods.write(msg);
+		} catch (IOError e) {}
+	}
+
+	/*=====================================
+	 * Message reciever
+	 *=====================================*/
+	public signal void data_recieved(uint8[] msg);
+    public signal void closing();
+    public signal void data_sent(uint8[] msg);
+    public signal void disappeared();
+
+	/*=====================================
+	 * Open port
+	 *=====================================*/
+	public void open() {
+		try {
+			methods.open();
+		} catch (IOError e) {}
+	}
+
+	/*=====================================
+	 * Close port
+	 *=====================================*/
+	public void close() {
+		try {
+			methods.close();
+		} catch (IOError e) {}
+	}
+}
+
+}
diff --git a/dserial-cli/src/error.vala b/dserial-cli/src/error.vala
new file mode 100644
index 0000000000000000000000000000000000000000..d09847f5646a2c768c28b52a3adaa07b26bea8a7
--- /dev/null
+++ b/dserial-cli/src/error.vala
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+enum Err {
+	NONEXISTENT_PORT,
+	PORT_NOT_SPECIFIED,
+	NAME_NOT_SPECIFIED,
+	SETTING_NOT_SPECIFIED,
+	UNKNOWN_SETTING,
+	READONLY_SETTING,
+	VALUE_NOT_SPECIFIED,
+	WRONG_VALUE,
+	PORT_NOT_SPECIFIED_VALUES,
+	NO_MESSAGE,
+	NEGATIVE_LENGTH,
+	NOT_ASCII_FORMAT_STRING,
+	INVALID_FORMAT_CHARACTER,
+	NOT_MATCHING_DOLLAR_COUNT,
+	NOT_NUMBER_BETWEEN_DOLLARS,
+	FIRST_NUMBER_NOT_GOOD,
+	DIGIT_TOO_BIG,
+	VALUES_ERROR,
+    TYPE_NOT_SPECIFIED,
+    WRONG_TYPE
+}
+
+int error(Err error) {
+	switch(error) {
+		case Err.NONEXISTENT_PORT:
+			stdout.printf("Port doesn't exist\n");
+			return 1;
+		case Err.PORT_NOT_SPECIFIED:
+			stdout.printf("Port not specified\n");
+			return 2;
+		case Err.NAME_NOT_SPECIFIED:
+			stdout.printf("Name not specified\n");
+			return 3;
+		case Err.SETTING_NOT_SPECIFIED:
+			stdout.printf("Setting not specified\n");
+			return 4;
+		case Err.UNKNOWN_SETTING:
+			stdout.printf("Unknown setting\n");
+			return 5;
+		case Err.READONLY_SETTING:
+			stdout.printf("This setting is read-only\n");
+			return 6;
+		case Err.VALUE_NOT_SPECIFIED:
+			stdout.printf("Value not specified\n");
+			return 7;
+		case Err.WRONG_VALUE:
+			stdout.printf("Wrong value. Use values command to determine possible values\n");
+			return 8;
+		case Err.PORT_NOT_SPECIFIED_VALUES:
+			stdout.printf("Port not specified. Values for this setting may vary from port to port therefore port is required\n");
+			return 9;
+		case Err.NO_MESSAGE:
+			stdout.printf("No message specified\n");
+			return 10;
+		case Err.NEGATIVE_LENGTH:
+			stdout.printf("Length must be positive\n");
+			return 13;
+		case Err.NOT_ASCII_FORMAT_STRING:
+			stdout.printf("Only ascii characters alowed in format string\n");
+			return 14;
+		case Err.INVALID_FORMAT_CHARACTER:
+			stdout.printf("Character is not allowed in format string\n");
+			return 15;
+		case Err.NOT_MATCHING_DOLLAR_COUNT:
+			stdout.printf("Invalid write string. Found rogue $.\n");
+			return 15;
+		case Err.NOT_NUMBER_BETWEEN_DOLLARS:
+			stdout.printf("Only numbers are allowed between dollars.\n");
+			return 16;
+		case Err.FIRST_NUMBER_NOT_GOOD:
+			stdout.printf("First character after $ has to be x X b B or number\n");
+			return 17;
+		case Err.DIGIT_TOO_BIG:
+			stdout.printf("Digit is too big for selected base\n");
+			return 18;
+		case Err.VALUES_ERROR:
+			stdout.printf("Unknown error appeared while getting value list\n");
+			return 19;
+        case Err.TYPE_NOT_SPECIFIED:
+            stdout.printf("Port type not specified\n");
+            return 20;
+        case Err.WRONG_TYPE:
+            stdout.printf("Specified type is not valid\n");
+            return 21;
+	}
+	return 0;
+}
diff --git a/dserial-cli/src/option-values.vala b/dserial-cli/src/option-values.vala
new file mode 100644
index 0000000000000000000000000000000000000000..e77aba1fce119746f082503e95c329b7d934a65c
--- /dev/null
+++ b/dserial-cli/src/option-values.vala
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+class OptionValues {
+	public string[] vals;
+	public bool error = false;
+	public bool unknown_setting = false;
+	public bool readonly = false;
+	
+	public static bool requires_port(string s) {
+		return (s=="baudrate" || s=="databits" || s=="stopbits");
+	}
+	
+	public OptionValues(string s, Serial.SerialClient? p = null) {
+		if(s=="name") {
+			stdout.printf("read-only\nany string\n");
+		} else if(s=="baudrate" || s=="databits" || s=="stopbits") {
+			if(p == null) {
+				error = true;
+			}
+			int[] availables;
+			bool WTF = true;
+			assert(WTF);
+			if(s=="baudrate") {
+                stdout.printf("Warning: Not implemented on dserial server\n");
+				availables = p.available_baudrates;
+			} else if(s=="databits") {
+				availables = p.available_data_bits;
+			} else if(s=="stopbits") {
+				availables = p.available_stop_bits;
+			} else {
+				error = true;
+				return;
+			}
+			vals = new string[availables.length];
+			int i = 0;
+			foreach(var b in availables) {
+				vals[i] = b.to_string();
+				i++;
+			}
+		} else if(s=="parity") {
+			vals = {"odd","even","none","mark","space"};
+		} else if(s=="flowcontrol") {
+			vals = {"software","hardware","none"};
+		} else if(s=="autodetected") {
+			readonly = true;
+			vals = {"true","false"};
+		} else if(s=="isopen") {
+			readonly = true;
+			vals = {"true","false"};
+		} else {
+			unknown_setting = true;
+			error = true;
+			vals = {};
+		}
+	}
+	
+	public static string[] settable_options() {
+		return {"baudrate","databits","stopbits","parity","flowcontrol"};
+	}
+}
diff --git a/dserial-cli/src/serial-communicator-cli.vala b/dserial-cli/src/serial-communicator-cli.vala
new file mode 100644
index 0000000000000000000000000000000000000000..aa580bcf98156114be460f7bd6da72ecfc16e6d9
--- /dev/null
+++ b/dserial-cli/src/serial-communicator-cli.vala
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2015 Jakub Skořepa <jakub@skorepa.info>
+ *
+ * This file is part of dserial
+ *
+ * dserial is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU  General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * dserial is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dserial.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/*=====================================
+ * Runs appropriate function
+ *=====================================*/
+int run_func(ApplicationState state, string[] args) {
+	string[] other_args = new string[args.length-1>0?args.length-1:0];
+	string? f = args[0];
+	for(int i = 1; i < args.length; i++) {
+		other_args[i-1] = args[i];
+	}
+
+	if(f == null) f = "help";
+	for( int i = 0; i < state.command_list.length; i++) {
+		if (state.command_list.index(i).name() == f) {
+			return state.command_list.index(i).execute(other_args, state);
+		}
+	}
+	stdout.printf(@"Unknown function $f\n");
+	if(!state.interactive)
+		stdout.printf("Execute \"dserial help\" for help\n");
+	else
+		stdout.printf("Run help for help\n");
+	return 100;
+}
+
+void init_list(ApplicationState state) {
+	Command c = new AddCommand();
+	state.command_list.append_val(c);
+	c = new AutodetectCommand();
+	state.command_list.append_val(c);
+	c = new BindCommand();
+	state.command_list.append_val(c);
+	c = new CloseCommand();
+	state.command_list.append_val(c);
+	c = new ExitCommand();
+	state.command_list.append_val(c);
+	c = new GetCommand();
+	state.command_list.append_val(c);
+	c = new HelpCommand();
+	state.command_list.append_val(c);
+	c = new InfoCommand();
+	state.command_list.append_val(c);
+	c = new InteractiveCommand();
+	state.command_list.append_val(c);
+	c = new ListCommand();
+	state.command_list.append_val(c);
+	c = new OpenCommand();
+	state.command_list.append_val(c);
+	c = new ReadCommand();
+	state.command_list.append_val(c);
+	c = new SetCommand();
+	state.command_list.append_val(c);
+	c = new UnbindCommand();
+	state.command_list.append_val(c);
+	c = new ValuesCommand();
+	state.command_list.append_val(c);
+	c = new WriteCommand();
+	state.command_list.append_val(c);
+}
+
+/*=====================================
+ * Main method
+ *=====================================*/
+int main (string[] args) {
+	var state = new ApplicationState();
+	init_list(state);
+
+	// remove program name
+	string[] other_args = new string[args.length-1>=0?args.length-1:0];
+	for(int i = 1; i < args.length; i++) {
+		other_args[i-1] = args[i];
+	}
+
+	return run_func(state, other_args);
+}