Serial port and GPS

Serial Class

Encapsulates serial port operations

For a list of all members of this type, see Serial Members.

System.Object
   serial.Serial
      serial.Serial2IP
      serial.SerialGPS

[Visual Basic]
Public Class Serial
[C#]
public class Serial

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Open, close, read and write operations on the serial port. No event driven, continous reading of serial ports in a thread with predefined timeout. This makes this class available to mono and to some broken implementations on Windows CE.

Example

The following example defines method readCallback() executed from the serial port reading thread, which prints the lines from the serial port to the standard output. Parallelly to the reading operations the method Main() also reads lines from the standard input and sends them directly to the serial port. The example program opens the serial port COM4, this is usually the GPS intermediate driver (GPSID) on HTC3300. Please be aware, that the port are differently named on different platforms, for example COM1: on desktop windows systems, /dev/ttyS0 on linux or COM1 on many PDAs. The list of valid port names can be retrieved from static property Serial.COMPORTS.

[C#]
 using System;
 using System.Collections;
 using serial;
 public class Test {
   private static void readCallback(ArrayList arr) {
     foreach(object o in arr) Console.WriteLine(o);
   }
   public static void Main() {
     Serial s;
     string str;

     s = new Serial();
     s.PortName = "COM4";
     s.RdLineCb = new ReadLineDelegate(Test.readCallback);
     s.Open();
     s.Read = true;
     while ((str = Console.ReadLine()) != null && str != "quit") {
       s.Write(str);
     }
     s.Close();
   }
 }
 
Additionally to the property RdLineCb the property RdByteCb defines defines a callback for direct handling of byte arrays read from the port.

Requirements

Namespace: serial

Assembly: s2ip (in s2ip.exe)

See Also

Serial Members | serial Namespace