예제 #1
0
        protected WndProcMessage GetReceivedMessage(ref Message m)
        {
            WndProcMessage rec = new WndProcMessage();

            rec.pdulength = Marshal.ReadInt32(m.LParam, 0);
            rec.pdu       = new byte[rec.pdulength];

            byte[] buffer = new byte[rec.pdulength + 4];
            Marshal.Copy(m.LParam, buffer, 0, buffer.Length);
            Buffer.BlockCopy(buffer, 4, rec.pdu, 0, rec.pdulength);

            return(rec);
        }
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM_M_CONNECTPLCSIM:
                ConnectPlcsimStatemachine();
                break;

            case WM_M_SENDDATA:
                if (m.LParam != IntPtr.Zero)
                {
                    if (m_PlcsimConnectionState == PlcsimConnectionState.Connected)
                    {
                        WndProcMessage msg = GetReceivedMessage(ref m);
                        SendDataToPlcsim(msg);
                    }
                }
                break;

            case WM_M_EXIT:
                if (m_PlcsimConnectionState == PlcsimConnectionState.Connected)
                {
                    m_PlcsimConnectionState = PlcsimConnectionState.DisconnectState1;
                    DisconnectPlcsimStatemachine();
                }
                break;

            case WM_SINEC:
                switch (m_PlcsimConnectionState)
                {
                case PlcsimConnectionState.NotConnected:
                case PlcsimConnectionState.ConnectState1:
                case PlcsimConnectionState.ConnectState2:
                case PlcsimConnectionState.ConnectState3:
                    ConnectPlcsimStatemachine();
                    break;

                case PlcsimConnectionState.Connected:
                    ReceiveFromPlcsimAndSendBack();
                    break;
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
예제 #3
0
        private static long WndProcDetour(IntPtr hWnd, uint msg, ulong wParam, long lParam)
        {
            // Ignore things not targeting the current window handle
            if (hWnd == WndProcHandler.hWnd)
            {
                var resp = WndProcMessage?.Invoke((WindowsMessage)msg, wParam, lParam);

                // Item1 is a bool, where true == capture event. If false, we're falling through default handling.
                if (resp.HasValue && resp.Value.Item1)
                {
                    return(resp.Value.Item2);
                }
            }

            return(NativeMethods.CallWindowProc(oldWndProcPtr, hWnd, msg, wParam, lParam));
        }
예제 #4
0
        private void SendDataToPlcsim(WndProcMessage msg)
        {
            if (++m_user >= 32000)
            {
                m_user = 1;
            }
            S7OexchangeBlock snd = GetNewS7OexchangeBlock(user: m_user, rb_type: 2, subsystem: 0x40, opcode: 6, response: 0xff);

            snd.offset_1 = 80;

            snd.application_block_opcode    = m_application_block_opcode;
            snd.application_block_subsystem = m_application_block_subsystem;

            snd.fill_length_1 = (ushort)msg.pdu.Length;
            snd.seg_length_1  = (ushort)msg.pdu.Length;

            snd.user_data_1 = new byte[SIZE_OF_USER_DATA_1];
            Array.Copy(msg.pdu, snd.user_data_1, msg.pdu.Length);

            SendS7OExchangeBlockToPlcsim(snd);
        }