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(String.Format("Starting arduino connection with baudrate:{0}", 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 133 of file ArduinoCommands.cs.

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

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 146 of file ArduinoCommands.cs.

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

Disables the micro stepping.

Definition at line 207 of file ArduinoCommands.cs.

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

Enables the micro stepping.

Definition at line 198 of file ArduinoCommands.cs.

199  {
200  this.SendCommand(CommandRepresentations.EnableMicroSteppingCommand);
201  }
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(String.Format("Testing COM port:{0}", 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(String.Format("Using Arduino on COM port:{0}",
108  detectedPort));
109  this.PortString = detectedPort;
110  this.PortFound = true;
111  this.currentPort = new SerialPort(testPort, this.baudRate) {ReadTimeout = 2000};
112  return this.PortString;
113  }
114  }
115  else
116  {
117  this.PortFound = false;
118  }
119  }
120  }
121  catch (Exception ex)
122  {
123  Singleton<Logger>.Instance.LogException(ex);
124  }
125  return string.Empty;
126  }
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 189 of file ArduinoCommands.cs.

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

Here is the caller graph for this function:

void ArduinoConnection.ArduinoCommands.RotateLaserCw ( int  steps)

Rotates the laser clockwise.

Parameters
stepsThe steps.

Definition at line 179 of file ArduinoCommands.cs.

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

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 169 of file ArduinoCommands.cs.

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

Rotates the turn table clockwise.

Parameters
stepsThe steps.

Definition at line 159 of file ArduinoCommands.cs.

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

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: