/// <summary> /// Configures this serial line. This should be called at most once. /// </summary> /// <param name="baudRate">The baud rate.</param> /// <param name="parity">A value from the <see cref="T:Microsoft.Gadgeteer.Interfaces.Serial.SerialParity"/> enumeration that specifies the parity.</param> /// <param name="stopBits">A value from the <see cref="T:Microsoft.Gadgeteer.Interfaces.Serial.SerialStopBits"/> enumeration that specifies the number of stop bits.</param> /// <param name="dataBits">The number of data bits.</param> public void Configure(int baudRate, GTI.Serial.SerialParity parity, GTI.Serial.SerialStopBits stopBits, int dataBits) { if (_SerialLine != null) { throw new Exception("UsbSerial.Configure can only be called once"); } // TODO: check if HW flow control should be used _SerialLine = new GTI.Serial(socket, baudRate, parity, stopBits, dataBits, GTI.Serial.HardwareFlowControl.NotRequired, this); }
/// <summary> /// Initializes the serial port to the passed in parameters. If no parameters are passed, the defaults are used. /// </summary> /// <param name="baudRate">The baud rate for the serail port. Defaulted to 38400.</param> /// <param name="parity">Specifies the parity bit for the serial port. Defaulted to none.</param> /// <param name="stopBits">Specifies the number of stop bits used on the serial port. Defaulted to one.</param> /// <param name="dataBits">The number of data bits. Defaulted to 8.</param> /// <param name="flowControl">Specifies if the serial port should use flow control. Defaulted to not use.</param> public void Initialize(int baudRate = 38400, GTI.Serial.SerialParity parity = GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits stopBits = GTI.Serial.SerialStopBits.One, int dataBits = 8, GTI.Serial.HardwareFlowControl flowControl = GTI.Serial.HardwareFlowControl.NotRequired) { // Set up serial port. serialPort = new GTI.Serial(socket, baudRate, parity, stopBits, dataBits, flowControl, this); serialPort.Open(); // Subscribe to events. //serialPort.DataReceived += new GTI.Serial.DataReceivedEventHandler(serialPort_DataReceived); //serialPort.LineReceived += new GTI.Serial.LineReceivedEventHandler(serialPort_LineReceived); }
/// <summary> /// Initializes the serial port to the passed in parameters. If no parameters are passed, the defaults are used. /// </summary> /// <param name="baudRate">The baud rate for the serail port. Defaulted to 38400.</param> /// <param name="parity">Specifies the parity bit for the serial port. Defaulted to none.</param> /// <param name="stopBits">Specifies the number of stop bits used on the serial port. Defaulted to one.</param> /// <param name="dataBits">The number of data bits. Defaulted to 8.</param> public GTI.Serial Initialize(int baudRate = 38400, GTI.Serial.SerialParity parity = GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits stopBits = GTI.Serial.SerialStopBits.One, int dataBits = 8) { this.port = new GTI.Serial(this.socket, baudRate, parity, stopBits, dataBits, GTI.Serial.HardwareFlowControl.NotRequired, this); this.port.Open(); return(this.port); }