c:\Program Files\QxSoft\CMM-Manager 2020>CMMMgr.exe /pipe c:\Program Files\QxSoft\CMM-Manager 2020> |
using System.IO.Pipes; class Program { static void Main(string[] args) { var client = new NamedPipeClientStream(".", "CMMManagerDataTransferPipe"); client.Connect(20000); } } |
using System; using System.Text; using System.IO; using System.IO.Pipes; class Program { static void Main(string[] args) { var client = new NamedPipeClientStream(".", "CMMManagerDataTransferPipe"); client.Connect(20000); // Create the reader and writer streams StreamReader reader = new StreamReader(client, Encoding.Unicode); StreamWriter writer = new StreamWriter(client, Encoding.Unicode); // Write to the pipe. Write(writer, "0002 EnumVersions()"); // Read from the pipe. string response = Read(reader); // Output response Console.Write(response); } static void Write(StreamWriter writer, string command) { writer.WriteLine(command); writer.Flush(); } static string Read(StreamReader reader) { string response = reader.ReadLine(); return response; } } |
C:\PipeClient>PipeClient.exe 0002 #1.0, #1.1, #1.2 |
using System; using System.Text; using System.IO; using System.IO.Pipes; class Program { static void Main(string[] args) { string[] commands = { "01 GetVersion()", "02 EnumVersions()", "03 SetVersion(#1.2)" }; var client = new NamedPipeClientStream(".", "CMMManagerDataTransferPipe"); client.Connect(20000); // Create the reader and writer streams StreamReader reader = new StreamReader(client, Encoding.Unicode); StreamWriter writer = new StreamWriter(client, Encoding.Unicode); int cmdNo = 0; int numberOfCmds = commands.Length; while (true) { string command = ""; if (0 >= numberOfCmds) { Console.WriteLine("\n<Enter message to send to server:>"); // Read message from the console. command = Console.ReadLine(); } else { // Use message from the command line argument. command = commands[cmdNo]; cmdNo++; numberOfCmds--; } Console.WriteLine("\n<Sending message to server as follows:>"); // Write to the pipe. Write(writer, command); Console.WriteLine(command); Console.WriteLine("\n<Message sent to server, receiving reply as follows:>"); // Read from the pipe. string response = Read(reader); // Output response Console.Write(response); } } static void Write(StreamWriter writer, string command) { writer.WriteLine(command); writer.Flush(); } static string Read(StreamReader reader) { string response = reader.ReadLine(); return response; } } |
C:\PipeClient>PipeClient.exe <Sending message to server as follows:> 01 GetVersion() <Message sent to server, receiving reply as follows:> 01 #1.0 <Sending message to server as follows:> 02 EnumVersions() <Message sent to server, receiving reply as follows:> 02 #1.0, #1.1, #1.2 <Sending message to server as follows:> 03 SetVersion(#1.2) <Message sent to server, receiving reply as follows:> 03 #1.2 <Enter message to send to server:> 01 GetScalePosition() <Sending message to server as follows:> 01 GetScalePosition() <Message sent to server, receiving reply as follows:> 01 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, nan, nan <Enter message to send to server:> |