Quantcast
Channel: Main Sequence Software - Latest posts
Viewing all articles
Browse latest Browse all 52138

API calls using example code from documentation fail

$
0
0

Hello SGP experts,

I am currently implementing a little application in c# which should call the SGP API to start imaging. I found the code snippet in the documentation and thought, I give it a try. But I never get any answer from the software when I send a request to it. Here is my little modified code. The request.Resource is different, but I also tried to use the original code, which was also not working. Any idea what I am missing? The code compiles, but when executed I never get past the "SgCaptureImageResponse good is always "null" problem.

Thx for your help
Ralf

		string temp_image_URL = @"C:\Users\Ralf\Desktop\MM\mm_exposure.fit";
		SgImage img = new SgImage() { BinningMode = 1, ExposureLength = 5, FrameType = "Light", Path = temp_image_URL };
		Guid imgReceipt;
		if (!TakeImage(img, out imgReceipt))
		   return;



	private static bool TakeImage(SgImage img, out Guid receipt)
	{

		RestSharp.IRestClient client = new RestClient();
		var request = new RestRequest(Method.POST);
		request.Resource = "http://localhost:59590/json/reply/SgCaptureImage";
		request.RequestFormat = DataFormat.Json;
		request.AddHeader("Content-Type", "application/json");
		request.AddBody(img);
	
	   IRestResponse response = client.Execute(request);
	
	   SgCaptureImageResponse good = JsonConvert.DeserializeObject<SgCaptureImageResponse>(response.Content);

	   if (!good.Success)
	   {
	       Console.WriteLine(good.Message);
	       receipt = Guid.Empty;
	       return false;
	   }
	
	   receipt = good.Receipt;
	   return true;
	}
	
	private static bool GetImagePath(Guid receipt, out string path)
	{
	   
		const string BaseUrl = "http://localhost:59590/";
		
		RestClient client = new RestClient(BaseUrl);
		
		// RestSharp.IRestClient client = new RestClient();

		var request = new RestRequest(Method.GET);
	   request.Resource = BaseUrl + "imagepath/" + receipt;
	   request.RequestFormat = DataFormat.Json;
	   request.AddHeader("Accept", "application/json");
	
	   IRestResponse response = client.Execute(request);
	   SgGenericResponse good = JsonConvert.DeserializeObject<SgGenericResponse>(response.Content);
	
	   if (!good.Success)
	   {
	       Console.WriteLine(good.Message);
	       path = "NA";
	       return false;
	   }
	
	   // When successful, Message will contain the path to the image (this might not be the same path you passed in)
	   path = good.Message;
	   return true;
	}
	
	// DTOs
	public class SgGenericResponse
	{
	   public bool Success { get; set; }
	   public string Message { get; set; }
	}

	public class SgCaptureImageResponse
	{
	   public bool Success { get; set; }
	   public string Message { get; set; }
	   public Guid Receipt { get; set; }
	}

	
	public class SgImage
	{
	   public int BinningMode { get; set; }
	   public int IsoMode { get; set; }
	   public int ExposureLength { get; set; }
	   public string Gain { get; set; }
	   public string Speed { get; set; }
	   public string FrameType { get; set; }
	   public string Path { get; set; }
	}

Viewing all articles
Browse latest Browse all 52138

Trending Articles