Below is a simple example of an integration of the PIXL client in C# 7.0. This runs the following actions:
To test this example:
A simple example showing how to connect to PIXL and run an experiment. |
Copy Code
|
---|---|
using System; using System.Linq; using SI.PIXL.Client.Enums; using SI.PIXL.Client.Structs.CommandResponse; using SI.PIXL.Client.Structs.Instructions; using SI.PIXL.Client.Structs.PlateHandling; namespace SI.PIXL.Client.SimpleExample { class Program { static void Main(string[] args) { try { // create a channel for communication with the PIXL - the IP address and port need to match the PIXL you are connecting to var channel = PIXLClient.GetPIXLChannel("192.168.100.90", 50052); // create a new instance of the PIXL class with the specified channel var pixl = new PIXLClient(channel); // display the status on the console Console.WriteLine($"Connected to PIXL, operational status is {pixl.OperationalStatus.CommandStatus}."); // if running if (pixl.OperationalStatus.CommandStatus == CommandStatus.Running) { // call abort to cancel any pending operation Console.WriteLine("Calling abort..."); var abortResult = pixl.Abort(); HandleResponse(abortResult); } // reset the PIXL Console.WriteLine("Calling reset, this may take a little while..."); var resetResult = pixl.Reset().Result; HandleResponse(resetResult); // initialise the PIXL now that it has finished resetting Console.WriteLine("Starting initialise..."); var initialiseResult = pixl.Initialise().Result; HandleResponse(initialiseResult); // create a source plate var sourcePlate = new Plate("Source_Plate_1", PlateTypes.PlusPlate, PlateRoles.Source); // TODO: do any actions required to load a source PlusPlate into the PIXLs black bay here. For example a robotic arm would load the plate at this point // inform the PIXL the plate has been loaded pixl.PlateLoaded(Bays.Black, sourcePlate.ID, sourcePlate.Type, sourcePlate.Role); // use the colony detection workflow to find colonies Console.WriteLine("Running colony detection workflow..."); var colonyDetectionResult = pixl.RunColonyDetectionWorkflow("Test project", "Empty").Result; HandleResponse(colonyDetectionResult.Result); // display some info on the detected colonies Console.WriteLine($"Detected {colonyDetectionResult.ProgramInformation.ColonyInformation.Length} colonies, all data has been logged at {colonyDetectionResult.TrackingPath}."); // select the 3 biggest colonies var biggestColonies = colonyDetectionResult.ProgramInformation.ColonyInformation.OrderBy(x => x.Diameter).Reverse().Take(3).ToArray(); // create a target plate var targetPlate = new Plate("Target_Plate_1", PlateTypes.PlusPlate_96, PlateRoles.Target); // TODO: do any actions required to load a target PlusPlate into the PIXLs red bay here. For example a robotic arm would load the plate at this point // inform the PIXL the plate has been loaded pixl.PlateLoaded(Bays.Red, targetPlate.ID, targetPlate.Type, targetPlate.Role); // create instructions for pinning the 3 colonies from the source plate to the target plate var pinnings = new[] { new ConsecutivePinningInstruction(new[] { new PinningInstruction(sourcePlate, biggestColonies[0].X, biggestColonies[0].Y), new PinningInstruction(targetPlate, 1, 1) }), new ConsecutivePinningInstruction(new[] { new PinningInstruction(sourcePlate, biggestColonies[1].X, biggestColonies[1].Y), new PinningInstruction(targetPlate, 1, 2) }), new ConsecutivePinningInstruction(new[] { new PinningInstruction(sourcePlate, biggestColonies[2].X, biggestColonies[2].Y), new PinningInstruction(targetPlate, 1, 3) }) }; // use the re-array workflow to pin colonies from the source plate to the target plate Console.WriteLine("Running re-array workflow..."); var rearrayResult = pixl.RunRearrayWorkflow("Test project", "Empty", string.Empty, pinnings).Result; HandleResponse(rearrayResult.Result); // TODO: do any actions required to remove the plates from the PIXLs black and red bays. For example a robotic arm would remove all plates at this point // inform the PIXL the plates have been removed pixl.PlateRemoved(Bays.Black); pixl.PlateRemoved(Bays.Red); Console.WriteLine($"Example complete! Pinned {rearrayResult.ProgramInformation.Pinnings.Length} colonies. Press any key to exit."); } catch (Exception e) { Console.WriteLine(e); } Console.ReadKey(); } /// <summary> /// Handle a response from the Api. /// </summary> /// <param name="response">The response.</param> private static void HandleResponse(ApiCommandResponse response) { // display on console Console.WriteLine(response.Message); // if failed, throw exception if (!response.IsSuccess) throw new Exception($"Unexpected result: {response.Code}: {response.Message}"); } } } |