Simply3DScan
ArduinoConnection.ArduinoCommands Class Reference

Class for detecting an arduino and sending commands to it More...

Public Member Functions

 ArduinoCommands (int baudRate, string portString="")
 Initializes a new instance of the ArduinoCommands class. More...
 
string FindComPort ()
 Finds the COM port used by arduino More...
 
void ActivateLaser (bool on=true)
 Activates the laser. More...
 
void ActivateLight (bool on, int hue)
 Activates the light. More...
 
void RotateTurnTableCw (int steps)
 Rotates the turn table clockwise. More...
 
void RotateTurnTableCcw (int steps)
 Rotates the turn table counter clockwise. More...
 
void RotateLaserCw (int steps)
 Rotates the laser clockwise. More...
 
void RotateLaserCcw (int steps)
 Rotates the laser counter clockwise. More...
 
void EnableMicroStepping ()
 Enables the micro stepping. More...
 
void DisableMicroStepping ()
 Disables the micro stepping. More...
 

Properties

bool PortFound [get]
 Gets a value indicating whether [port found]. More...
 
string PortString [get]
 Gets the port string. More...
 

Detailed Description

Class for detecting an arduino and sending commands to it

Definition at line 13 of file ArduinoCommands.cs.

Constructor & Destructor Documentation

ArduinoConnection.ArduinoCommands.ArduinoCommands ( int  baudRate,
string  portString = "" 
)

Initializes a new instance of the ArduinoCommands class.

Parameters
baudRateThe baud rate.
portStringTh port string.

Definition at line 42 of file ArduinoCommands.cs.

43  {
44  Singleton<Logger>.Instance.LogInfo($"Starting arduino connection with baudrate:{baudRate}");
45 
46  this.baudRate = baudRate;
47  if (String.IsNullOrEmpty(portString))
48  this.FindComPort();
49  else
50  {
51  this.PortString = portString;
52  this.currentPort = new SerialPort(this.PortString, baudRate) {ReadTimeout = 2000};
53  }
54 
55  if (null != this.currentPort)
56  this.currentPort.ErrorReceived += this.CurrentPortOnErrorReceived;
57 
58  }
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
string PortString
Gets the port string.
static T Instance
Gets the instance.
Definition: Singleton.cs:27
string FindComPort()
Finds the COM port used by arduino

Here is the call graph for this function:

Member Function Documentation

void ArduinoConnection.ArduinoCommands.ActivateLaser ( bool  on = true)

Activates the laser.

Parameters
onif set to true [on].

Definition at line 132 of file ArduinoCommands.cs.

133  {
134  this.SendCommand(@on
135  ? CommandRepresentations.EnableLaserCommand
136  : CommandRepresentations.DisableLaserCommand);
137  }

Here is the caller graph for this function:

void ArduinoConnection.ArduinoCommands.ActivateLight ( bool  on,
int  hue 
)

Activates the light.

Parameters
onif set to true [on].
hueThe hue.

Definition at line 145 of file ArduinoCommands.cs.

146  {
147  if (on)
148  this.SendCommand(CommandRepresentations.EnableLightCommand, hue);
149  else
150  this.SendCommand(CommandRepresentations.DisableLightCommand);
151  }
void ArduinoConnection.ArduinoCommands.DisableMicroStepping ( )

Disables the micro stepping.

Definition at line 206 of file ArduinoCommands.cs.

207  {
208  this.SendCommand(CommandRepresentations.DisableMicroSteppingCommand);
209  }
void ArduinoConnection.ArduinoCommands.EnableMicroStepping ( )

Enables the micro stepping.

Definition at line 197 of file ArduinoCommands.cs.

198  {
199  this.SendCommand(CommandRepresentations.EnableMicroSteppingCommand);
200  }
string ArduinoConnection.ArduinoCommands.FindComPort ( )

Finds the COM port used by arduino

  • prerequisit: sketch must run on arduino and arduino must be powered
Returns

Definition at line 83 of file ArduinoCommands.cs.

84  {
85  try
86  {
87  string[] ports = SerialPort.GetPortNames();
88  foreach (string port in ports)
89  {
90  string testPort = port;
91  Task<string> detectPort = Task<string>.Factory.StartNew(() =>
92  {
93  Singleton<Logger>.Instance.LogInfo($"Testing COM port:{testPort}");
94  SerialPort serialPort = new SerialPort(testPort, this.baudRate) {ReadTimeout = 2000};
95  return this.DetectArduino(serialPort) ? testPort : String.Empty;
96  });
97 
98  if (detectPort.Wait(5000))
99  {
100 
101  string detectedPort = detectPort.Result;
102 
103  if (String.IsNullOrEmpty(detectedPort))
104  this.PortFound = false;
105  else
106  {
107  Singleton<Logger>.Instance.LogInfo($"Using Arduino on COM port:{detectedPort}");
108  this.PortString = detectedPort;
109  this.PortFound = true;
110  this.currentPort = new SerialPort(testPort, this.baudRate) {ReadTimeout = 2000};
111  return this.PortString;
112  }
113  }
114  else
115  {
116  this.PortFound = false;
117  }
118  }
119  }
120  catch (Exception ex)
121  {
122  Singleton<Logger>.Instance.LogException(ex);
123  }
124  return string.Empty;
125  }
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
string PortString
Gets the port string.
static T Instance
Gets the instance.
Definition: Singleton.cs:27
bool PortFound
Gets a value indicating whether [port found].

Here is the caller graph for this function:

void ArduinoConnection.ArduinoCommands.RotateLaserCcw ( int  steps)

Rotates the laser counter clockwise.

Parameters
stepsThe steps.

Definition at line 188 of file ArduinoCommands.cs.

189  {
190  this.SendCommand(CommandRepresentations.RotateLaserCcwCommand, steps);
191  }

Here is the caller graph for this function:

void ArduinoConnection.ArduinoCommands.RotateLaserCw ( int  steps)

Rotates the laser clockwise.

Parameters
stepsThe steps.

Definition at line 178 of file ArduinoCommands.cs.

179  {
180  this.SendCommand(CommandRepresentations.RotateLaserCwCommand, steps);
181  }

Here is the caller graph for this function:

void ArduinoConnection.ArduinoCommands.RotateTurnTableCcw ( int  steps)

Rotates the turn table counter clockwise.

Parameters
stepsThe steps.

Definition at line 168 of file ArduinoCommands.cs.

169  {
170  this.SendCommand(CommandRepresentations.RotateTurnTableCcwCommand, steps);
171  }
void ArduinoConnection.ArduinoCommands.RotateTurnTableCw ( int  steps)

Rotates the turn table clockwise.

Parameters
stepsThe steps.

Definition at line 158 of file ArduinoCommands.cs.

159  {
160  this.SendCommand(CommandRepresentations.RotateTurnTableCwCommand, steps);
161  }

Here is the caller graph for this function:

Property Documentation

bool ArduinoConnection.ArduinoCommands.PortFound
get

Gets a value indicating whether [port found].

true if [port found]; otherwise, false.

Definition at line 25 of file ArduinoCommands.cs.

string ArduinoConnection.ArduinoCommands.PortString
get

Gets the port string.

The port string.

Definition at line 33 of file ArduinoCommands.cs.


The documentation for this class was generated from the following file: