DESKTOP-Kang 6 роки тому
батько
коміт
baf52d73df

+ 24 - 9
Dev/OHVDriveLogger/OHVDriveLogger/OHVDriveLogger/FormMain.cs

@@ -1,4 +1,5 @@
-using GSG.NET.Logging;
+using GSG.NET.Concurrent;
+using GSG.NET.Logging;
 using GSG.NET.PLC;
 using GSG.NET.PLC.Keyence;
 using GSG.NET.PLC.KNC;
@@ -30,8 +31,19 @@ namespace OHVDriveLogger
 
         private void FormMain_FormClosing( object sender, FormClosingEventArgs e )
         {
-            this.plc.Disconnect();
-            this.zmp.Dispose();
+            DialogResult result = MessageBox.Show( "Drive Logger", "EXIT", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
+            if ( result == System.Windows.Forms.DialogResult.Yes )
+            {
+                plc.WriteBit( "DRIVE_LOGGING_ONOFF", false );
+                LockUtils.Wait( 200 );
+
+                this.plc.Disconnect();
+                this.zmp.Dispose();
+            }
+            else
+            {
+                e.Cancel = true;
+            }
         }
 
         private void FormMain_Load( object sender, EventArgs e )
@@ -42,7 +54,7 @@ namespace OHVDriveLogger
             this.plc.Config.MonitorInterval = 1000;
 
             var grpB = new KncGroup { Device = KncDevice.MR, Name = "MR" };
-            grpB.AddBitBlock( new KncBitBlock { Name = $"DRIVE_LOGGING_ONOFF", Address = 16, SubNo = 0 } );
+            grpB.AddBitBlock( new KncBitBlock { Name = $"DRIVE_LOGGING_ONOFF", Address = 16, SubNo = 0 } ); //MR100 Keyence 주소 체계가 다름.
 
             this.plc.AddGroup( grpB );
 
@@ -83,11 +95,14 @@ namespace OHVDriveLogger
 
         private void button1_Click( object sender, EventArgs e )
         {
-            var bit = plc.ReadBit( "DRIVE_LOGGING_ONOFF" );
-            if ( bit.IsBitOn )
-                plc.WriteBit( "DRIVE_LOGGING_ONOFF", false );
-            else
-                plc.WriteBit( "DRIVE_LOGGING_ONOFF", true );
+            //var bit = plc.ReadBit( "DRIVE_LOGGING_ONOFF" );
+            //if ( bit.IsBitOn )
+            //    plc.WriteBit( "DRIVE_LOGGING_ONOFF", false );
+            //else
+            //    plc.WriteBit( "DRIVE_LOGGING_ONOFF", true );
+
+            string strOut;
+            zmp.Request( "Hello", out strOut );
         }
     }
 }

+ 8 - 2
Dev/OHVDriveLogger/OHVDriveLogger/OHVDriveLogger/ZmqManager.cs

@@ -97,11 +97,11 @@ namespace OHVDriveLogger
             }
         }
 
-        bool Request( string topic, out string response )
+        public bool Request( string topic, out string response )
         {
             response = string.Empty;
 
-            if ( this.IsReqConnected )
+            if ( !this.IsReqConnected )
                 return false;
 
             if ( this.req.HasOut )
@@ -110,7 +110,13 @@ namespace OHVDriveLogger
             if ( this.req.TryReceiveFrameString( TimeSpan.FromSeconds( 5 ), out response ) )
                 return true;
             else
+            {
+                this.req.Disconnect( "tcp://127.0.0.1:5567" );
+
+                //this.req = new RequestSocket();
+                this.req.Connect( "tcp://127.0.0.1:5567" );
                 return false;
+            }
         }
     }
 }