Exemplo n.º 1
0
        private void ConnMac()
        {
            LogPrint("当前仪器连接方式为客户端请求方式", 1);
            LogPrint("仪器地址:" + ipm, 1);
            ipm = new IPEndPoint(clientip, int.Parse(clientport));
            while (true)
            {
                try
                {
                    client            = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    ucWave1.WaveColor = Color.FromArgb(255, 77, 59);
                    MACIP.Clear();
                    Properties.Settings.Default.MacStatus = "";
                    LogPrint("正在连接仪器...", 1);
                    client.Connect(ipm);
                    LogPrint("仪器连接成功", 1);
                    Properties.Settings.Default.MacStatus = client.RemoteEndPoint.ToString();
                    MACIP.Text        = client.RemoteEndPoint.ToString();
                    ucWave1.WaveColor = Color.FromArgb(0, 155, 144);
                    while (true)
                    {
                        try
                        {
                            NotifyIcon.Icon = Properties.Resources.icon;
                            string recStr = ReceiveMac(client);
                            if (recStr != "" || recStr.Length > 1)

                            {
                                NotifyIcon.Icon = Properties.Resources.transfer;
                                SendLIS(tm.Trans(tm.Trans(recStr, "MTL"), "=="));
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            LogPrint(ex.Message + ",重新尝试连接仪器...", 1);
                            break;
                        }
                    }
                }
                catch (Exception e) { LogPrint("检查仪器监听及配置", 1); Thread.Sleep(timesleep); continue; }
            }
        }
Exemplo n.º 2
0
        private void WaitMac()
        {
            LogPrint("当前仪器连接方式为服务端监听方式", 1);
            ipm = new IPEndPoint(ip, int.Parse(serverport));
            LogPrint("正在 " + ipm + " 端口启动仪器监听...", 1);
            MSocket.Bind(ipm);
            MSocket.Listen(0);
            while (true)
            {
                ucWave1.WaveColor = Color.FromArgb(255, 77, 59);
                MACIP.Clear();
                Properties.Settings.Default.MacStatus = "";
                LogPrint("正在等待仪器连接...", 1);
                MacSocket = MSocket.Accept();
                LogPrint("仪器连接成功", 1);

                MACIP.Text = MacSocket.RemoteEndPoint.ToString();
                Properties.Settings.Default.MacStatus = MacSocket.RemoteEndPoint.ToString();
                ucWave1.WaveColor = Color.FromArgb(0, 155, 144);
                while (true)
                {
                    NotifyIcon.Icon = Properties.Resources.icon;
                    try
                    {
                        string recStr = ReceiveMac(MacSocket);
                        if (recStr != "" || recStr.Length > 1)
                        {
                            NotifyIcon.Icon = Properties.Resources.transfer;
                            SendLIS(tm.Trans(tm.Trans(recStr, "MTL"), "=="));
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        LogPrint(ex.Message + ",重新启动仪器监听...", 1);
                        break;
                    }
                }
            }
        }