Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_DS28EC20_GPIO
Platforms/dotnet/SerialPort.hpp@4:caf56f265a13, 2018-01-19 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri Jan 19 10:25:02 2018 -0600
- Revision:
- 4:caf56f265a13
- Parent:
- 3:f818ea5172ed
Cleaned old files.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| IanBenzMaxim | 3:f818ea5172ed | 1 | /******************************************************************************* |
| IanBenzMaxim | 3:f818ea5172ed | 2 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
| IanBenzMaxim | 3:f818ea5172ed | 3 | * |
| IanBenzMaxim | 3:f818ea5172ed | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| IanBenzMaxim | 3:f818ea5172ed | 5 | * copy of this software and associated documentation files (the "Software"), |
| IanBenzMaxim | 3:f818ea5172ed | 6 | * to deal in the Software without restriction, including without limitation |
| IanBenzMaxim | 3:f818ea5172ed | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| IanBenzMaxim | 3:f818ea5172ed | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| IanBenzMaxim | 3:f818ea5172ed | 9 | * Software is furnished to do so, subject to the following conditions: |
| IanBenzMaxim | 3:f818ea5172ed | 10 | * |
| IanBenzMaxim | 3:f818ea5172ed | 11 | * The above copyright notice and this permission notice shall be included |
| IanBenzMaxim | 3:f818ea5172ed | 12 | * in all copies or substantial portions of the Software. |
| IanBenzMaxim | 3:f818ea5172ed | 13 | * |
| IanBenzMaxim | 3:f818ea5172ed | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| IanBenzMaxim | 3:f818ea5172ed | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| IanBenzMaxim | 3:f818ea5172ed | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| IanBenzMaxim | 3:f818ea5172ed | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
| IanBenzMaxim | 3:f818ea5172ed | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| IanBenzMaxim | 3:f818ea5172ed | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| IanBenzMaxim | 3:f818ea5172ed | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| IanBenzMaxim | 3:f818ea5172ed | 21 | * |
| IanBenzMaxim | 3:f818ea5172ed | 22 | * Except as contained in this notice, the name of Maxim Integrated |
| IanBenzMaxim | 3:f818ea5172ed | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
| IanBenzMaxim | 3:f818ea5172ed | 24 | * Products, Inc. Branding Policy. |
| IanBenzMaxim | 3:f818ea5172ed | 25 | * |
| IanBenzMaxim | 3:f818ea5172ed | 26 | * The mere transfer of this software does not imply any licenses |
| IanBenzMaxim | 3:f818ea5172ed | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
| IanBenzMaxim | 3:f818ea5172ed | 28 | * trademarks, maskwork rights, or any other form of intellectual |
| IanBenzMaxim | 3:f818ea5172ed | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
| IanBenzMaxim | 3:f818ea5172ed | 30 | * ownership rights. |
| IanBenzMaxim | 3:f818ea5172ed | 31 | *******************************************************************************/ |
| IanBenzMaxim | 3:f818ea5172ed | 32 | |
| IanBenzMaxim | 3:f818ea5172ed | 33 | #pragma once |
| IanBenzMaxim | 3:f818ea5172ed | 34 | |
| IanBenzMaxim | 3:f818ea5172ed | 35 | #include <memory> |
| IanBenzMaxim | 3:f818ea5172ed | 36 | #include <string> |
| IanBenzMaxim | 3:f818ea5172ed | 37 | #include <MaximInterface/Links/SerialPort.hpp> |
| IanBenzMaxim | 3:f818ea5172ed | 38 | #include <MaximInterface/Utilities/Export.h> |
| IanBenzMaxim | 3:f818ea5172ed | 39 | #include "MoveOnly.hpp" |
| IanBenzMaxim | 3:f818ea5172ed | 40 | |
| IanBenzMaxim | 3:f818ea5172ed | 41 | namespace MaximInterface { |
| IanBenzMaxim | 3:f818ea5172ed | 42 | namespace dotnet { |
| IanBenzMaxim | 3:f818ea5172ed | 43 | |
| IanBenzMaxim | 3:f818ea5172ed | 44 | /// Serial port interface using .NET type System::IO::Ports::SerialPort. |
| IanBenzMaxim | 3:f818ea5172ed | 45 | class SerialPort : public MaximInterface::SerialPort, private MoveOnly { |
| IanBenzMaxim | 3:f818ea5172ed | 46 | public: |
| IanBenzMaxim | 3:f818ea5172ed | 47 | enum ErrorValue { |
| IanBenzMaxim | 3:f818ea5172ed | 48 | NotConnectedError = 1, |
| IanBenzMaxim | 3:f818ea5172ed | 49 | ArgumentError, |
| IanBenzMaxim | 3:f818ea5172ed | 50 | InvalidOperationError, |
| IanBenzMaxim | 3:f818ea5172ed | 51 | IOError, |
| IanBenzMaxim | 3:f818ea5172ed | 52 | UnauthorizedAccessError |
| IanBenzMaxim | 3:f818ea5172ed | 53 | }; |
| IanBenzMaxim | 3:f818ea5172ed | 54 | |
| IanBenzMaxim | 3:f818ea5172ed | 55 | MaximInterface_EXPORT SerialPort(); |
| IanBenzMaxim | 3:f818ea5172ed | 56 | MaximInterface_EXPORT ~SerialPort(); |
| IanBenzMaxim | 3:f818ea5172ed | 57 | |
| IanBenzMaxim | 3:f818ea5172ed | 58 | MaximInterface_EXPORT SerialPort(SerialPort &&) noexcept; |
| IanBenzMaxim | 3:f818ea5172ed | 59 | MaximInterface_EXPORT SerialPort & operator=(SerialPort &&) noexcept; |
| IanBenzMaxim | 3:f818ea5172ed | 60 | |
| IanBenzMaxim | 3:f818ea5172ed | 61 | MaximInterface_EXPORT virtual error_code |
| IanBenzMaxim | 3:f818ea5172ed | 62 | connect(const std::string & portName) override; |
| IanBenzMaxim | 3:f818ea5172ed | 63 | MaximInterface_EXPORT virtual error_code disconnect() override; |
| IanBenzMaxim | 3:f818ea5172ed | 64 | MaximInterface_EXPORT virtual bool connected() const override; |
| IanBenzMaxim | 3:f818ea5172ed | 65 | MaximInterface_EXPORT virtual std::string portName() const override; |
| IanBenzMaxim | 3:f818ea5172ed | 66 | |
| IanBenzMaxim | 3:f818ea5172ed | 67 | MaximInterface_EXPORT virtual error_code |
| IanBenzMaxim | 3:f818ea5172ed | 68 | setBaudRate(int_least32_t baudRate) override; |
| IanBenzMaxim | 3:f818ea5172ed | 69 | MaximInterface_EXPORT virtual error_code sendBreak() override; |
| IanBenzMaxim | 3:f818ea5172ed | 70 | MaximInterface_EXPORT virtual error_code clearReadBuffer() override; |
| IanBenzMaxim | 3:f818ea5172ed | 71 | MaximInterface_EXPORT virtual error_code |
| IanBenzMaxim | 3:f818ea5172ed | 72 | writeByte(uint_least8_t data) override; |
| IanBenzMaxim | 3:f818ea5172ed | 73 | MaximInterface_EXPORT virtual error_code |
| IanBenzMaxim | 3:f818ea5172ed | 74 | writeBlock(const uint_least8_t * data, size_t dataLen) override; |
| IanBenzMaxim | 3:f818ea5172ed | 75 | MaximInterface_EXPORT virtual error_code |
| IanBenzMaxim | 3:f818ea5172ed | 76 | readByte(uint_least8_t & data) override; |
| IanBenzMaxim | 3:f818ea5172ed | 77 | MaximInterface_EXPORT virtual error_code readBlock(uint_least8_t * data, |
| IanBenzMaxim | 3:f818ea5172ed | 78 | size_t dataLen) override; |
| IanBenzMaxim | 3:f818ea5172ed | 79 | |
| IanBenzMaxim | 3:f818ea5172ed | 80 | MaximInterface_EXPORT static const error_category & errorCategory(); |
| IanBenzMaxim | 3:f818ea5172ed | 81 | |
| IanBenzMaxim | 3:f818ea5172ed | 82 | private: |
| IanBenzMaxim | 3:f818ea5172ed | 83 | struct Data; |
| IanBenzMaxim | 3:f818ea5172ed | 84 | std::unique_ptr<Data> data; |
| IanBenzMaxim | 3:f818ea5172ed | 85 | }; |
| IanBenzMaxim | 3:f818ea5172ed | 86 | |
| IanBenzMaxim | 3:f818ea5172ed | 87 | inline error_code make_error_code(SerialPort::ErrorValue e) { |
| IanBenzMaxim | 3:f818ea5172ed | 88 | return error_code(e, SerialPort::errorCategory()); |
| IanBenzMaxim | 3:f818ea5172ed | 89 | } |
| IanBenzMaxim | 3:f818ea5172ed | 90 | |
| IanBenzMaxim | 3:f818ea5172ed | 91 | } // namespace dotnet |
| IanBenzMaxim | 3:f818ea5172ed | 92 | } // namespace MaximInterface |