Skip to content

Commit

Permalink
Signed-off-by: matt <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantAsylum committed Jun 10, 2020
1 parent 52a432c commit 69c2dcb
Show file tree
Hide file tree
Showing 12 changed files with 512 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Tractor/AutoDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ static void BuildDictionary()
Dic.Add("Minimum Current to Pass (A)", "The minimum current, in amps, required in order to pass the test.");
Dic.Add("Maximum Current to Pass (A)", "The maximum current, in amps, required in order to pass the test.");

Dic.Add("Minimum Voltage to Pass (V)", "The minimum voltage, in volts, required in order to pass the test.");
Dic.Add("Maximum Voltage to Pass (V)", "The maximum voltage, in volts, required in order to pass the test.");

Dic.Add("RMS Measurement Start (Hz)", "The starting frequency of the indicated RMS measurement. ");
Dic.Add("RMS Measurement Stop (Hz)", "The ending frequency of the indicated RMS measurement.");

Expand Down Expand Up @@ -206,6 +209,8 @@ static void BuildDictionary()
Dic.Add("Start Frequency (Hz)", "The starting frequency of the noise measurement for THD+N measurements.");
Dic.Add("Stop Frequency (Hz)", "The stopping frequency of the noise measurement for THD+N measurements.");

Dic.Add("Channel", "Specifies the DVM channel to make the measurement. On the QA351, valid channel numbers are 0 (Main) and 1 (Aux).");

Dic.Add("", "");
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Tractor/Com.QuantAsylum.Tractor.TestManagers/IVoltMeter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tractor.Com.QuantAsylum.Tractor.TestManagers
{
interface IVoltMeter
{
float GetVoltage(int channel);
}
}
146 changes: 146 additions & 0 deletions Tractor/Com.QuantAsylum.Tractor.TestManagers/QA351.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Com.QuantAsylum.Tractor.TestManagers;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Web.Script.Serialization;

namespace Tractor.Com.QuantAsylum.Tractor.TestManagers
{
class QA351 : IInstrument, IVoltMeter
{
static HttpClient Client = new HttpClient();

static string RootUrl;

public QA351()
{
SetRootUrl("http://localhost:9351");
}
void SetRootUrl(string rootUrl)
{
RootUrl = rootUrl;
Client = new HttpClient
{
BaseAddress = new Uri(RootUrl)
};
}

public bool ConnectToDevice(out string result)
{
// Nothing special to do for REST device
result = "";
return true;
}

public void CloseConnection()
{

}

public double GetVersion()
{
string result = GetSync(RootUrl + "/Status/Version", "Value");
return Convert.ToDouble(result);
}

public bool IsConnected()
{
// Do a version read and see if the correct version comes back
try
{
double current = GetVersion();
return true;
}
catch
{

}

return false;
}

public bool IsRunning()
{
return IsConnected();
}

public void LaunchApplication()
{

}

public void SetToDefaults()
{

}

public float GetVoltage(int channel)
{
if (channel < 0 || channel > 1)
throw new Exception("Invalid channel specified. The QA351 can support channel numbers of 0 (Main) and 1 (Aux)");

string result = GetSync(RootUrl + $"/Volts/{channel}", "Value");
float val = Convert.ToSingle(result);
return val;
}

/*******************************************************************/
/*********************** HELPERS for REST **************************/
/*******************************************************************/

private void PutSync(string url)
{
PutSync(url, "", 0);
}

/// <summary>
/// Synchronous PUT. This will throw an exception of the PUT fails for some reason
/// </summary>
/// <param name="url"></param>
/// <param name="token"></param>
/// <param name="value"></param>
private void PutSync(string url, string token, int value)
{
string json;

if (token != "")
json = string.Format("{{\"{0}\":{1}}}", token, value);
else
json = "{{}}";

StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

// We make the PutAsync synchronous via the .Result
var response = Client.PutAsync(url, content).Result;

// Throw an exception if not successful
response.EnsureSuccessStatusCode();
}

/// <summary>
/// Synchronous GET. This will throw an exception if the GET fails for some reason
/// </summary>
/// <param name="url"></param>
/// <param name="token"></param>
/// <returns></returns>
private string GetSync(string url, string token)
{
string content;

Client.DefaultRequestHeaders.Accept.Clear();
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = Client.GetAsync(url).Result;
response.EnsureSuccessStatusCode();
content = response.Content.ReadAsStringAsync().Result;
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
var result = jsSerializer.DeserializeObject(content);
Dictionary<string, object> dict = new Dictionary<string, object>();
dict = (Dictionary<string, object>)result;

return dict[token].ToString();
}
}
}
Loading

0 comments on commit 69c2dcb

Please sign in to comment.