2016年11月30日 星期三

PLC SLMP Protocol的用法 (一)



在Receive loop的動作於一般TCP server的動作不同
一般server都會有ack的回應封包,所以可以判定資料封包是否有收完全

SLMP沒有這動作
PLC單純只會回應client端send的封包,資料封包丟完後無ACK的
簡單講也就是non-handshaking 的server啦

以下是code

private void OnReceive(System.IAsyncResult ar)
        {
            try
            {
                // Read data from the remote device.
                int bytesRead = tcpAsyn.EndReceive(ar);

                if (bytesRead > 0)
                {
                    // There might be more data, so store the data received so far.
                    asb.Append(Encoding.ASCII.GetString(tcpAsyClBuffer, 0, bytesRead));

                    // Get the rest of the data.
                    tcpAsyn.BeginReceive(tcpAsyClBuffer, 0,tcpAsyClBuffer.Length , 0,
                        new AsyncCallback(OnReceive), tcpAsyn);
                }
                else
                {
                    // All the data has arrived; put it in response.
                    if (asb.Length > 1)
                    {
                        response = asb.ToString();
                    }
                    //add do_packet
                    do_packet();
                    // Signal that all bytes have been received.
                    receiveDone.Set();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                //Console.ReadKey(true);
            }
        }

上面的一般tcp server的用法
這樣是無法正常運作的喔

2016年4月15日 星期五

Remote Debug

首先要安裝軟體在想要debug的電腦上. 

軟體會放在在debug端,建一個使用者MyName,當然權限越高越好。

 執行Remote Debugging Monitor,打開Toos\Option,可以發現Server Name,For example MyName@OtherPC。 

會到visual studio,開你的C++ Solution,打開Project\Property\Linker,Output File設為"\\OtherPC\c$\Test.exe" 

5:在C++ Solution,打開Project\Property\Debugging 你應該可以看到Debugger to launch的預設值應該是 "Local Windows Debugger",把它改為"Remote Window Debugger"。

 5.1:在Remote Command設定為"\\OtherPC\C$\Test\Test.exe" 

5.2:在Remote Server Name設定為"MyName@OtherPC" 如果一切順利,你應該可以開始Remote Debugging。

 P.S. 如果發生以下訊息"Unable to start debugging",那是因為Debugging Server無回應,請確定OtherPC的Remote Debugging Server是否已經打開. 

有時開始Remote Debugging時,Visual Studio會發出一個Dialog Box告訴你無法Remote Debugging,這時請檢查"系統管理工具\本機安全性原則工具\安全性設定\本機原則\安全性選項\網路存取:共用和安全性模式用於本機帳戶"的設定. 如果是"僅適用於來賓-本機使用者以Guest驗證"請改為"傳統-本機使用者以自身身份驗證"。

引用:http://blog.xuite.net/xujy280/twblog/127304235-Remote+Debug(For+Visual+Studio).