Click or drag to resize
Solid Soils Solutions

EnhancedSerialConnectionFindSerialConnection Method (String, String)

[This is preliminary documentation and is subject to change.]

Finds a serial connection to a device supporting plain serial communications.

Namespace:  Solid.Arduino
Assembly:  Solid.Arduino (in Solid.Arduino.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public static ISerialConnection FindSerialConnection(
	string query,
	string expectedReply
)

Parameters

query
Type: SystemString
The query text used to inquire the connection
expectedReply
Type: SystemString
The reply text the connected device is expected to respond with

Return Value

Type: ISerialConnection
A ISerialConnection instance or null if no connection is found
Remarks

This method searches all available serial ports until it finds a working serial connection. For every available serial port an attempt is made to open a connection at a range of common baudrates. The connection is tested by sending the query string passed to this method.

The connected device is expected to respond by sending the reply string passed to this method. When the string received is equal to the expected reply string, the connection is regarded to be valid.

Examples
The Arduino sketch below can be used to demonstrate this method. Upload the sketch to your Arduino device.
 1char query[] = "Hello?";
 2char reply[] = "Arduino!";
 3
 4void setup()
 5{
 6  Serial.begin(9600);
 7  while (!Serial) {}
 8}
 9
10void loop()
11{
12  if (Serial.find(query))
13  {
14    Serial.println(reply);
15  }
16  else
17  {
18    Serial.println("Listening...");
19    Serial.flush();
20  }
21
22  delay(25);
23}
See Also