-
大小: 123KB文件類型: .rar金幣: 2下載: 1 次發(fā)布日期: 2022-12-30
- 語(yǔ)言: C#
- 標(biāo)簽:
資源簡(jiǎn)介
采用三菱圓口的Rs422進(jìn)行通訊,筆記本需要有Usb轉(zhuǎn)RS422的線,不然下載后不能使用,還有三菱的協(xié)議在發(fā)送后得延時(shí)才有數(shù)據(jù)返回,所以此程序掃描效率比較低,只適合拿來(lái)學(xué)習(xí)!!!

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.IO.Ports;
using?System.Linq;
using?System.Text;
using?System.Threading;
using?System.Threading.Tasks;
namespace?三菱422通訊
{
????public?class?CmdBuilder
????{
????????///?
????????///?串口
????????///?
????????public?static?SerialPort?serialPort?{?get;?set;?}
????????///?
????????///?內(nèi)在地址
????????///?
????????public?enum?MemoryCode
????????{
????????????///?
????????????///?讀取X信號(hào)
????????????///?
????????????ReadX?=?36000
????????????///?
????????????///?讀取Y信號(hào)
????????????///?
????????????ReadY?=?35776
????????????///?
????????????///?讀寫D或?qū)懭隡寄存器
????????????///?
????????????DorM?=?16384
????????????///?
????????????///?寫入Y
????????????///?
????????????WriteY?=?24064
???????????
????????????///?
????????????///?讀取M
????????????///?
????????????ReadM?=?34816
????????}
????????///?
????????///?計(jì)算校驗(yàn)和并返回原字符加校驗(yàn)和
????????///?
????????///?要計(jì)算的字符
????????///?
????????private?static?string?CheckSum(string?str)
????????{
????????????str?=?str.Replace(“?“?““).Replace(“ “?““);
????????????int?v?=?0;
????????????for?(int?i?=?1;?i?????????????{
????????????????v?+=?str.Substring(i?*?2?2).HexToDec();
????????????}
????????????string?vHex?=?v.DecToHex(2);
????????????string?interval?=?string.Empty;
#if?debug
????????????????interval=“?“;
#endif
????????????vHex?=?vHex.Substring(vHex.Length?-?2).ToUpper();
????????????return?(str?+?interval?+?vHex.AsciiStrToHex()).ToUpper();
????????}
????????#region??////////////////////???讀???////////////////////
????????///?
????????///?讀取X信號(hào)
????????///?
????????///?從X0開始讀取多少組(注意,X0-X7為一組、X10-X17為一組)
????????///?
????????public?static?List?GetX(int?GetWordCount)
????????{
????????????string?template?=?“02453030{0}{1}03“;//{0}--地址???{1}--讀取幾個(gè)8位
#if?DEBUG
????????????template?=?“02?453030?{0}?{1}?03“;
#endif
????????????StringBuilder?sb?=?new?StringBuilder(““);
????????????int?Addr?=??(int)MemoryCode.ReadX;
????????????string?AddrHex?=?Addr.DecToHex().PadLeft(4?‘0‘).ToUpper();
????????????sb.AppendFormat(template
????????????????AddrHex.AsciiStrToHex()
????????????????(GetWordCount+1).DecToHex(2).AsciiStrToHex());
????????????string?cmd?=?CheckSum(sb.ToString());
????????????string?result?=?SendCmd(cmd100);
????????????//返回:02?3031?3030?03?43?34???X0=On
????????????//??????02?3031?3031?03?43?35???X0、X10=On
????????????//??????02?3431?3030?03?43?38???X0、X6=On
????????????//??????02?3031?3830?03?43?43???X0、X17=On???【01h???80h??80h=10000000?Bin】
????????????try
????????????{
????????????????result?=?result.Substring(2);
????????????????result?=?result.Substring(0?re
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????187??2018-01-13?07:54??三菱422通訊\三菱422通訊\App.config
?????文件??????28672??2018-01-16?14:54??三菱422通訊\三菱422通訊\bin\Debug\三菱422通訊.exe
?????文件????????187??2018-01-13?07:54??三菱422通訊\三菱422通訊\bin\Debug\三菱422通訊.exe.config
?????文件??????71168??2018-01-16?14:54??三菱422通訊\三菱422通訊\bin\Debug\三菱422通訊.pdb
?????文件??????22984??2018-01-16?14:55??三菱422通訊\三菱422通訊\bin\Debug\三菱422通訊.vshost.exe
?????文件????????187??2018-01-13?07:54??三菱422通訊\三菱422通訊\bin\Debug\三菱422通訊.vshost.exe.config
?????文件????????490??2012-06-06?02:06??三菱422通訊\三菱422通訊\bin\Debug\三菱422通訊.vshost.exe.manifest
?????目錄??????????0??2018-01-15?07:56??三菱422通訊\三菱422通訊\bin\Debug
?????目錄??????????0??2018-01-13?08:46??三菱422通訊\三菱422通訊\bin\Release
?????目錄??????????0??2018-01-13?08:46??三菱422通訊\三菱422通訊\bin
?????文件??????22212??2018-01-16?14:30??三菱422通訊\三菱422通訊\CmdBuilder.cs
?????文件??????11579??2018-01-16?14:43??三菱422通訊\三菱422通訊\DataConvert.cs
?????文件???????1275??2018-01-16?09:32??三菱422通訊\三菱422通訊\DtataCheangEventArgs.cs
?????文件???????2830??2018-01-16?15:15??三菱422通訊\三菱422通訊\Form1.cs
?????文件??????13650??2018-01-16?14:54??三菱422通訊\三菱422通訊\Form1.Designer.cs
?????文件???????5817??2018-01-16?14:54??三菱422通訊\三菱422通訊\Form1.resx
?????文件???????1308??2018-01-15?07:56??三菱422通訊\三菱422通訊\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6979??2018-01-16?09:41??三菱422通訊\三菱422通訊\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????????0??2018-01-13?07:54??三菱422通訊\三菱422通訊\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2018-01-13?07:54??三菱422通訊\三菱422通訊\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2018-01-13?07:54??三菱422通訊\三菱422通訊\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????目錄??????????0??2018-01-13?07:54??三菱422通訊\三菱422通訊\obj\Debug\TempPE
?????文件????????780??2018-01-16?14:55??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.csproj.FileListAbsolute.txt
?????文件????????975??2018-01-16?14:54??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.csproj.GenerateResource.Cache
?????文件???????2209??2018-01-13?09:04??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.csprojResolveAssemblyReference.cache
?????文件??????28672??2018-01-16?14:54??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.exe
?????文件????????180??2018-01-16?14:54??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.Form1.resources
?????文件??????71168??2018-01-16?14:54??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.pdb
?????文件????????180??2018-01-16?09:48??三菱422通訊\三菱422通訊\obj\Debug\三菱422通訊.Properties.Resources.resources
?????目錄??????????0??2018-01-16?14:54??三菱422通訊\三菱422通訊\obj\Debug
............此處省略19個(gè)文件信息
評(píng)論
共有 條評(píng)論