<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lập trình ứng dụng - HaiNH</title>
	<atom:link href="https://hainh.dev/chuyen-muc/lap-trinh-ung-dung/feed/" rel="self" type="application/rss+xml" />
	<link>https://hainh.dev</link>
	<description></description>
	<lastBuildDate>Thu, 16 Oct 2025 17:24:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://hainh.dev/wp-content/uploads/2025/10/cropped-logomyblog-32x32.png</url>
	<title>Lập trình ứng dụng - HaiNH</title>
	<link>https://hainh.dev</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">249252746</site>	<item>
		<title>DatagridView bị tình trạng giật lag nhấp nháy khi cuộn dòng trong winform</title>
		<link>https://hainh.dev/datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform</link>
					<comments>https://hainh.dev/datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Thu, 27 Oct 2022 06:01:41 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[lập trình ứng dụng]]></category>
		<category><![CDATA[Winform]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=4194</guid>

					<description><![CDATA[<p>Nếu các bạn sử dụng DataGridView mà khi cuộn các dòng dữ liệu gặp tình trạng giật lag, nhấp nháy (flickering) thì hãy sử dụng giải pháp set DoubleBuffered = True, gần như tất cả control đều có thuộc tính này nhưng DataGridView thì lại bị ẩn đi. Chúng ta chỉ cẩn sử dụng đoạn...</p>
<p>The post <a href="https://hainh.dev/datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform/">DatagridView bị tình trạng giật lag nhấp nháy khi cuộn dòng trong winform</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Nếu các bạn sử dụng DataGridView mà khi cuộn các dòng dữ liệu gặp tình trạng giật lag, nhấp nháy (flickering) thì hãy sử dụng giải pháp  set DoubleBuffered = True, gần như tất cả control đều có thuộc tính này nhưng DataGridView thì lại bị ẩn đi. Chúng ta chỉ cẩn sử dụng đoạn code dưới đây để bật thuộc tính này cho các control cần thiết.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(1 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#FFFFFF"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#000000;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>public static void SetDoubleBuffered(Control control)
{
  // set instance non-public property with name "DoubleBuffered" to true
  typeof(Control).InvokeMember("DoubleBuffered",
      BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
      null, control, new object[] { true });
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #0000FF">public</span><span style="color: #000000"> </span><span style="color: #0000FF">static</span><span style="color: #000000"> </span><span style="color: #0000FF">void</span><span style="color: #000000"> </span><span style="color: #795E26">SetDoubleBuffered</span><span style="color: #000000">(</span><span style="color: #267F99">Control</span><span style="color: #000000"> </span><span style="color: #001080">control</span><span style="color: #000000">)</span></span>
<span class="line"><span style="color: #000000">{</span></span>
<span class="line"><span style="color: #008000">  // set instance non-public property with name &quot;DoubleBuffered&quot; to true</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #0000FF">typeof</span><span style="color: #000000">(</span><span style="color: #267F99">Control</span><span style="color: #000000">).</span><span style="color: #795E26">InvokeMember</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;DoubleBuffered&quot;</span><span style="color: #000000">,</span></span>
<span class="line"><span style="color: #000000">      </span><span style="color: #001080">BindingFlags</span><span style="color: #000000">.</span><span style="color: #001080">SetProperty</span><span style="color: #000000"> | </span><span style="color: #001080">BindingFlags</span><span style="color: #000000">.</span><span style="color: #001080">Instance</span><span style="color: #000000"> | </span><span style="color: #001080">BindingFlags</span><span style="color: #000000">.</span><span style="color: #001080">NonPublic</span><span style="color: #000000">,</span></span>
<span class="line"><span style="color: #000000">      </span><span style="color: #0000FF">null</span><span style="color: #000000">, </span><span style="color: #001080">control</span><span style="color: #000000">, </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #0000FF">object</span><span style="color: #000000">[] { </span><span style="color: #0000FF">true</span><span style="color: #000000"> });</span></span>
<span class="line"><span style="color: #000000">}</span></span></code></pre></div>



<p>Khi sử dụng chỉ cần gọi vd: gdv.SetDoubleBuffered() ở form_load chẳng hạn, vd kết quả sẽ như dưới đây</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="537" height="301" data-attachment-id="4195" data-permalink="https://hainh.dev/datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform/setdoublebuffered-true/" data-orig-file="https://hainh.dev/wp-content/uploads/2022/10/SetDoubleBuffered-true-1.gif" data-orig-size="537,301" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="SetDoubleBuffered-true" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2022/10/SetDoubleBuffered-true-1-300x168.gif" data-large-file="https://hainh.dev/wp-content/uploads/2022/10/SetDoubleBuffered-true-1.gif" src="https://hainh.dev/wp-content/uploads/2022/10/SetDoubleBuffered-true-1.gif" alt="" class="wp-image-4195"/></figure><p>The post <a href="https://hainh.dev/datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform/">DatagridView bị tình trạng giật lag nhấp nháy khi cuộn dòng trong winform</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/datagridview-bi-tinh-trang-giat-lag-nhap-nhay-khi-cuon-dong-trong-winform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4194</post-id>	</item>
		<item>
		<title>Vấn đề khi upload hình ảnh từ điện thoại lên server bị xoay hình</title>
		<link>https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh</link>
					<comments>https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Wed, 08 May 2019 09:40:22 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[điện thoại]]></category>
		<category><![CDATA[lập trình ứng dụng]]></category>
		<category><![CDATA[xử lý ảnh]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=2636</guid>

					<description><![CDATA[<p>Chẳng là gần đây mình có một module thực hiện việc upload hình ảnh từ mobile lên server, tuy nhiên khi hình ảnh được đẩy lên server rồi thì xem lại có hình thì bị xoay, hình thì không như dưới đây Sau khi loay hoay tìm các vấn đề không biết tại sao thì...</p>
<p>The post <a href="https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/">Vấn đề khi upload hình ảnh từ điện thoại lên server bị xoay hình</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Chẳng là gần đây mình có một module thực hiện việc upload hình ảnh từ mobile lên server, tuy nhiên khi hình ảnh được đẩy lên server rồi thì xem lại có hình thì bị xoay, hình thì không như dưới đây</p>
<p><img decoding="async" data-attachment-id="2637" data-permalink="https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/mobile-upload-hinh-anh-bi-xoay/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay.jpg" data-orig-size="1115,662" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="mobile upload hinh anh bi xoay" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay-300x178.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay-1024x608.jpg" class="aligncenter size-full wp-image-2637" src="https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay.jpg" alt="Hình ảnh bị xoay khi upload lên server được chụp bằng điện thoại" width="1115" height="662" srcset="https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay.jpg 1115w, https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay-300x178.jpg 300w, https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay-1024x608.jpg 1024w, https://hainh.dev/wp-content/uploads/2019/05/mobile-upload-hinh-anh-bi-xoay-768x456.jpg 768w" sizes="(max-width: 1115px) 100vw, 1115px" /></p>
<p>Sau khi loay hoay tìm các vấn đề không biết tại sao thì cuối cùng mình cũng tìm ra từ khóa &#8220;mobile image exif orientation&#8221;. Và cuối cùng vấn đề của mình cũng đã được giải quyết. Lý do là vì bất kỳ hình ảnh nào được chụp từ thiết bị di động sẽ đều được lưu hướng gia tốc ( xoay ) hiện tại của điện thoại vào thẻ Exif, gọi là metadata image. Các bạn có thể tìm hiểu thêm thông tin về Exif <a href="https://en.wikipedia.org/wiki/Exif" target="_blank" rel="noopener noreferrer">tại đây</a>  . Dựa vào thông tin được lưu trong ảnh đó thì các trình xem ảnh sẽ tự động xoay hướng ảnh sao cho phù hợp. Vấn đề là khi chúng ta upload lên server và chương trình xem ảnh của chúng ta lại không quan tâm đến thông tin đó, bởi vậy ảnh bị hiển thi sai hướng. Giải quyết vấn đề này chúng ta có 2 hướng:</p>
<ol>
<li>Đọc thông tin đó và xoay lại hướng phù hợp trước khi ra view người xem.</li>
<li>Xoay lại hướng trước khi lưu vào server.</li>
</ol>
<h3><span style="color: #339966;">Giá trị được lưu vào EXIF orientation sẽ là kiểu số từ 1 đến 8:</span></h3>
<ol>
<li>0 độ, không cần điều chỉnh</li>
<li>0 độ, hình ảnh được lật về bên phải</li>
<li>180 độ, ảnh lật xuống phía dưới</li>
<li>180 độ, ảnh lật về phía phải</li>
<li>90 độ, ảnh lật về phía phải</li>
<li>90 độ, quay phải</li>
<li>270 độ, ảnh lật về phía phải</li>
<li>270 độ, quay phải</li>
</ol>
<p><img decoding="async" data-attachment-id="2638" data-permalink="https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/exif_orientations-1/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/05/EXIF_Orientations-1.gif" data-orig-size="512,252" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="EXIF_Orientations (1)" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/05/EXIF_Orientations-1-300x148.gif" data-large-file="https://hainh.dev/wp-content/uploads/2019/05/EXIF_Orientations-1.gif" class="size-full wp-image-2638 alignnone" src="https://hainh.dev/wp-content/uploads/2019/05/EXIF_Orientations-1.gif" alt="" width="512" height="252" /></p>
<p>Về vấn để xử lý trên code C# với đối tượng Image hoặc Bitmap thì đầu tiên mình lấy giá trị Exif Orientation của nó, sau đó giựa vào giá trị từ 1 &#8211; 8 đó để biết được hướng ảnh cần xoay, cuối cùng gọi phương thức RotateFlip của ảnh đó là xong.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="rowhammer">// Biến img là biến Image hình ảnh
// 0x0112 là tag Orientation được lưu trong Exif
var _exifOrientation = img.GetPropertyItem(0x0112); // return 1 -&gt; 8
// Để chắc ăn là hình ảnh có tag đó thì ta có thể dùng lệnh kiểm tra
if (img.PropertyIdList.Contains(0x0112)){ .... }</pre>
<p>Đoạn code lấy hướng cần xoay của ảnh giựa vào giá trị Exif Orientation</p>
<pre class="EnlighterJSRAW" data-enlighter-theme="rowhammer" data-enlighter-language="csharp">private RotateFlipType GetOrientationToFlipType(int orientationValue)
{
  RotateFlipType rotateFlipType = RotateFlipType.RotateNoneFlipNone;
  switch (orientationValue)
  {
    case 1:
      rotateFlipType = RotateFlipType.RotateNoneFlipNone;
      break;
    case 2:
      rotateFlipType = RotateFlipType.RotateNoneFlipX;
      break;
    case 3:
      rotateFlipType = RotateFlipType.Rotate180FlipNone;
      break;
    case 4:
      rotateFlipType = RotateFlipType.Rotate180FlipX;
      break;
    case 5:
      rotateFlipType = RotateFlipType.Rotate90FlipX;
      break;
    case 6:
      rotateFlipType = RotateFlipType.Rotate90FlipNone;
      break;
    case 7:
      rotateFlipType = RotateFlipType.Rotate270FlipX;
      break;
    case 8:
      rotateFlipType = RotateFlipType.Rotate270FlipNone;
      break;
    default:
      rotateFlipType = RotateFlipType.RotateNoneFlipNone;
      break;
  }
  return rotateFlipType;
}</pre>
<p>Xoay lại hình ảnh theo hướng cần thiết</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="rowhammer">img.RotateFlip(GetOrientationToFlipType(_exifOrientation));</pre><p>The post <a href="https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/">Vấn đề khi upload hình ảnh từ điện thoại lên server bị xoay hình</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/van-de-khi-upload-hinh-anh-tu-dien-thoai-len-server-bi-xoay-hinh/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2636</post-id>	</item>
		<item>
		<title>C# lấy địa chỉ IP internet của máy tính</title>
		<link>https://hainh.dev/c-lay-dia-chi-ip-internet-cua-may-tinh/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-lay-dia-chi-ip-internet-cua-may-tinh</link>
					<comments>https://hainh.dev/c-lay-dia-chi-ip-internet-cua-may-tinh/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Thu, 28 Feb 2019 02:52:15 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[lập trình ứng dụng]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=2523</guid>

					<description><![CDATA[<p>Lấy kết quả trả về khi chạy Command Prompt: Lấy địa chỉ IP thông qua cách sử dụng CMD:Chú ý: using System.Text.RegularExpressions; Một cách khác lấy địa chỉ IP thông qua trang http://ipinfo.io/ip</p>
<p>The post <a href="https://hainh.dev/c-lay-dia-chi-ip-internet-cua-may-tinh/">C# lấy địa chỉ IP internet của máy tính</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Lấy kết quả trả về khi chạy Command Prompt:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#FFFFFF"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#000000;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>public static string RunCMD(string cmd)
{
  Process cmdProcess;
  cmdProcess = new Process();
  cmdProcess.StartInfo.FileName = "cmd.exe";
  cmdProcess.StartInfo.Arguments = "/c " + cmd;
  cmdProcess.StartInfo.RedirectStandardOutput = true;
  cmdProcess.StartInfo.UseShellExecute = false;
  cmdProcess.StartInfo.CreateNoWindow = true;
  cmdProcess.Start();
  string output = cmdProcess.StandardOutput.ReadToEnd();
  cmdProcess.WaitForExit();
  if (String.IsNullOrEmpty(output))
    return "";
  return output;
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #0000FF">public</span><span style="color: #000000"> </span><span style="color: #0000FF">static</span><span style="color: #000000"> </span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #795E26">RunCMD</span><span style="color: #000000">(</span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #001080">cmd</span><span style="color: #000000">)</span></span>
<span class="line"><span style="color: #000000">{</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #267F99">Process</span><span style="color: #000000"> </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #267F99">Process</span><span style="color: #000000">();</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #001080">StartInfo</span><span style="color: #000000">.</span><span style="color: #001080">FileName</span><span style="color: #000000"> = </span><span style="color: #A31515">&quot;cmd.exe&quot;</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #001080">StartInfo</span><span style="color: #000000">.</span><span style="color: #001080">Arguments</span><span style="color: #000000"> = </span><span style="color: #A31515">&quot;/c &quot;</span><span style="color: #000000"> + </span><span style="color: #001080">cmd</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #001080">StartInfo</span><span style="color: #000000">.</span><span style="color: #001080">RedirectStandardOutput</span><span style="color: #000000"> = </span><span style="color: #0000FF">true</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #001080">StartInfo</span><span style="color: #000000">.</span><span style="color: #001080">UseShellExecute</span><span style="color: #000000"> = </span><span style="color: #0000FF">false</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #001080">StartInfo</span><span style="color: #000000">.</span><span style="color: #001080">CreateNoWindow</span><span style="color: #000000"> = </span><span style="color: #0000FF">true</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #795E26">Start</span><span style="color: #000000">();</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #001080">output</span><span style="color: #000000"> = </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #001080">StandardOutput</span><span style="color: #000000">.</span><span style="color: #795E26">ReadToEnd</span><span style="color: #000000">();</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #001080">cmdProcess</span><span style="color: #000000">.</span><span style="color: #795E26">WaitForExit</span><span style="color: #000000">();</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #AF00DB">if</span><span style="color: #000000"> (</span><span style="color: #001080">String</span><span style="color: #000000">.</span><span style="color: #795E26">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #001080">output</span><span style="color: #000000">))</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #A31515">&quot;&quot;</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #001080">output</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">}</span></span></code></pre></div>



<p>Lấy địa chỉ IP thông qua cách sử dụng CMD:<br>Chú ý: using System.Text.RegularExpressions;</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#FFFFFF"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#000000;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>public static string GetIP()
{
  try
  {
    string output = RunCMD("nslookup myip.opendns.com. resolver1.opendns.com");
    var ip = Regex.Matches(output, @"\b(?:(?:25&#91;0-5&#93;|2&#91;0-4&#93;&#91;0-9&#93;|&#91;01&#93;?&#91;0-9&#93;&#91;0-9&#93;?)\.){3}(?:25&#91;0-5&#93;|2&#91;0-4&#93;&#91;0-9&#93;|&#91;01&#93;?&#91;0-9&#93;&#91;0-9&#93;?)\b");
    return ip&#91;1&#93;.Value;
  }
  catch
  {
    return "127.0.0.1";
  }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #0000FF">public</span><span style="color: #000000"> </span><span style="color: #0000FF">static</span><span style="color: #000000"> </span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #795E26">GetIP</span><span style="color: #000000">()</span></span>
<span class="line"><span style="color: #000000">{</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #AF00DB">try</span></span>
<span class="line"><span style="color: #000000">  {</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #001080">output</span><span style="color: #000000"> = </span><span style="color: #795E26">RunCMD</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;nslookup myip.opendns.com. resolver1.opendns.com&quot;</span><span style="color: #000000">);</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #0000FF">var</span><span style="color: #000000"> </span><span style="color: #001080">ip</span><span style="color: #000000"> = </span><span style="color: #001080">Regex</span><span style="color: #000000">.</span><span style="color: #795E26">Matches</span><span style="color: #000000">(</span><span style="color: #001080">output</span><span style="color: #000000">, </span><span style="color: #A31515">@&quot;\b(?:(?:25&#91;0-5&#93;|2&#91;0-4&#93;&#91;0-9&#93;|&#91;01&#93;?&#91;0-9&#93;&#91;0-9&#93;?)\.){3}(?:25&#91;0-5&#93;|2&#91;0-4&#93;&#91;0-9&#93;|&#91;01&#93;?&#91;0-9&#93;&#91;0-9&#93;?)\b&quot;</span><span style="color: #000000">);</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #001080">ip</span><span style="color: #000000">&#91;</span><span style="color: #098658">1</span><span style="color: #000000">&#93;.</span><span style="color: #001080">Value</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  }</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #AF00DB">catch</span></span>
<span class="line"><span style="color: #000000">  {</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #A31515">&quot;127.0.0.1&quot;</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  }</span></span>
<span class="line"><span style="color: #000000">}</span></span></code></pre></div>



<p>Một cách khác lấy địa chỉ IP thông qua trang http://ipinfo.io/ip</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#FFFFFF"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#000000;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>public static string getIpInternet()
{
  try
  {
    using (System.Net.WebClient client = new System.Net.WebClient())
    {
      string ip = client.DownloadString("http://ipinfo.io/ip");
      ip = ip.Replace("\r", "").Replace("\n", "");
      return ip;
    }
  }
  catch
  {
    return "127.0.0.1";
  }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #0000FF">public</span><span style="color: #000000"> </span><span style="color: #0000FF">static</span><span style="color: #000000"> </span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #795E26">getIpInternet</span><span style="color: #000000">()</span></span>
<span class="line"><span style="color: #000000">{</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #AF00DB">try</span></span>
<span class="line"><span style="color: #000000">  {</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #AF00DB">using</span><span style="color: #000000"> (</span><span style="color: #267F99">System</span><span style="color: #000000">.</span><span style="color: #267F99">Net</span><span style="color: #000000">.</span><span style="color: #267F99">WebClient</span><span style="color: #000000"> </span><span style="color: #001080">client</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #267F99">System</span><span style="color: #000000">.</span><span style="color: #267F99">Net</span><span style="color: #000000">.</span><span style="color: #267F99">WebClient</span><span style="color: #000000">())</span></span>
<span class="line"><span style="color: #000000">    {</span></span>
<span class="line"><span style="color: #000000">      </span><span style="color: #0000FF">string</span><span style="color: #000000"> </span><span style="color: #001080">ip</span><span style="color: #000000"> = </span><span style="color: #001080">client</span><span style="color: #000000">.</span><span style="color: #795E26">DownloadString</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;http://ipinfo.io/ip&quot;</span><span style="color: #000000">);</span></span>
<span class="line"><span style="color: #000000">      </span><span style="color: #001080">ip</span><span style="color: #000000"> = </span><span style="color: #001080">ip</span><span style="color: #000000">.</span><span style="color: #795E26">Replace</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;</span><span style="color: #EE0000">\r</span><span style="color: #A31515">&quot;</span><span style="color: #000000">, </span><span style="color: #A31515">&quot;&quot;</span><span style="color: #000000">).</span><span style="color: #795E26">Replace</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;</span><span style="color: #EE0000">\n</span><span style="color: #A31515">&quot;</span><span style="color: #000000">, </span><span style="color: #A31515">&quot;&quot;</span><span style="color: #000000">);</span></span>
<span class="line"><span style="color: #000000">      </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #001080">ip</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">    }</span></span>
<span class="line"><span style="color: #000000">  }</span></span>
<span class="line"><span style="color: #000000">  </span><span style="color: #AF00DB">catch</span></span>
<span class="line"><span style="color: #000000">  {</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #A31515">&quot;127.0.0.1&quot;</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">  }</span></span>
<span class="line"><span style="color: #000000">}</span></span></code></pre></div>



<p></p><p>The post <a href="https://hainh.dev/c-lay-dia-chi-ip-internet-cua-may-tinh/">C# lấy địa chỉ IP internet của máy tính</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/c-lay-dia-chi-ip-internet-cua-may-tinh/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2523</post-id>	</item>
		<item>
		<title>Tui học lập trình Siemen PLC–S7-300 truy cập vùng nhớ</title>
		<link>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho</link>
					<comments>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho/#comments</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 11:33:03 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Siemen PLC S7]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=2279</guid>

					<description><![CDATA[<p>Địa chỉ ô nhớ trong PLC S7-300 bao gồm hai thành phần: phần chữ và phần số. Truy nhập theo byte: Bao gồm các kiểu Byte (1 byte), Word (2 byte), Double word (4 byte) Quy cách: Tên vùng nhớ, kích thước, địa chỉ byte đầu tiên Vùng nhớ các đầu vào I: &#8211; Tại...</p>
<p>The post <a href="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho/">Tui học lập trình Siemen PLC–S7-300 truy cập vùng nhớ</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Địa chỉ ô nhớ trong PLC S7-300 bao gồm hai thành phần: phần chữ và phần số.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2280" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho/s7-truy-cap-vung-nho/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-truy-cap-vung-nho.jpg" data-orig-size="262,45" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 truy cap vung nho" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-truy-cap-vung-nho.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-truy-cap-vung-nho.jpg" class="aligncenter size-full wp-image-2280" src="https://hainh.dev/wp-content/uploads/2019/01/s7-truy-cap-vung-nho.jpg" alt="" width="262" height="45" /></p>
<p id="id5780333" class="para">Truy nhập theo byte: Bao gồm các kiểu Byte (1 byte), Word (2 byte), Double word (4 byte)</p>
<p class="para">Quy cách: Tên vùng nhớ, kích thước, địa chỉ byte đầu tiên</p>
<h3><span style="color: #339966;">Vùng nhớ các đầu vào I:</span></h3>
<p>&#8211; Tại thời điểm đầu tiên mỗi vòng quét PLC lấy tín hiệu từ các đầu vào và ghi các giá trị tương ứng vào vùng nhớ đầu vào.</p>
<p>&#8211; Truy nhập: Kiểu: Bit I[địa chỉ byte].[địa chỉ bit] I0.1</p>
<p>Byte, word, Double word I[kích thước][địa chỉ byte đầu tiên]</p>
<p>Ví dụ: IB4, IW1, ID2</p>
<h3><span style="color: #339966;">Vùng nhớ các đầu ra Q:</span></h3>
<p>&#8211; Trong quá trình thực hiện các công việc trong một vòng quét (bao gồm cả chương trình điều khiển), PLC sẽ ghi các giá trị tơơng ứng của các vào vùng nhớ này, cuối vòng quét PLC sẽ gửi các giá trị này đến các đầu ra tương ứng.</p>
<p>&#8211; Truy nhập: Kiểu: Bit Q[địa chỉ byte].[địa chỉ bit] Q0.0</p>
<p>Byte, word, Double word Q[kích thước][địa chỉ byte đầu tiên]</p>
<p>Ví dụ: QB2, QW1, QD4</p>
<h3><span style="color: #339966;">Vùng nhớ M:</span></h3>
<p>&#8211; Các ô nhớ thuộc vùng nhớ (M) dùng để lơu trữ trạng thái của quá trình hoạt động hoặc các thông tin điều khiển khác.</p>
<p>&#8211; Truy nhập:Kiểu: Bit M[địa chỉ byte].[địa chỉ bit] M10.1</p>
<p>Byte, Word, Double word M[kích thước][địa chỉ byte đầu tiên]</p>
<p>Ví dụ: MB20, MW8, MD6</p>
<h3><span style="color: #339966;">Vùng nhớ thời gian T</span></h3>
<p>&#8211; Mỗi bộ thời gian có hai giá trị được lưu trữ trong vùng nhớ T: Giá trị đếm thời gian hiện tại (16 bit), và giá trị bit timer (1 bit).</p>
<p>&#8211; Truy nhập: T [số thứ tự bộ timer] T3</p>
<h3><span style="color: #339966;">Vùng nhớ bộ đếm C:</span></h3>
<p>&#8211; Mỗi bộ đếm có hai giá trị được lơu trữ trong vùng nhớ C: Giá trị đếm hiện tại (kiểu BDC, 12 bit), và giá trị bit counter (1 bit).</p>
<p>&#8211; Truy nhập: C [số thứ tự bộ timer] C1</p>
<h3><span style="color: #339966;">Vùng nhớ các đầu vào, đầu ra Analog AI, AQ:</span></h3>
<p>&#8211; PLC chuyển đổi một giá trị điện áp (hoặc dòng điện) thành một số nhị phân (12 bit) lưu trữ trong vùng nhớ analog (hoặc ngược lại).</p>
<p>&#8211; Cách truy nhập với tín hiệu vào: PI[kích thước][địa chỉ byte đầu tiên]</p>
<p>Ví dụ: Truy nhập: Kiểu: Byte, Word, Double word</p>
<p>PIB20, PIW8, PID6</p>
<p>&#8211; Cách truy nhập với tín hiệu ra: PQ[kích thước][địa chỉ byte đầu tiên]</p>
<p>Ví dụ: Truy nhập: Kiểu: Byte, Word, Double word</p>
<p>PQB20, PQW8, PQD6</p>
<h3><span style="color: #339966;">Vùng nhớ của các khối dữ liệu DB:</span></h3>
<p>&#8211; Mở khối dữ liệu DB hoặc DI bằng lệnh OPN</p>
<p>Ví dụ: OPN DB 1 // Mở khối dữ liệu DB (Open data Block)</p>
<p>Hoặc OPN DI 1 // Mở khối dữ liệu DI (Open instance data Block)</p>
<p>&#8211; Mở một bít trong khối dữ liệu DBX</p>
<p>Ví dụ: A DB3.DB 0.5 // mở bit số 5 của byte 0 trong khối dữ liệu DB3</p>
<p>&#8211; Mở một Byte, một WORD hoặc một một DW trong khối dữ liệu DBx</p>
<p>Ví dụ: L DB3. DBB2 // chỉ tới Byte 2 trong khối dữ liệu DB3</p>
<p>L DB3. DBW2 // chỉ tới WORD 2 trong khối dữ liệu DB3</p>
<p>L DB. DBD2 // chỉ tới DWORD 2 trong khối dữ liệu DB3</p>
<h3><span style="color: #339966;">Vùng nhớ trong các khối chương trình OB, FBx và FCx</span></h3>
<p>&#8211; Chỉ 1 bit</p>
<p>Ví dụ: A L0.2// chỉ bít số 2 của Byte 0 trong miền dữ liệu địa phương</p>
<p>&#8211; Chỉ một Byte, Word hoặc DW</p>
<p>Ví dụ: L LB0 // chỉ byte 0 trong miền dữ liệu địa phương</p>
<p>L LW0 // chỉ Word 0 trong miền dữ liệu địa phương</p>
<p>L LD0 // chỉ DWord 0 trong miền dữ liệu địa phương</p><p>The post <a href="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho/">Tui học lập trình Siemen PLC–S7-300 truy cập vùng nhớ</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-truy-cap-vung-nho/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2279</post-id>	</item>
		<item>
		<title>Tui học lập trình Siemen PLC–S7-300 các vùng nhớ</title>
		<link>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-cac-vung-nho/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tui-hoc-lap-trinh-siemen-plc-s7-300-cac-vung-nho</link>
					<comments>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-cac-vung-nho/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 11:21:48 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Siemen PLC S7]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=2276</guid>

					<description><![CDATA[<p>Toàn bộ chương trình của Siemen PLC–S7-300 được lưu trong bộ nhớ dưới dạng các khối chương trình (OB, FC, FB..) và được thực hiện với chu kỳ quét. Vùng chứa chương trình ứng dụng: OB (Organization Block): chứa chương trình chính. FC ( Function): Chứa chương trình chính được tổ chức thành hành và...</p>
<p>The post <a href="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-cac-vung-nho/">Tui học lập trình Siemen PLC–S7-300 các vùng nhớ</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Toàn bộ chương trình của Siemen PLC–S7-300 được lưu trong bộ nhớ dưới dạng các khối chương trình (OB, FC, FB..) và được thực hiện với chu kỳ quét.</p>
<h3><span style="color: #339966;">Vùng chứa chương trình ứng dụng:</span></h3>
<ul>
<li><strong>OB (Organization Block)</strong>: chứa chương trình chính.</li>
<li><strong>FC ( Function)</strong>: Chứa chương trình chính được tổ chức thành hành và có khả năng trao đổi dữ liệu với bất kỳ 1 khối chương trình nào khác. Các dữ liệu này phải được xây dựng thành một khối liệu riêng.</li>
<li><strong>FB ( function Block)</strong>: chứa chương trình chính được tổ chức thành hàm và có khả năng trao đổi dữ liệu với bất kỳ 1 khối chương trình nào khác.Các dữ liệu này phải được xây dựng thành 1 khối dữ liệu riêng.</li>
</ul>
<h3><span style="color: #339966;">Vùng chứa tham số hệ số điều hành và chương trình ứng dụng:</span></h3>
<ul>
<li><strong>I ( process image input)</strong> : Miền dữ liệu các cổng vào số, trước khi bắt đầu thực hiện chương trình, PLC sẽ đọc giá trị logic của tất cả các cổng đầu vào và cất chúng trong 1 vùng nhớ I. Thông thường chương trình ứng dụng không đọc trực tiếp trạng thái logic của cổng vào số mà chỉ lấy dữ liệu của tổng và từ bộ đệm I.</li>
<li><strong>Q (process Image Output)</strong>: Miền bộ đệm các dữ liệu cổng ra số. Kết thúc giai đoạn thực hiện chương trình, PLC sẽ chuyển giá trị logic của bộ đệm Q tới các cổng ra số. Thông thường chương trình không trực tiếp gần giá trị tới tận cổng ra mà chỉ chuyển chúng tới bộ đệm Q.</li>
<li><strong>M ( Miền các biến cờ)</strong> : Chương trình ứng dụng sử dụng những biến này để lưu giữ các tham số cần thiết và có thể truy nhập nó theo Bit, Byte, Word hay Double Word.</li>
<li><strong>T (Timer)</strong> : Miền nhớ phục vụ bộ thời gian bao gồm việc lưu trữ giá trị thời gian đặt trước, giá trị đến thời gian tức thời cũng như giá trị logic đầu ra của bộ thời gian.</li>
<li><strong>C (Counter)</strong> : Miền nhớ phục vụ bộ đếm bao gồm việc lưu trữ giá trị đặt trước, giá trị đến tức thời và giá trị logic đầu ra của bộ đệm.</li>
<li><strong>PI</strong>: Miền địa chỉ cổng vào của các module tự. Các giá trị tương tự tại cổng vào của module tương tự sẽ được module đọc và chuyển tự động theo địa chỉ. Chương trình ứng dụng có thể truy cập miền nhớ PI theo Byte, từng từ PIW hoặc PID.</li>
<li><strong>PQ</strong>: Miền địa chỉ cổng ra cho các module tương tự. Các giá trị theo những những địa chỉ này sẽ được module tương tự chuyển tới các cổng ra tương tự. Chương trình ứng dụng có thể truy nhập miền nhớ PQ theo Byte( PQB) từng từ (PQW )hoặc theo từng từ kép (PQD).</li>
</ul>
<h3><span style="color: #339966;">Vùng chứa dữ liệu:</span></h3>
<ul>
<li><strong>DB (Data Block)</strong>: Miền chứa dữ liệu được tổ chức thành khối. Kích thước cũng như số lượng khối do người sử dụng quy định, Phù hợp với từng bài toán điều khiển. Chương trình có thể truy nhập miền này theo theo từng bit (DBX), byte (DBB), từ (DBW) hoặc từ kép (DBD).</li>
<li><strong>L (local data block)</strong>: Miền dữ liệu địa phương, được các khối chương trình OB, FC, FB tổ chức và sử dụng cho các biến nháp tức thời và trao đổi dữ liệu của biến hình thức với khối lượng chương trình gọi nó. Toàn bộ vùng nhớ sẽ bị xóa sau khi khối khối lượng thực hiện xong. Có thể truy nhập theo từng bit( L), byte( LB), từ ( LW), hoặc từ kép (LD).</li>
</ul>
<p>&nbsp;</p><p>The post <a href="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-cac-vung-nho/">Tui học lập trình Siemen PLC–S7-300 các vùng nhớ</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-cac-vung-nho/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2276</post-id>	</item>
		<item>
		<title>Tui học lập trình Siemen PLC–S7-300 Hello word</title>
		<link>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word</link>
					<comments>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 06:11:29 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Siemen PLC S7]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=2261</guid>

					<description><![CDATA[<p>Mình là dân IT Software nên về điện đóm, tự động hóa hoàn toàn mù mịt, nhưng hiện tại mình lập trình các dự án liên quan nhiều đến việc nhận dữ liệu truyền thông từ plc lên máy tính. Bởi vậy mình bắt buộc phải biết cấu trúc dữ liệu của plc hay các...</p>
<p>The post <a href="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/">Tui học lập trình Siemen PLC–S7-300 Hello word</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">Mình là dân IT Software nên về điện đóm, tự động hóa hoàn toàn mù mịt, nhưng hiện tại mình lập trình các dự án liên quan nhiều đến việc nhận dữ liệu truyền thông từ plc lên máy tính. Bởi vậy mình bắt buộc phải biết cấu trúc dữ liệu của plc hay các chương trình chạy như nào để còn nắm bắt được vấn đề. Hôm nay mình sẽ note lại cách mà mình tạo 1 project và hello word với thứ mới mẻ này nhé, bỏ qua cách cài đặt thì nó quá đơn giản rồi.</p>
<h3><strong>1. Khởi động Simatic Manager và chọn File -&gt; New. </strong></h3>
<p>Nhập tên project tại ô name: hello word -&gt; ok</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2262" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-1/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1.jpg" data-orig-size="901,617" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 1" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1-300x205.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1.jpg" class="aligncenter size-full wp-image-2262" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1.jpg" alt="" width="901" height="617" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1.jpg 901w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1-300x205.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-1-768x526.jpg 768w" sizes="(max-width: 901px) 100vw, 901px" /></p>
<h3><strong>2. Khai báo trạm làm</strong> việc<strong> PLC</strong></h3>
<p>Vào menu Insert -&gt; Station -&gt; SIMATIC 300 Station</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2263" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-2/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2.jpg" data-orig-size="902,620" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 2" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2-300x206.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2.jpg" class="aligncenter size-full wp-image-2263" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2.jpg" alt="" width="902" height="620" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2.jpg 902w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2-300x206.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-2-768x528.jpg 768w" sizes="(max-width: 902px) 100vw, 902px" /></p>
<p><img loading="lazy" decoding="async" data-attachment-id="2264" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-3/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3.jpg" data-orig-size="901,620" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 3" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3-300x206.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3.jpg" class="aligncenter size-full wp-image-2264" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3.jpg" alt="" width="901" height="620" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3.jpg 901w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3-300x206.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-3-768x528.jpg 768w" sizes="(max-width: 901px) 100vw, 901px" /></p>
<h3>3. Thiết lập phần cứng cho trạm</h3>
<p>Bấm chọn Hardware để hiển thị danh sách các phần cứng.</p>
<p>Chọn SIMATIC 300 -&gt; RACK-300 -&gt; Rail</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2265" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-4/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4.jpg" data-orig-size="973,622" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 4" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4-300x192.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4.jpg" class="aligncenter size-full wp-image-2265" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4.jpg" alt="" width="973" height="622" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4.jpg 973w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4-300x192.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-4-768x491.jpg 768w" sizes="(max-width: 973px) 100vw, 973px" /></p>
<p>Chọn nguồn PS-300 -&gt; PS 307 5A</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2266" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-5/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5.jpg" data-orig-size="972,621" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 5" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5-300x192.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5.jpg" class="aligncenter size-full wp-image-2266" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5.jpg" alt="" width="972" height="621" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5.jpg 972w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5-300x192.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-5-768x491.jpg 768w" sizes="(max-width: 972px) 100vw, 972px" /></p>
<p>Chọn CPU -&gt; CPU &#8211; 300 -&gt; CPU 313C-2 DP -&gt; 6ES7 313-6CE00-0AB0 -&gt; ok</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2267" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-6/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6.jpg" data-orig-size="969,616" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 6" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6-300x191.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6.jpg" class="aligncenter size-full wp-image-2267" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6.jpg" alt="" width="969" height="616" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6.jpg 969w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6-300x191.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-6-768x488.jpg 768w" sizes="(max-width: 969px) 100vw, 969px" /></p>
<p>Khai báo tham số cho trạm<br />
Chọn đầu vào, ra logic, khai báo<br />
Chọn AI/AO, khai báo<br />
Chọn Count,&#8230;</p>
<p>Click dub vào D/12/DO16 để cấu hình input, output tại tab Address -&gt; ok<img loading="lazy" decoding="async" data-attachment-id="2268" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-7/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7.jpg" data-orig-size="971,618" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 7" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7-300x191.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7.jpg" class="aligncenter size-full wp-image-2268" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7.jpg" alt="" width="971" height="618" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7.jpg 971w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7-300x191.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-7-768x489.jpg 768w" sizes="(max-width: 971px) 100vw, 971px" /></p>
<h3>4. Lập trình PLC &#8211; OB</h3>
<p>Chọn S7 Program -&gt; Blocks , -&gt; Insert New Object -&gt; Organization Block</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2270" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-9/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9.jpg" data-orig-size="901,616" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 9" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9-300x205.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9.jpg" class="aligncenter size-full wp-image-2270" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9.jpg" alt="" width="901" height="616" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9.jpg 901w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9-300x205.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-9-768x525.jpg 768w" sizes="(max-width: 901px) 100vw, 901px" /></p>
<p>Name: OB1, Created in Language: LAD -&gt; ok</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2269" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-8/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8.jpg" data-orig-size="901,614" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 8" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8-300x204.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8.jpg" class="aligncenter size-full wp-image-2269" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8.jpg" alt="" width="901" height="614" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8.jpg 901w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8-300x204.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-8-768x523.jpg 768w" sizes="(max-width: 901px) 100vw, 901px" /></p>
<p>Tạo 1 network như dưới đây</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2271" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-10/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10.jpg" data-orig-size="927,627" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 10" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10-300x203.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10.jpg" class="aligncenter size-full wp-image-2271" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10.jpg" alt="" width="927" height="627" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10.jpg 927w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10-300x203.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-10-768x519.jpg 768w" sizes="(max-width: 927px) 100vw, 927px" /></p>
<h3>5. Chạy chương trình giả lập PLC-SIM</h3>
<p>Giờ code đã có, chỉ cần máy ảo để chạy thử xem thế nào. Tích vào biểu tượng giống hình mình đã đánh giấu dưới đây hoặc vào menu Options -&gt; Simunate Modules.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2272" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-11/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11.jpg" data-orig-size="902,619" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 11" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11-300x206.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11.jpg" class="aligncenter size-full wp-image-2272" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11.jpg" alt="" width="902" height="619" srcset="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11.jpg 902w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11-300x206.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-11-768x527.jpg 768w" sizes="(max-width: 902px) 100vw, 902px" /></p>
<h3>6. Download chương trình xuống PLC-SIM</h3>
<p>Bấm vào biểu tượng Download để đổ chương trình xuống PLC, và bấm biểu tượng Monitor để theo dõi giá trị tại cửa sổ OB1 và chọn RUN tại PLC-SIM, Bấm F2, F3 để hiển thị cửa sổ Input -&gt; Output và xem kết quả:</p>
<p><img loading="lazy" decoding="async" data-attachment-id="2273" data-permalink="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/s7-helloword-12/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-12.gif" data-orig-size="1207,737" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="s7 helloword 12" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-12-300x183.gif" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-12-1024x625.gif" class="aligncenter size-full wp-image-2273" src="https://hainh.dev/wp-content/uploads/2019/01/s7-helloword-12.gif" alt="" width="1207" height="737" /></p>
<p>OK, Vậy là đã hoàn thành việc hello word ! Mình sẽ tìm hiểu thêm về ngôn ngữ LAD sau vậy.</p>
<p>&nbsp;</p><p>The post <a href="https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/">Tui học lập trình Siemen PLC–S7-300 Hello word</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/tui-hoc-lap-trinh-siemen-plc-s7-300-hello-word/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2261</post-id>	</item>
		<item>
		<title>Visual studio 2017 The task factory &#8220;CodeTaskFactory&#8221; could not be loaded from the assembly</title>
		<link>https://hainh.dev/visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly</link>
					<comments>https://hainh.dev/visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Thu, 10 Jan 2019 10:36:03 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[nuget]]></category>
		<category><![CDATA[visual studio]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=2243</guid>

					<description><![CDATA[<p>The task factory &#8220;CodeTaskFactory&#8221; could not be loaded from the assembly &#8220;C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Professional\ MSBuild\ 15.0\ Bin\ Microsoft. Build. Tasks. v15.0 .dll&#8221;. Could not load file or assembly &#8216;file:/// C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Professional\ MSBuild\ 15.0\ Bin\ Microsoft.Build.Tasks.v15.0.dll&#8217; or one of its dependencies. The system...</p>
<p>The post <a href="https://hainh.dev/visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly/">Visual studio 2017 The task factory “CodeTaskFactory” could not be loaded from the assembly</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<blockquote class="wp-block-quote"><p>The task factory &#8220;CodeTaskFactory&#8221; could not be loaded from the assembly &#8220;C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Professional\ MSBuild\ 15.0\ Bin\ Microsoft. Build. Tasks. v15.0 .dll&#8221;. Could not load file or assembly &#8216;file:/// C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Professional\ MSBuild\ 15.0\ Bin\ Microsoft.Build.Tasks.v15.0.dll&#8217; or one of its dependencies. The system cannot find the file specified.</p></blockquote>


<p>Nếu bạn tải thư viện mới trên nuget về và visual studio của bạn bị báo lỗi như trên thì nguyên nhân có thể là do&nbsp;NuGet packages&nbsp; bạn đang sử dụng cao hơn phiên bản MSBuild&#8217;s CodeTaskFactory. Bạn chỉ cần qua bên Nuget chọn tab Update để cập nhật&nbsp; package như hình dưới đây là ok</p>


<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1451" height="897" data-attachment-id="2244" data-permalink="https://hainh.dev/visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly/loi-vs2017-2/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2.jpg" data-orig-size="1451,897" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="loi vs2017 2" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2-300x185.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2-1024x633.jpg" src="https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2.jpg" alt="" class="wp-image-2244" srcset="https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2.jpg 1451w, https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2-300x185.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2-1024x633.jpg 1024w, https://hainh.dev/wp-content/uploads/2019/01/loi-vs2017-2-768x475.jpg 768w" sizes="(max-width: 1451px) 100vw, 1451px" /></figure><p>The post <a href="https://hainh.dev/visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly/">Visual studio 2017 The task factory “CodeTaskFactory” could not be loaded from the assembly</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/visual-studio-2017-the-task-factory-codetaskfactory-could-not-be-loaded-from-the-assembly/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2243</post-id>	</item>
		<item>
		<title>Entity Framework so sánh giá trị ngày bỏ qua thời gian</title>
		<link>https://hainh.dev/entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian</link>
					<comments>https://hainh.dev/entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Thu, 10 Jan 2019 09:56:51 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=1362</guid>

					<description><![CDATA[<p>Nếu như dữ liệu chúng ta lưu kiểu datetime bao gồm cả ngày và giờ nhưng khi truy vấn chỉ so sánh ngày thì mình sẽ xử lý với tham số ngày giờ truyền vào cắt hết giờ phút của nó đi, vd biến _tuNgay = &#8216;2019/10/01 15:20:23&#8217; sẽ khởi tạo lại giá trị _tuNgay...</p>
<p>The post <a href="https://hainh.dev/entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian/">Entity Framework so sánh giá trị ngày bỏ qua thời gian</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Nếu như dữ liệu chúng ta lưu kiểu datetime bao gồm cả ngày và giờ nhưng khi truy vấn chỉ so sánh ngày thì mình sẽ xử lý với tham số ngày giờ truyền vào cắt hết giờ phút của nó đi, vd biến <strong>_tuNgay = &#8216;2019/10/01 15:20:23&#8217;</strong> sẽ khởi tạo lại giá trị <strong>_tuNgay = new DateTime(_tuNgay.Year,_tuNgay.Month,_tuNgay.Date) </strong>. Trong câu truy vấn SQL thì mình <strong>convert(datetime,NgayBaoCao,103) &gt;= @tuNgay and convert(datetime,NgayBaoCao,103) &lt;= @denNgay</strong>. </p>
<p>Tuy nhiên trong Entity Framework nếu sử dụng các hàm ngoài vào trong câu truy vấn sẽ bị báo lỗi. Chúng ta phải sử dụng phương thức DbFunctions.TruncateTime để cắt dữ liệu ngày giờ như ví dụ dưới đây:</p>


<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1290" height="273" data-attachment-id="2240" data-permalink="https://hainh.dev/entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian/dbfunction/" data-orig-file="https://hainh.dev/wp-content/uploads/2019/01/dbfunction.jpg" data-orig-size="1290,273" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="dbfunction" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2019/01/dbfunction-300x63.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2019/01/dbfunction-1024x217.jpg" src="https://hainh.dev/wp-content/uploads/2019/01/dbfunction.jpg" alt="" class="wp-image-2240" srcset="https://hainh.dev/wp-content/uploads/2019/01/dbfunction.jpg 1290w, https://hainh.dev/wp-content/uploads/2019/01/dbfunction-300x63.jpg 300w, https://hainh.dev/wp-content/uploads/2019/01/dbfunction-1024x217.jpg 1024w, https://hainh.dev/wp-content/uploads/2019/01/dbfunction-768x163.jpg 768w" sizes="(max-width: 1290px) 100vw, 1290px" /></figure><p>The post <a href="https://hainh.dev/entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian/">Entity Framework so sánh giá trị ngày bỏ qua thời gian</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/entity-framework-so-sanh-gia-tri-ngay-bo-qua-thoi-gian/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1362</post-id>	</item>
		<item>
		<title>Tạo trình soạn thảo html editor trong winform</title>
		<link>https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tao-trinh-soan-thao-html-editor-trong-winform</link>
					<comments>https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Wed, 05 Dec 2018 09:10:32 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[lập trình ứng dụng]]></category>
		<category><![CDATA[webbrowser]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=1206</guid>

					<description><![CDATA[<p>Nếu ứng dụng của bạn cần soạn thảo và hiển thị nội dung html thì mình có giải pháp sử dụng webbrowser control để soạn thảo nội dung. Chỉ cần nhúng nó vào form và sử dụng phương thức  .Document.ExecCommand để tiến hành việc định dạng cho nó. Để có thể soạn thảo nội dung...</p>
<p>The post <a href="https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/">Tạo trình soạn thảo html editor trong winform</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Nếu ứng dụng của bạn cần soạn thảo và hiển thị nội dung html thì mình có giải pháp sử dụng webbrowser control để soạn thảo nội dung. Chỉ cần nhúng nó vào form và sử dụng phương thức  .Document.ExecCommand để tiến hành việc định dạng cho nó.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="1207" data-permalink="https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/html-editor/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/12/html-editor.jpg" data-orig-size="970,500" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="html editor" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/12/html-editor-300x155.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2018/12/html-editor.jpg" class="aligncenter size-full wp-image-1207" src="https://hainh.dev/wp-content/uploads/2018/12/html-editor.jpg" alt="" width="970" height="500" srcset="https://hainh.dev/wp-content/uploads/2018/12/html-editor.jpg 970w, https://hainh.dev/wp-content/uploads/2018/12/html-editor-300x155.jpg 300w, https://hainh.dev/wp-content/uploads/2018/12/html-editor-768x396.jpg 768w" sizes="(max-width: 970px) 100vw, 970px" /></p>
<p>Để có thể soạn thảo nội dung trực tiếp trên webbrowser control thì bạn cần khai báo thuộc tính như sau:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">txtEditor.Navigate("about:blank");
txtEditor.Document.DomDocument.DesignMode = "On";</pre>
<p>Sử dụng <span style="color: #800080;"><strong>document.execCommand(<em>command</em>, <em>showUI</em>, <em>value</em>)</strong></span> để tiến hành việc định dạng.<br />
[su_table]</p>
<table style="height: 44px; width: 132px;">
<tbody>
<tr style="height: 22px;">
<td style="height: 22px; width: 44px;"><strong>Value</strong></td>
<td style="height: 22px; width: 88px;"><strong>Mô tả</strong></td>
</tr>
<tr style="height: 22px;">
<td style="height: 22px; width: 44px;">command</td>
<td style="height: 22px; width: 88px; text-align: left;">&#8220;backColor&#8221;<br />
&#8220;bold&#8221;<br />
&#8220;createLink&#8221;<br />
&#8220;copy&#8221;<br />
&#8220;cut&#8221;<br />
&#8220;defaultParagraphSeparator&#8221;<br />
&#8220;delete&#8221;<br />
&#8220;fontName&#8221;<br />
&#8220;fontSize&#8221;<br />
&#8220;foreColor&#8221;<br />
&#8220;formatBlock&#8221;<br />
&#8220;forwardDelete&#8221;<br />
&#8220;insertHorizontalRule&#8221;<br />
&#8220;insertHTML&#8221;<br />
&#8220;insertImage&#8221;<br />
&#8220;insertLineBreak&#8221;<br />
&#8220;insertOrderedList&#8221;<br />
&#8220;insertParagraph&#8221;<br />
&#8220;insertText&#8221;<br />
&#8220;insertUnorderedList&#8221;<br />
&#8220;justifyCenter&#8221;<br />
&#8220;justifyFull&#8221;<br />
&#8220;justifyLeft&#8221;<br />
&#8220;justifyRight&#8221;<br />
&#8220;outdent&#8221;<br />
&#8220;paste&#8221;<br />
&#8220;redo&#8221;<br />
&#8220;selectAll&#8221;<br />
&#8220;strikethrough&#8221;<br />
&#8220;styleWithCss&#8221;<br />
&#8220;superscript&#8221;<br />
&#8220;undo&#8221;<br />
&#8220;unlink&#8221;<br />
&#8220;useCSS&#8221;</td>
</tr>
<tr>
<td style="width: 44px;"><em>showUI</em></td>
<td style="width: 88px; text-align: left;">True nếu hiển cần thị GUI của command, vd sử dụng chèn hình ảnh, link vv ..</td>
</tr>
<tr>
<td style="width: 44px;"><em>value</em></td>
<td style="width: 88px; text-align: left;">Giá trị của command, vd: màu sắc, liên kết vv&#8230;</td>
</tr>
</tbody>
</table>
<p>[/su_table]</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">txtEditor.Document.ExecCommand("FontSize", False, 16) //Set khối đã chọn font size = 16px
txtEditor.Document.ExecCommand("insertImage", True, Nothing) //Show popup hiển thị chèn hình ảnh
txtEditor.Document.ExecCommand("foreColor", False, "#ff0000") //Set khối đã chọn có màu chữ thành đỏ</pre>
<p>Để lấy nội dung đoạn html đã nhập ta sử dụng thuộc tính: <span style="color: #800080;"><strong>txtEditor.DocumentText</strong></span></p>
<p>Để gắn giá trị html cho webbrowser ta sử dụng phương thức <span style="color: #800080;"><strong>txtEditor.Document.Write(&#8220;Nội dung html&#8221;)</strong></span></p>
<p>Demo form html editor mình xây dựng cho mục tạo chữ ký khi gửi email</p>
<p><img loading="lazy" decoding="async" data-attachment-id="1208" data-permalink="https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/html-editor-2/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/12/html-editor.gif" data-orig-size="972,497" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="html editor" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/12/html-editor-300x153.gif" data-large-file="https://hainh.dev/wp-content/uploads/2018/12/html-editor.gif" class="aligncenter size-full wp-image-1208" src="https://hainh.dev/wp-content/uploads/2018/12/html-editor.gif" alt="" width="972" height="497" /></p><p>The post <a href="https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/">Tạo trình soạn thảo html editor trong winform</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/tao-trinh-soan-thao-html-editor-trong-winform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1206</post-id>	</item>
		<item>
		<title>Sử dụng GeckoFx để tìm kiếm vị trí từ khóa trên google</title>
		<link>https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google</link>
					<comments>https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Tue, 06 Nov 2018 11:22:17 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[geckofx]]></category>
		<category><![CDATA[lập trình ứng dụng]]></category>
		<category><![CDATA[SEO]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=1019</guid>

					<description><![CDATA[<p>Mình sẽ làm 1 ví dụ về việc sử dụng GeckoFx để tìm kiếm vị trí từ khóa trên google giống như ứng dụng  Phần mềm kiểm tra vị trí từ khóa trên google nhé. Về việc cài đặt thư viện thì các bạn có thể tham khảo tại đây: Sử dụng GeckoFx thay thế cho...</p>
<p>The post <a href="https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/">Sử dụng GeckoFx để tìm kiếm vị trí từ khóa trên google</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Mình sẽ làm 1 ví dụ về việc sử dụng GeckoFx để tìm kiếm vị trí từ khóa trên google giống như ứng dụng  <a href="https://hainh.dev/phan-mem-kiem-tra-vi-tri-tu-khoa-tren-google/" target="_blank" rel="noopener">Phần mềm kiểm tra vị trí từ khóa trên google</a> nhé.</p>
<p>Về việc cài đặt thư viện thì các bạn có thể tham khảo tại đây: <a href="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/" target="_blank" rel="noopener">Sử dụng GeckoFx thay thế cho webbrowser control</a></p>
<p><img loading="lazy" decoding="async" data-attachment-id="1020" data-permalink="https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/gecko-google-1/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1.jpg" data-orig-size="907,631" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="gecko google 1" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1-300x209.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1.jpg" class="aligncenter size-full wp-image-1020" src="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1.jpg" alt="" width="907" height="631" srcset="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1.jpg 907w, https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1-300x209.jpg 300w, https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1-768x534.jpg 768w" sizes="(max-width: 907px) 100vw, 907px" /></p>
<p style="text-align: center;">Chương trình có giao diện giống như hình trên</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">public partial class Form1 : Form
{
  public Form1()
  {
    InitializeComponent();
    Gecko.Xpcom.Initialize(Application.StartupPath + "\\firefox");
  }

  private void Form1_Load(object sender, EventArgs e)
  {

  }

  private void btnTimKiem_Click(object sender, EventArgs e)
  {
    //Chuyển hướng đến trang google
    geckoWebBrowser1.Navigate("http://google.com.vn");
    //Thêm sự kiện để đợi trang google load xong mới nhập từ khóa
    geckoWebBrowser1.DocumentCompleted += new EventHandler&lt;Gecko.Events.GeckoDocumentCompletedEventArgs&gt;(geckoWebBrowser1_NhapTuKhoa);
  }

  //Sự kiện trang google load xong và nhập từ khóa
  void geckoWebBrowser1_NhapTuKhoa(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
  {

    //Xóa luôn sự kiện này tránh tình trạng loop
    geckoWebBrowser1.DocumentCompleted -= geckoWebBrowser1_NhapTuKhoa;

    //Tìm đối tượng text input có name là q đầu tiên
    Gecko.DOM.GeckoInputElement _input = (Gecko.DOM.GeckoInputElement)geckoWebBrowser1.Document.GetElementsByName("q")[0];
    //Gắn giá trị cho text input vừa tìm thấy với giá trị ô txtTuKhoa.text
    _input.Value = txtTuKhoa.Text;


    //Đợi trước khi bấm nút search theo số giây đã nhập trên ô txtThoiGianNgungTruocKhiSearch
    Application.DoEvents();
    System.Threading.Thread.Sleep((int)txtThoiGianNgungTruocKhiSearch.Value * 1000);

    //Submit form
    _input.Form.submit();

    //Add sự kiện chuyển trang tìm kiếm
    geckoWebBrowser1.DocumentCompleted += new EventHandler&lt;Gecko.Events.GeckoDocumentCompletedEventArgs&gt;(geckoWebBrowser1_TimViTri);

    //Reset lại vị trí và số trang
    TrangHienTai = 1;
    ViTriHienTai = 1;

  }

  private int TrangHienTai = 1;
  private int ViTriHienTai = 1;

  void geckoWebBrowser1_TimViTri(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
  {

    //Lấy danh sách thẻ div class g để duyệt và phân tích
    Gecko.GeckoNodeCollection arrNode = geckoWebBrowser1.Document.GetElementsByClassName("g");
    foreach (Gecko.GeckoHtmlElement item in arrNode)
    {
      //Lấy link của kết quả tìm kiếm, thẻ a nằm trong thẻ h3
      Gecko.DOM.GeckoAnchorElement _link = (Gecko.DOM.GeckoAnchorElement)item.GetElementsByTagName("h3")[0].GetElementsByTagName("a")[0];
      //So sánh với tên trang web trên kia nếu có thì đã tìm thấy vị trí
      if (_link.GetAttribute("href").ToLower().IndexOf(txtTrangWeb.Text.ToLower()) &gt;= 0)
      {

        //Cuộn đến vị trí cần xem và tạo border xung quanh nó
        item.ScrollIntoView(true);
        item.Style.CssText = "border:3px solid red;margin-top:20px;padding:15px;";
        item.InnerHtml = "&lt;h3 style='font-weight:bold;color:red;font-size:18px;'&gt;Vị trí: " + ViTriHienTai + "&lt;/h3&gt;&lt;br/&gt;" + item.InnerHtml;

        //Hiển thị vi trí kết quả và hủy sự kiện này tránh loop
        MessageBox.Show("Đã tìm thấy vị trí thứ " + ViTriHienTai + " !");
        geckoWebBrowser1.DocumentCompleted -= geckoWebBrowser1_TimViTri;
        return;
      }
      //Tăng vị trí hiện tại lên 1 nếu chưa
      ViTriHienTai += 1;
    }

    //Nếu số trang đã tới giới hạn thì thông báo không tìm thấy kết quả
    if (TrangHienTai == txtGioiHanSoTrang.Value)
    {
      MessageBox.Show("Không tìm thấy vị trí !");
      geckoWebBrowser1.DocumentCompleted -= geckoWebBrowser1_TimViTri;
      return;
    }

    //Kiểm tra có tồn tại nút Tiếp hay không
    Gecko.GeckoNodeCollection arrNodePage = geckoWebBrowser1.Document.GetElementsByClassName("fl");
    int num;
    bool isNum = Int32.TryParse(arrNodePage[arrNodePage.Length-1].TextContent, out num);
    if (isNum)
    {
      MessageBox.Show("Đã hết kết quả Search, Không tìm thấy vị trí !");
      geckoWebBrowser1.DocumentCompleted -= geckoWebBrowser1_TimViTri;
      return;
    }
    else
    {
      TrangHienTai += 1;
      ((Gecko.DOM.GeckoAnchorElement)arrNodePage[arrNodePage.Length - 1]).Click();
    }

  }
}</pre>
<p>Cùng xem kết quả nào:</p>
<p><img loading="lazy" decoding="async" data-attachment-id="1021" data-permalink="https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/gecko-google/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/gecko-google.gif" data-orig-size="1905,1015" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="gecko google" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-300x160.gif" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/gecko-google-1024x546.gif" class="aligncenter size-full wp-image-1021" src="https://hainh.dev/wp-content/uploads/2018/11/gecko-google.gif" alt="" width="1905" height="1015" /></p>
<p>Link mã nguồn chương trình: <a href="https://drive.google.com/open?id=0B68_ejhDXR0wUjlPWTVTRVNXNDA">https://drive.google.com/open?id=0B68_ejhDXR0wUjlPWTVTRVNXNDA</a></p><p>The post <a href="https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/">Sử dụng GeckoFx để tìm kiếm vị trí từ khóa trên google</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/su-dung-geckofx-de-tim-kiem-vi-tri-tu-khoa-tren-google/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1019</post-id>	</item>
		<item>
		<title>Sử dụng GeckoFx thay thế cho webbrowser control</title>
		<link>https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=su-dung-geckofx-thay-the-cho-webbrowser-control</link>
					<comments>https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/#respond</comments>
		
		<dc:creator><![CDATA[NGUYỄN HOÀNG HẢI]]></dc:creator>
		<pubDate>Sun, 04 Nov 2018 11:01:33 +0000</pubDate>
				<category><![CDATA[Lập trình ứng dụng]]></category>
		<category><![CDATA[geckofx]]></category>
		<category><![CDATA[lập trình ứng dụng]]></category>
		<category><![CDATA[web auto]]></category>
		<guid isPermaLink="false">https://hainh2k3.com/?p=992</guid>

					<description><![CDATA[<p>Hi all, Trong winform thì control Webbrowser sẽ sử dụng trình duyệt IE mặc định của máy tính để hiển thị, tuy nhiên nếu máy tính sử dụng chương trình của chúng ta là XP hay win 7 thì có thể nó đang sử dụng IE 7 hoặc 8, dẫn đến việc hiển thị CSS,...</p>
<p>The post <a href="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/">Sử dụng GeckoFx thay thế cho webbrowser control</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hi all,</p>
<p>Trong winform thì control Webbrowser sẽ sử dụng trình duyệt IE mặc định của máy tính để hiển thị, tuy nhiên nếu máy tính sử dụng chương trình của chúng ta là XP hay win 7 thì có thể nó đang sử dụng IE 7 hoặc 8, dẫn đến việc hiển thị CSS, html5 không tốt hoặc bị trang web thông báo đang sử dụng trình duyệt cũ. Ngoài ra thì cái webbrowser control mặc định của nó quá cùi bắp, cách đây tầm 3 &#8211; 4 năm mình phải thực hiện một số công việc automation trên web nên đã tìm ra cách thay thế nó bằng firefox thông qua thư viện GeckoFx.</p>
<p>Đây là một thư viện mã nguồn mở, các bạn có thể tìm thêm thông tin tại đây:  <a href="https://bitbucket.org/geckofx/geckofx/wiki/Home">https://bitbucket.org/geckofx/geckofx/wiki/Home</a></p>
<p>Để cài đặt vào project các bạn có thể thông qua nuget như hình dưới đây:</p>
<p><img loading="lazy" decoding="async" data-attachment-id="993" data-permalink="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/geckofx-1/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1.png" data-orig-size="1341,875" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GeckoFx 1" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1-300x196.png" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1-1024x668.png" class="aligncenter size-full wp-image-993" src="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1.png" alt="" width="1341" height="875" srcset="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1.png 1341w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1-300x196.png 300w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1-1024x668.png 1024w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-1-768x501.png 768w" sizes="(max-width: 1341px) 100vw, 1341px" /></p>
<p style="text-align: center;">Tìm từ khóa geckofx và install vào project.</p>
<p>Sau khi cài đặt xong các bạn vào thư mục đường dẫn project của các bạn và vào tiếp &#8220;packages\GeckoFX&#8230;..&#8221;, copy thư mục Output (Đây là thư mục chứa các thư viện xulrunner xử lý và hiển thị nội dung trang web) vào thư mục bin project của bạn và đổi tên, vd của mình là &#8220;firefox&#8221; như hình dưới đây:</p>
<p><img loading="lazy" decoding="async" data-attachment-id="994" data-permalink="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/geckofx-2/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-2.jpg" data-orig-size="471,274" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GeckoFx 2" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-2-300x175.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-2.jpg" class="aligncenter size-full wp-image-994" src="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-2.jpg" alt="" width="471" height="274" srcset="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-2.jpg 471w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-2-300x175.jpg 300w" sizes="(max-width: 471px) 100vw, 471px" /></p>
<p>Tiếp đến Add Reference file Geckofx-Winforms.dll trong thư mục &#8220;\packages\GeckoFX.1.0.5\lib&#8221; vào toolbox sau đó kéo vào form vị trí bạn cần thiết kế.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="995" data-permalink="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/geckofx-3/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3.jpg" data-orig-size="1341,875" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GeckoFx 3" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3-300x196.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3-1024x668.jpg" class="aligncenter size-full wp-image-995" src="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3.jpg" alt="" width="1341" height="875" srcset="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3.jpg 1341w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3-300x196.jpg 300w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3-1024x668.jpg 1024w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-3-768x501.jpg 768w" sizes="(max-width: 1341px) 100vw, 1341px" /></p>
<p>Giờ mình sẽ viết code để GeckoWebBrowser mở trang web tại sự kiện form load như sau:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-title="Ví dụ điều hướng trang web">public Form1()
  {
    InitializeComponent();
    //Khai báo đường dẫn thư mục xulrunner.
    Gecko.Xpcom.Initialize(Application.StartupPath + "\\firefox");
  }

  private void Form1_Load(object sender, EventArgs e)
  {
    //Chuyển hướng đến trang google.
    geckoWebBrowser1.Navigate("https://google.com.vn");
  }
}</pre>
<p><img loading="lazy" decoding="async" data-attachment-id="997" data-permalink="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/geckofx-0/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-0.jpg" data-orig-size="757,490" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GeckoFx 0" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-0-300x194.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-0.jpg" class="aligncenter size-full wp-image-997" src="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-0.jpg" alt="" width="757" height="490" srcset="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-0.jpg 757w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-0-300x194.jpg 300w" sizes="(max-width: 757px) 100vw, 757px" /></p>
<p><span style="color: #ff0000;"><strong>Chú ý:</strong></span> Nếu bạn dùng visual studio 2017 có thể sẽ xảy ra lỗi khi build liên quan đến &#8220;CodeTaskFactory&#8221; và &#8220;Microsoft.Build.Tasks.v15.0.dll&#8221;. Nguyên nhân là do thư viện này họ sử dụng visual studio 2013 để build thì phải. Giải pháp khắc phục việc này là chuyển sang dùng thư viện geckofx45 cho phiên bản .NET 4.5 trở lên, hoặc khi cài xong nuget, các bạn copy toàn bộ folder ouput và lib của nó ra ngoài, uninstall nó ra và add các thư viện Geckofx-Core.dll, Geckofx-Winforms.dll lại.</p>
<p>Trong quá trình chạy debug nếu xuất hiện lỗi thì bạn nên chuyển project platform target về x64 hoặc x86 phù hợp nhé.</p>
<p><img loading="lazy" decoding="async" data-attachment-id="996" data-permalink="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/geckofx-4/" data-orig-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-4.jpg" data-orig-size="730,450" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GeckoFx 4" data-image-description="" data-image-caption="" data-medium-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-4-300x185.jpg" data-large-file="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-4.jpg" class="aligncenter size-full wp-image-996" src="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-4.jpg" alt="" width="730" height="450" srcset="https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-4.jpg 730w, https://hainh.dev/wp-content/uploads/2018/11/GeckoFx-4-300x185.jpg 300w" sizes="(max-width: 730px) 100vw, 730px" /></p>
<p>Mình có làm 1 video từ hồi 2016, các bạn có thể tham khảo hình dung cho dễ nhé:</p>
<p style="text-align: center;">[su_youtube url=&#8221;https://youtu.be/_6O5zW5qa-Q&#8221;]</p>
<p>Về cơ bản thì các sự kiện, thao tác với DOM document của nó khá giống với webbrower control. Mình sẽ có bài hướng dẫn về việc thao tác với DOM để auto 1 số trang web nhé, vd: như tự động đăng nhập, điền biểu mẫu, tìm kiếm nội dung trong trang web vv &#8230;</p>
<p>Đây là 1 cái <a href="https://hainh.dev/chuong-trinh-ket-xuat-tin-nhan-facebook-messenger/">tool</a> mình làm có sử dụng geckofx để đăng nhập facebook sau đó kết xuất nội dung ra ngoài, mã nguồn của nó mình sẽ tìm lại nếu các bạn cần nhé.</p>
<p>&nbsp;</p><p>The post <a href="https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/">Sử dụng GeckoFx thay thế cho webbrowser control</a> first appeared on <a href="https://hainh.dev">HaiNH</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://hainh.dev/su-dung-geckofx-thay-the-cho-webbrowser-control/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">992</post-id>	</item>
	</channel>
</rss>
