Class PortSerial
- Namespace
- nanoFramework.Tools.Debugger.PortSerial
- Assembly
- nanoFramework.Tools.DebugLibrary.Net.dll
A class representing a serial port used for communication with a device.
public class PortSerial : PortMessageBase, IPort
- Inheritance
-
PortSerial
- Implements
- Inherited Members
- Extension Methods
Constructors
PortSerial(PortSerialManager, NanoDevice<NanoSerialDevice>)
Initializes a new instance of the PortSerial class.
public PortSerial(PortSerialManager portManager, NanoDevice<NanoSerialDevice> serialDevice)
Parameters
portManager
PortSerialManagerThe manager for the serial port.
serialDevice
NanoDevice<NanoSerialDevice>The NanoDevice associated with the serial port.
Fields
ValidBaudRates
A list of valid baud rates for the serial port.
public static readonly List<int> ValidBaudRates
Field Value
Properties
AvailableBytes
Gets the number of bytes available in the receive buffer of the open serial port. If the port is not open, returns -1.
public int AvailableBytes { get; }
Property Value
BaudRate
Gets or sets the baud rate for the serial port.
public int BaudRate { get; }
Property Value
Device
Gets the underlying SerialPort device.
public SerialPort Device { get; }
Property Value
InstanceId
Gets the Instance ID of the device. This DeviceInformation represents which device is connected or which device will be reconnected when the device is plugged in again (if IsEnabledAutoReconnect is true);.
public string InstanceId { get; }
Property Value
IsDeviceConnected
Gets a value indicating whether the device is connected.
public bool IsDeviceConnected { get; }
Property Value
LastActivity
Gets or sets the date and time when the device was last active.
public DateTime LastActivity { get; set; }
Property Value
NanoDevice
Gets or sets the baud rate for the serial port.
public NanoDevice<NanoSerialDevice> NanoDevice { get; }
Property Value
Methods
CloseDevice()
Closes the device, stops the device watcher, stops listening for app events, and resets object state to before a device was ever connected.
public void CloseDevice()
ConnectDevice()
Connects to a serial device.
public ConnectPortResult ConnectDevice()
Returns
- ConnectPortResult
The result of the connection attempt
DisconnectDevice(bool)
Disconnects the current device.
public void DisconnectDevice(bool force = false)
Parameters
force
boolFlag indicating whether the device should be forcibly disposed.
OpenDevice()
This method opens the device using the WinRT Serial API. After the device is opened, save the device so that it can be used across scenarios.
It is important that the FromIdAsync call is made on the UI thread because the consent prompt can only be displayed on the UI thread.
This method is used to reopen the device after the device reconnects to the computer and when the app resumes.
public ConnectPortResult OpenDevice()
Returns
- ConnectPortResult
True if the device was successfully opened, false if the device could not be opened for well known reasons. An exception may be thrown if the device could not be opened for extraordinary reasons.
ReadBuffer(int)
Reads the specified number of bytes from the connected device. The device must be connected and open.
public byte[] ReadBuffer(int bytesToRead)
Parameters
bytesToRead
intThe number of bytes to read from the device.
Returns
- byte[]
A byte array containing the bytes read from the device. If an error occurs or the device is not connected or open, an empty byte array is returned.
Exceptions
- DeviceNotConnectedException
Thrown when the device is not connected or open.
SendBuffer(byte[])
Sends the specified byte array to the connected device.
public int SendBuffer(byte[] buffer)
Parameters
buffer
byte[]The byte array to send.
Returns
- int
The number of bytes sent.
Exceptions
- DeviceNotConnectedException
Thrown when the device is not connected.
Events
LogMessageAvailable
Event that is raised when a log message is available.
public override event EventHandler<StringEventArgs> LogMessageAvailable