資源簡(jiǎn)介
這是一個(gè)通過(guò)C#網(wǎng)絡(luò)socket功能,通過(guò)CIP協(xié)議實(shí)現(xiàn)AB,歐姆龍NJ/NX系列PLC簡(jiǎn)單標(biāo)簽(不包括數(shù)組結(jié)構(gòu)體聯(lián)合體)讀寫(xiě)的例子,希望給研究CIP協(xié)議通信采集PLC數(shù)據(jù)的同學(xué)一個(gè)參考。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Net;
using?System.Net.Sockets;
using?System.Text;
using?System.Threading;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?UMMC
{
????public?partial?class?Form1?:?Form
????{
????????public?static?Form1?form;
????????funtion?f?=?new?funtion();
????????potocol?p?=?new?potocol();
????????bool?but1_flag?=?false;
????????Socket?clientSocket;
????????IPEndPoint?ipe;
????????IPAddress?ip;
????????public?Form1()
????????{
????????????InitializeComponent();
????????????
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????//窗體加載時(shí)對(duì)socket進(jìn)行初始化
????????????int?port?=?int.Parse(porttxtB.Text);
????????????string?host?=?IPtxt.Text;
????????????ip?=?IPAddress.Parse(host);
????????????ipe?=?new?IPEndPoint(ip?port);
????????}
????????private?void?ctBtn_Click(object?sender?EventArgs?e)
????????{
????????????if?(but1_flag)
????????????{
????????????????ctBtn.Text?=?“連接“;
????????????????but1_flag?=?false;
????????????????clientSocket.Close();
????????????}
????????????else
????????????{
????????????????ctBtn.Text?=?“斷開(kāi)“;
????????????????but1_flag?=?true;
????????????????clientSocket?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????????clientSocket.Connect(ipe);
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????clientSocket.Send(p.Registercmd);
????????????textBox1.AppendText(GetCurrentTime()?+?“\r\n“?+?BitConverter.ToString(p.Registercmd)?+?“\r\n\n“);
????????????Thread.Sleep(2);
????????????byte[]?raed_resp?=?new?byte[100];
????????????int?CNT=?clientSocket.Receive(raed_resp?raed_resp.Length?0);
????????????byte[]?rcv?=?new?byte[CNT];
????????????Array.Copy(raed_resp0?rcv0?CNT);
????????????textBox1.AppendText(GetCurrentTime()?+?“\r\n“?+?BitConverter.ToString(rcv)?+?“\r\n\n“);
???????????
????????????byte[]?ReadCMD?=?f.CreatReadCode(read_text.Text);
????????????ReadCMD[4]?=?raed_resp[4];?ReadCMD[5]?=?raed_resp[5];?ReadCMD[6]?=?raed_resp[6];?ReadCMD[7]?=?raed_resp[7];
????????????clientSocket.Send(ReadCMD);
????????????textBox1.AppendText(GetCurrentTime()?+?“\r\n“?+?BitConverter.ToString(ReadCMD)?+?“\r\n\n“);
????????????Thread.Sleep(2);
????????????CNT?=?clientSocket.Receive(raed_resp?raed_resp.Length?0);
????????????byte[]?rcv1?=?new?byte[CNT];
????????????Array.Copy(raed_resp?0?rcv1?0?CNT);
????????????textBox1.AppendText(GetCurrentTime()?+?“\r\n“?+?BitConverter.ToString(rcv1)?+?“\r\n\n“);
????????????//Byte[]?S_TO_ASCII?=?f.Str_TO_ASCII(read_text.Text);
????????????//read_resptext.Text?=?BitConverter.ToString(S_TO_ASCII);
????????????//byte[]?rmassg?=?f.CreatReadCode(read_text.Text);
????????????//textBox1.Text=?BitConverter.ToString(rmassg)+?rmassg.Length;
????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
????..A..H.?????24576??2019-11-24?01:22??UMMC\.vs\UCMM\v14\.suo
????..A..H.?????50176??2019-11-23?16:58??UMMC\.vs\UCMM\v15\.suo
?????文件??????????0??2019-10-11?18:31??UMMC\.vs\UCMM\v15\Server\sqlite3\db.lock
?????文件?????602112??2019-11-22?14:51??UMMC\.vs\UCMM\v15\Server\sqlite3\storage.ide
?????文件??????32768??2019-11-23?13:21??UMMC\.vs\UCMM\v15\Server\sqlite3\storage.ide-shm
?????文件????4140632??2019-11-23?13:33??UMMC\.vs\UCMM\v15\Server\sqlite3\storage.ide-wal
?????文件???????1110??2019-10-11?18:33??UMMC\UCMM.sln
?????文件????????189??2019-10-09?16:50??UMMC\UMMC\App.config
?????文件??????17920??2019-11-23?13:33??UMMC\UMMC\bin\Debug\UMMC.exe
?????文件????????189??2019-10-09?16:50??UMMC\UMMC\bin\Debug\UMMC.exe.config
?????文件??????40448??2019-11-23?13:33??UMMC\UMMC\bin\Debug\UMMC.pdb
?????文件??????22696??2019-11-24?00:36??UMMC\UMMC\bin\Debug\UMMC.vshost.exe
?????文件????????189??2019-10-09?16:50??UMMC\UMMC\bin\Debug\UMMC.vshost.exe.config
?????文件????????490??2018-04-12?07:35??UMMC\UMMC\bin\Debug\UMMC.vshost.exe.manifest
?????文件???????7132??2019-11-22?14:48??UMMC\UMMC\Form1.cs
?????文件??????13443??2019-11-22?14:48??UMMC\UMMC\Form1.Designer.cs
?????文件???????5817??2019-11-22?14:48??UMMC\UMMC\Form1.resx
?????文件???????7080??2019-11-23?13:33??UMMC\UMMC\funtion.cs
?????文件???????1443??2019-10-10?13:47??UMMC\UMMC\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7048??2019-11-24?00:36??UMMC\UMMC\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????????0??2019-10-09?16:50??UMMC\UMMC\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2019-10-09?16:50??UMMC\UMMC\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2019-10-09?16:50??UMMC\UMMC\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件?????????42??2019-10-11?18:31??UMMC\UMMC\obj\Debug\UCMM.csproj.CoreCompileInputs.cache
?????文件????????791??2019-11-24?00:36??UMMC\UMMC\obj\Debug\UCMM.csproj.FileListAbsolute.txt
?????文件???????1012??2019-11-22?14:48??UMMC\UMMC\obj\Debug\UCMM.csproj.GenerateResource.cache
?????文件??????11490??2019-10-11?18:31??UMMC\UMMC\obj\Debug\UCMM.csprojAssemblyReference.cache
?????文件?????????42??2019-10-10?16:16??UMMC\UMMC\obj\Debug\UMMC.csproj.CoreCompileInputs.cache
?????文件????????685??2019-10-11?17:04??UMMC\UMMC\obj\Debug\UMMC.csproj.FileListAbsolute.txt
?????文件???????1012??2019-10-11?09:57??UMMC\UMMC\obj\Debug\UMMC.csproj.GenerateResource.cache
............此處省略35個(gè)文件信息
- 上一篇:C#開(kāi)發(fā)大全提高卷ISO鏡像
- 下一篇:C#2048源碼
評(píng)論
共有 條評(píng)論