Пример #1
0
        static void Main(string[] args)
        {
            // According to http://www.rialverde.com/en/hobbies/ERVPhys.html, the serial number for the MultiClamp in demo mode
            // is 00000000. Given the UI, I'm assuming this is a 2-channel device and the ID numbers are 0 and 1 or 1 and 2; in either
            // case, 1 seems like a safe bet.
            //
            uint uSerialNum = 0;
            uint uChannelID = 1;

            // Give command-line arguments a chance to override default serial # and channel ID
            //
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "/serial")
                    {
                        uSerialNum = UInt32.Parse(args[++i]);
                    }
                    if (args[i] == "/channel")
                    {
                        uChannelID = UInt32.Parse(args[++i]);
                    }
                }
            }

            Console.WriteLine("Registering for MultiClamp conversation...");
            int mctgOpenMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_OPEN_MESSAGE_STR);

            Console.WriteLine("MCTG_OPEN_MESSAGE_STR = {0}", mctgOpenMsg);
            int mctgCloseMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_CLOSE_MESSAGE_STR);

            Console.WriteLine("MCTG_CLOSE_MESSAGE_STR = {0}", mctgCloseMsg);
            int mctgReconnectMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_RECONNECT_MESSAGE_STR);

            Console.WriteLine("MCTG_RECONNECT_MSG_STR = {0}", mctgReconnectMsg);
            int mctgRequestMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_REQUEST_MESSAGE_STR);


            Console.WriteLine("Opening MultiClamp conversation...");
            UInt32 lParam = MulticlampInterop.MCTG_Pack700BSignalIDs(uSerialNum, uChannelID); // Pack the above two into an UInt32(?)
            int    result = Win32Interop.PostMessage((IntPtr)0xffff, mctgOpenMsg, (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);

            Console.WriteLine("result = {0}", result);


            Console.WriteLine("Registering for WM_COPYDATA messages....");
            Win32Interop.MessageEvents.WatchMessage(Win32Interop.WM_COPYDATA, (sender, evtArgs) =>
            {
                // WM_COPYDATA LPARAM is a pointer to a COPYDATASTRUCT structure
                Win32Interop.COPYDATASTRUCT cds = new Win32Interop.COPYDATASTRUCT();
                cds = (Win32Interop.COPYDATASTRUCT)
                      Marshal.PtrToStructure(evtArgs.Message.LParam, typeof(Win32Interop.COPYDATASTRUCT));

                // WM_COPYDATA structure (COPYDATASTRUCT)
                // dwData -- RegisterWindowMessage(MCTG_REQUEST_MESSAGE_STR)
                // cbData -- size (in bytes) of the MC_TELEGRAPH_DATA structure being sent
                // lpData -- MC_TELEGRAPH_DATA*
                MulticlampInterop.MC_TELEGRAPH_DATA mtd = new MulticlampInterop.MC_TELEGRAPH_DATA();
                mtd = (MulticlampInterop.MC_TELEGRAPH_DATA)Marshal.PtrToStructure(cds.lpData, typeof(MulticlampInterop.MC_TELEGRAPH_DATA));
                MulticlampInterop.MulticlampData md = new MulticlampInterop.MulticlampData(mtd);
                Console.WriteLine("Received WM_COPYDATA message; cracking it: {0}", md);
            });

            Console.WriteLine("Registering for MCTG_RECONNECT_MESSAGE messages...");
            Win32Interop.MessageEvents.WatchMessage(mctgReconnectMsg, (sndr, eArgs) =>
            {
                Console.WriteLine("Received MCTG_RECONNECT_MESSAGE: {0}", eArgs.Message);

                if ((IntPtr)lParam == eArgs.Message.LParam)
                {
                    Console.WriteLine("Opening MultiClamp conversation...");
                    int localResult = Win32Interop.PostMessage((IntPtr)0xffff, mctgOpenMsg, (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
                    Console.WriteLine("result = {0}", localResult);

                    Console.WriteLine("Registering for WM_COPYDATA messages....");
                    Win32Interop.MessageEvents.WatchMessage(Win32Interop.WM_COPYDATA, (sender, evtArgs) =>
                    {
                        // WM_COPYDATA LPARAM is a pointer to a COPYDATASTRUCT structure
                        Win32Interop.COPYDATASTRUCT cds = new Win32Interop.COPYDATASTRUCT();
                        cds = (Win32Interop.COPYDATASTRUCT)
                              Marshal.PtrToStructure(evtArgs.Message.LParam, typeof(Win32Interop.COPYDATASTRUCT));

                        // WM_COPYDATA structure (COPYDATASTRUCT)
                        // dwData -- RegisterWindowMessage(MCTG_REQUEST_MESSAGE_STR)
                        // cbData -- size (in bytes) of the MC_TELEGRAPH_DATA structure being sent
                        // lpData -- MC_TELEGRAPH_DATA*
                        MulticlampInterop.MC_TELEGRAPH_DATA mtd = new MulticlampInterop.MC_TELEGRAPH_DATA();
                        mtd = (MulticlampInterop.MC_TELEGRAPH_DATA)Marshal.PtrToStructure(cds.lpData, typeof(MulticlampInterop.MC_TELEGRAPH_DATA));
                        MulticlampInterop.MulticlampData md = new MulticlampInterop.MulticlampData(mtd);
                        Console.WriteLine("Received WM_COPYDATA message; cracking it: {0}", md);
                    });
                }
            });


            Console.WriteLine("Requesting telegraph data...");
            result = Win32Interop.PostMessage(Win32Interop.HWND_BROADCAST, mctgRequestMsg,
                                              (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
            Console.WriteLine("  result = {0}", result);

            //var t = new Thread(() => Thread.Sleep(10 * 1000));
            //t.Start();

            Console.WriteLine("Press Enter to quit....");
            Console.ReadLine();

            Console.WriteLine("Closing MultiClamp conversation...");
            result = Win32Interop.PostMessage((IntPtr)0xffff, mctgCloseMsg, (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
            Console.WriteLine("result = {0}", result);
        }
Пример #2
0
        static void Main(string[] args)
        {
            // According to http://www.rialverde.com/en/hobbies/ERVPhys.html, the serial number for the MultiClamp in demo mode
            // is 00000000. Given the UI, I'm assuming this is a 2-channel device and the ID numbers are 0 and 1 or 1 and 2; in either
            // case, 1 seems like a safe bet.
            //
            uint uSerialNum = 0;
            uint uChannelID = 1;

            // Give command-line arguments a chance to override default serial # and channel ID
            //
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "/serial")
                        uSerialNum = UInt32.Parse(args[++i]);
                    if (args[i] == "/channel")
                        uChannelID = UInt32.Parse(args[++i]);
                }
            }

            Console.WriteLine("Registering for MultiClamp conversation...");
            int mctgOpenMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_OPEN_MESSAGE_STR);
            Console.WriteLine("MCTG_OPEN_MESSAGE_STR = {0}", mctgOpenMsg);
            int mctgCloseMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_CLOSE_MESSAGE_STR);
            Console.WriteLine("MCTG_CLOSE_MESSAGE_STR = {0}", mctgCloseMsg);
            int mctgReconnectMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_RECONNECT_MESSAGE_STR);
            Console.WriteLine("MCTG_RECONNECT_MSG_STR = {0}", mctgReconnectMsg);
            int mctgRequestMsg = Win32Interop.RegisterWindowMessage(MulticlampInterop.MCTG_REQUEST_MESSAGE_STR);

            Console.WriteLine("Opening MultiClamp conversation...");
            UInt32 lParam = MulticlampInterop.MCTG_Pack700BSignalIDs(uSerialNum, uChannelID); // Pack the above two into an UInt32(?)
            int result = Win32Interop.PostMessage((IntPtr)0xffff, mctgOpenMsg, (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
            Console.WriteLine("result = {0}", result);

            Console.WriteLine("Registering for WM_COPYDATA messages....");
            Win32Interop.MessageEvents.WatchMessage(Win32Interop.WM_COPYDATA, (sender, evtArgs) =>
                {
                    // WM_COPYDATA LPARAM is a pointer to a COPYDATASTRUCT structure
                    Win32Interop.COPYDATASTRUCT cds = new Win32Interop.COPYDATASTRUCT();
                    cds = (Win32Interop.COPYDATASTRUCT)
                        Marshal.PtrToStructure(evtArgs.Message.LParam, typeof(Win32Interop.COPYDATASTRUCT));

                    // WM_COPYDATA structure (COPYDATASTRUCT)
                    // dwData -- RegisterWindowMessage(MCTG_REQUEST_MESSAGE_STR)
                    // cbData -- size (in bytes) of the MC_TELEGRAPH_DATA structure being sent
                    // lpData -- MC_TELEGRAPH_DATA*
                    MulticlampInterop.MC_TELEGRAPH_DATA mtd = new MulticlampInterop.MC_TELEGRAPH_DATA();
                    mtd = (MulticlampInterop.MC_TELEGRAPH_DATA)Marshal.PtrToStructure(cds.lpData, typeof(MulticlampInterop.MC_TELEGRAPH_DATA));
                    MulticlampInterop.MulticlampData md = new MulticlampInterop.MulticlampData(mtd);
                    Console.WriteLine("Received WM_COPYDATA message; cracking it: {0}", md);
                });

            Console.WriteLine("Registering for MCTG_RECONNECT_MESSAGE messages...");
            Win32Interop.MessageEvents.WatchMessage(mctgReconnectMsg, (sndr, eArgs)=>
                                                                          {
                                                                              Console.WriteLine("Received MCTG_RECONNECT_MESSAGE: {0}", eArgs.Message);

                                                                              if ((IntPtr)lParam == eArgs.Message.LParam)
                                                                              {
                                                                                  Console.WriteLine("Opening MultiClamp conversation...");
                                                                                  int localResult = Win32Interop.PostMessage((IntPtr)0xffff, mctgOpenMsg, (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
                                                                                  Console.WriteLine("result = {0}", localResult);

                                                                                  Console.WriteLine("Registering for WM_COPYDATA messages....");
                                                                                  Win32Interop.MessageEvents.WatchMessage(Win32Interop.WM_COPYDATA, (sender, evtArgs) =>
                                                                                  {
                                                                                      // WM_COPYDATA LPARAM is a pointer to a COPYDATASTRUCT structure
                                                                                      Win32Interop.COPYDATASTRUCT cds = new Win32Interop.COPYDATASTRUCT();
                                                                                      cds = (Win32Interop.COPYDATASTRUCT)
                                                                                          Marshal.PtrToStructure(evtArgs.Message.LParam, typeof(Win32Interop.COPYDATASTRUCT));

                                                                                      // WM_COPYDATA structure (COPYDATASTRUCT)
                                                                                      // dwData -- RegisterWindowMessage(MCTG_REQUEST_MESSAGE_STR)
                                                                                      // cbData -- size (in bytes) of the MC_TELEGRAPH_DATA structure being sent
                                                                                      // lpData -- MC_TELEGRAPH_DATA*
                                                                                      MulticlampInterop.MC_TELEGRAPH_DATA mtd = new MulticlampInterop.MC_TELEGRAPH_DATA();
                                                                                      mtd = (MulticlampInterop.MC_TELEGRAPH_DATA)Marshal.PtrToStructure(cds.lpData, typeof(MulticlampInterop.MC_TELEGRAPH_DATA));
                                                                                      MulticlampInterop.MulticlampData md = new MulticlampInterop.MulticlampData(mtd);
                                                                                      Console.WriteLine("Received WM_COPYDATA message; cracking it: {0}", md);
                                                                                  });
                                                                              }
                                                                          });

            Console.WriteLine("Requesting telegraph data...");
            result = Win32Interop.PostMessage(Win32Interop.HWND_BROADCAST, mctgRequestMsg,
                                                  (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
            Console.WriteLine("  result = {0}", result);

            //var t = new Thread(() => Thread.Sleep(10 * 1000));
            //t.Start();

            Console.WriteLine("Press Enter to quit....");
            Console.ReadLine();

            Console.WriteLine("Closing MultiClamp conversation...");
            result = Win32Interop.PostMessage((IntPtr)0xffff, mctgCloseMsg, (IntPtr)Win32Interop.MessageEvents.WindowHandle, (IntPtr)lParam);
            Console.WriteLine("result = {0}", result);
        }