麻豆一区区三三四区产品麻豆-麻豆影视国产TV在线观看-麻豆影视国产在线观看-麻豆影视在线-麻豆影视在线观看av-麻豆影院

xiapeng01
級(jí)別: 探索解密
精華主題: 0
發(fā)帖數(shù)量: 61 個(gè)
工控威望: 189 點(diǎn)
下載積分: 1197 分
在線時(shí)間: 80(小時(shí))
注冊(cè)時(shí)間: 2012-12-31
最后登錄: 2024-12-12
查看xiapeng01的 主題 / 回貼
樓主  發(fā)表于: 2024-04-13 10:19
復(fù)制粘貼代碼到VsCode 或LinqPad 中,執(zhí)行即可,需要.net8。在我的電腦上實(shí)驗(yàn)成功,歡迎反饋不同型號(hào)的結(jié)果。
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;

namespace WeintekTest;

class Program
{
    static Weintek weintek=new Weintek("192.168.20.51");

    static void Main(string[] args)
    {
        ClearTool();          
    }

    static void Fun0()
    {
        Console.WriteLine(weintek.GetLB(9047));
        Console.WriteLine(weintek.GetLB(9048));
    }

    static void Fun1()
    {
        Console.WriteLine("Done!");
        Console.Read();

        File.WriteAllText("res.txt","");

        for(int i=9000;i<12900;i++)
        {
            string str=$"{DateTime.Now}:LW{i}:\t"+weintek.GetLW(1, i) + Environment.NewLine;
            File.AppendAllText("res.txt",str);
        }
        
        Console.WriteLine("Done!");
        Console.Read();
    }

    static void ClearTool()
    {
        //Console.WriteLine("如要確認(rèn)執(zhí)行請(qǐng)按\"Y\"鍵:");
        //var key=Console.ReadKey();
        //Console.WriteLine();
        //if(key.Key != ConsoleKey.Y)
        {
            //Console.WriteLine("已取消執(zhí)行!");
            //Console.Read();            
            //return;
        }

        Console.WriteLine("請(qǐng)謹(jǐn)慎操作!");
        Console.WriteLine("觸摸屏將在稍后重啟,請(qǐng)?jiān)谟|摸屏重啟后手動(dòng)進(jìn)入并執(zhí)行觸摸屏校準(zhǔn)!");
        Console.WriteLine("校準(zhǔn)完成后,會(huì)彈出對(duì)話框詢問是否重置密碼,輸入'yes'即可清空內(nèi)部項(xiàng)目并重置下載密碼!");

        for(int i=10;i>0;i--)
        {
            //倒計(jì)時(shí)執(zhí)行
            Console.WriteLine($"倒計(jì)時(shí):{i}秒.");
            Thread.Sleep(1000);
        }

        Console.WriteLine("正在更新日期時(shí)間...");
        //更新日期時(shí)間
        weintek.SetLW(9022, (short)DateTime.Now.Year);//更新年
        weintek.SetLW(9021, (short)DateTime.Now.Month);//更新月
        weintek.SetLW(9020, (short)DateTime.Now.Day);//更新日
        weintek.SetLW(9019, (short)DateTime.Now.Hour);//更新時(shí)
        weintek.SetLW(9018, (short)DateTime.Now.Minute);//更新分
        weintek.SetLW(9017, (short)DateTime.Now.Second);//更新秒
        
        Console.WriteLine("正在更改系統(tǒng)設(shè)置...");
        weintek.SetLB(9020, true);//顯示系統(tǒng)控制按鈕
        weintek.SetLB(9033, true);//允許上傳
        weintek.SetLB(12364, true);//開啟屏幕校正后恢復(fù)出廠設(shè)置的選項(xiàng)
        weintek.SetLB(9048, true);//開啟重啟保護(hù)
        weintek.SetLB(9047, true);//重啟觸摸屏
        //設(shè)定LB寄存器時(shí)返回報(bào)文實(shí)例
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-01-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-02-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-03-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-04-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-05-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02

        Console.WriteLine("Done!");
        Console.Read();
    }



    public class Weintek
    {
        string _ip;
        int _port=8000;

        int _index=0;
        readonly object lckObj=new object();

        public Weintek(string ip)
        {
            _ip=ip;
            _port=8000;
            
        }

        public Weintek(string ip,int port)
        {
            _ip=ip;
            _port=port;
            
        }

        int GetIndex()
        {
            lock(lckObj)
            {
                return ++_index;
            }
        }

        int GetEasyWatchIndex()
        {
            return 1;
        }

        public bool GetLB(int regAddress)
        {
            //讀LB12364
            //PC發(fā):        01600000ff000000000008000c 00e5 0300000100000000000000000000ff 0403 000001000000
            //HMI回true:    01600000ff0000000000080005 00e5 030000010000000000000000000000000000 0010 0000  //大端
            //HMI回false:   01600000ff0000000000080005 00e5 030000010000000000000000000000000000 0000 0000 //大端

            //讀LB9047
            //PC發(fā):        01600000ff000000000008000c 00fb 0300000200000000000000000000ff 3502 000001000000

            //讀LB9048
            //PC發(fā):        01600000ff000000000008000c 00fe 0300000300000000000000000000ff 3502 000001000000

            try
            {
                bool ret=false;
                string sendHeader="01600000ff000000000008000c";
                string sendConstStr1 = "0300000100000000000000000000ff";
                string sendConstStr2 = "000001000000";

                string receiveHeader="01600000ff0000000000080005";

                var sendStr = sendHeader;
                sendStr += GetIndex().ToString("x4");
                sendStr += sendConstStr1;
                sendStr += GetLBAddress(regAddress).Substring(0,4);
    
                sendStr += sendConstStr2;
                
                var receiveData = Send(sendStr);
                var receiveStr = BitConverter.ToString(receiveData).Replace("-","").ToLower();
                if(receiveStr.Length> receiveHeader.Length &&
                    receiveStr.StartsWith(receiveHeader) &&
                    string.Compare(sendStr.Substring(sendHeader.Length,4),receiveStr.Substring(receiveHeader.Length,4))==0)
                {
                    var dat=ToLittleEndian(Convert.ToUInt16(receiveStr.Substring(66,4),16));
                    var temp =(Convert.ToUInt16(Math.Pow(2,regAddress % 0x10)));
                    ret = (dat & temp) > 0;
                    return ret;
                }

                return ret;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }


        /// <summary>
        /// 設(shè)置觸摸屏的LB寄存器(系統(tǒng)寄存器的值)
        /// </summary>
        /// <param name="ip">觸摸屏的地址</param>
        /// <param name="port">鏈接端口號(hào),默認(rèn)值為8000</param>
        /// <param name="index">報(bào)文序號(hào),返回報(bào)文的序號(hào)和發(fā)送報(bào)文序號(hào)相同</param>
        /// <param name="regAddress">LB寄存器地址</param>
        /// <param name="Value">設(shè)定值</param>
        public bool SetLB(int regAddress, bool Value)
        {
        //設(shè)定LB寄存器時(shí)返回報(bào)文實(shí)例
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-01-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-02-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-03-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-04-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
        //2024/4/13 10:36:54+_接收內(nèi)容33:    01-60-00-00-FF-00-00-00-00-00-08-00-01-00-05-00-00-00-01-00-00-00-00-00-00-00-00-00-00-00-00-00-02
            try
            {
                string sendHeader="01600000ff000000000008000c";
                string sendConstStr = "0000000100000000000000020000ff";//前面的01是EasyWatch序號(hào),排第一個(gè)的為01,第二個(gè)的為02,在此處無關(guān)緊要

                string receiveHeader="01600000FF0000000000080001";

                var sendStr = sendHeader;
                sendStr += GetIndex().ToString("x4");
                sendStr += sendConstStr;
                sendStr += GetLBAddress(regAddress);
                sendStr += Value ? "ff" : "00";
                sendStr += "0000";
                
                var receiveData = Send(sendStr);
                var receiveStr = BitConverter.ToString(receiveData).Replace("-","").ToLower();
                if(receiveStr.Length> receiveHeader.Length && receiveStr.StartsWith(receiveHeader))
                {
                    return true;
                }

                return false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }        

        static string GetLBAddress(int addr)
        {
            string ret = "";
            string str = addr.ToString("X5");
            ret += str.Substring(2, 2);
            ret += str.Substring(0, 2);
            ret += "00000";
            ret += str.Substring(4, 1);
            return ret;
        }

        public Int16 GetLW(int regAddress)
        {
            return GetLW(regAddress,1);
        }

        /// <summary>
        /// 讀取LW寄存器的值
        /// </summary>
        /// <param name="ip">觸摸屏IP地址</param>
        /// <param name="port">端口</param>
        /// <param name="index">包序號(hào)</param>
        /// <param name="regAddress">LW寄存器地址</param>
        /// <param name="count">寄存器個(gè)數(shù),當(dāng)前只支持1個(gè)寄存器</param>
        /// <returns>返回值</returns>
        public Int16 GetLW(int regAddress, int count)
        {
            //讀LW9009
            //PC發(fā):    01600000ff000000000008000c00be0300003600000000000000000008ff3123000001000000
            //HMI回:   01600000ff000000000008000500be03000036000000000000000000000000000040400000

            //PC發(fā):    01600000ff000000000008000c00bc0300003600000000000000000008ff3123000001000000
            //HMI回:    01600000ff000000000008000500bc03000036000000000000000000000000000040400000
            try
            {
                UInt16 ret = 0;
                string sendHeader = "01600000ff000000000008000c";
                string sendRegConstStr = "0300003600000000000000000008ff";

                string receiveHeader = "01600000ff0000000000080005";

                string sendStr = sendHeader;
                sendStr += GetIndex().ToString("x4");
                sendStr += sendRegConstStr;
                sendStr += ToLittleEndian((UInt16)regAddress).ToString("x4");
                sendStr += "0000";
                sendStr += ToLittleEndian((UInt16)count).ToString("x4");
                sendStr += "0000";

                var receiveData = Send(sendStr);
                var receiveStr = BitConverter.ToString(receiveData).Replace("-", "").ToLower();

                if (receiveStr.Length > receiveHeader.Length && //長(zhǎng)度無無異常
                    receiveStr.StartsWith(receiveHeader) && //接收頭校驗(yàn)成功
                    string.Compare(sendStr.Substring(sendHeader.Length, 4), receiveStr.Substring(receiveHeader.Length, 4)) == 0 //包序號(hào)校驗(yàn)成功
                )
                {
                    var s1 = receiveStr.Substring(66, 4);
                    ret = Convert.ToUInt16(s1, 16);
                    return (Int16)ToLittleEndian(ret);
                }
                return -1;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return -1;
            }
        }

        public bool SetLW(int regAddress, Int16 value)
        {
            //寫LW9022=2024    (0xE807)|9022=0x3e23
            //PC發(fā):    01600000ff000000000008000e 00d9 0300005100000000000000010008ff 3e23 0000 0100 e807 0000
            //HMI回:        01600000ff0000000000080001 00d9 030000510000000000000000000000000001
            //              01600000ff00000000000800010001030000510000000000000000000000000001
            try
            {
                string sendHeader = "01600000ff000000000008000e";
                string sendRegConstStr = "0300005100000000000000010008ff";
                
                string receiveHeader = "01600000ff0000000000080001";

                string sendStr = sendHeader;
                sendStr += GetIndex().ToString("x4");
                sendStr += sendRegConstStr;
                sendStr += ToLittleEndian((UInt16)regAddress).ToString("x4");
                sendStr += "0000";
                sendStr += ToLittleEndian(1).ToString("x4");
                sendStr += ToLittleEndian((UInt16)value).ToString("x4");
                sendStr += "0000";

                var receiveData = Send(sendStr);
                var receiveStr = BitConverter.ToString(receiveData).Replace("-", "").ToLower();

                if (receiveStr.Length > receiveHeader.Length && //長(zhǎng)度無無異常
                    receiveStr.StartsWith(receiveHeader) && //接收頭校驗(yàn)成功
                    string.Compare(sendStr.Substring(sendHeader.Length, 4), receiveStr.Substring(receiveHeader.Length, 4)) == 0 //包序號(hào)校驗(yàn)成功
                )
                {
                    return true;
                }
                return false;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }

        byte[] Send(string str)
        {
            try
            {
                using (var client = new TcpClient())
                {
                    client.Connect(_ip, _port);
                    var s = client.GetStream();
                    var sendData = HexStringToByteArray(str);
                    s.Write(sendData);

                    byte[] buffer = new byte[1024];
                    int n = s.Read(buffer);
                    byte[] receiveData = new byte[n];
                    Array.Copy(buffer, receiveData, n);
                    //Console.WriteLine($"{DateTime.Now.ToString()}+_接收內(nèi)容{receiveData.Length}:\t" + BitConverter.ToString(receiveData));
                    return receiveData;
                }
            }catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }

        /// <summary>
        /// 十六進(jìn)制字符串轉(zhuǎn)字節(jié)數(shù)組
        /// </summary>
        /// <param name="str">要轉(zhuǎn)換的字符串</param>
        /// <returns></returns>
        static byte[] HexStringToByteArray(string str)
        {
            return Enumerable.Range(0, str.Length).Where(x => (x % 2) == 0).Select(y => (byte)Convert.ToByte(str.Substring(y, 2), 16)).ToArray();
        }

        /// <summary>
        /// 大端轉(zhuǎn)小端和小端轉(zhuǎn)大端的操作是相同的,共用同一個(gè)即可
        /// </summary>
        /// <param name="dat">要轉(zhuǎn)換的內(nèi)容</param>
        /// <returns></returns>
        static UInt16 ToLittleEndian(UInt16 dat)
        {
            return BitConverter.ToUInt16(BitConverter.GetBytes(dat).Reverse().ToArray());
        }

        /// <summary>
        /// 大端轉(zhuǎn)小端和小端轉(zhuǎn)大端的操作是相同的,共用同一個(gè)即可
        /// </summary>
        /// <param name="dat">要轉(zhuǎn)換的內(nèi)容</param>
        /// <returns></returns>
        static UInt32 ToLittleEndian(UInt32 dat)
        {
            return BitConverter.ToUInt32(BitConverter.GetBytes(dat).Reverse().ToArray());
        }
    }
}
[ 此帖被xiapeng01在2024-04-13 15:55重新編輯 ]
xiapeng01
級(jí)別: 探索解密
精華主題: 0
發(fā)帖數(shù)量: 61 個(gè)
工控威望: 189 點(diǎn)
下載積分: 1197 分
在線時(shí)間: 80(小時(shí))
注冊(cè)時(shí)間: 2012-12-31
最后登錄: 2024-12-12
查看xiapeng01的 主題 / 回貼
1樓  發(fā)表于: 2024-04-13 15:51
內(nèi)容超長(zhǎng)。。。。。。
觸摸屏重啟后手動(dòng)進(jìn)入觸摸屏校準(zhǔn),執(zhí)行完成校準(zhǔn)后會(huì)詢問是否恢復(fù)下載密碼,輸入yes之后,會(huì)清空內(nèi)部的項(xiàng)目。
[ 此帖被xiapeng01在2024-04-20 16:16重新編輯 ]
附件: WeintekTest.rar (161 K) 下載次數(shù):21
網(wǎng)站提示: 請(qǐng)不要用迅雷下載附件,容易出錯(cuò)
tttabi
級(jí)別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 112 個(gè)
工控威望: 319 點(diǎn)
下載積分: 2348 分
在線時(shí)間: 45(小時(shí))
注冊(cè)時(shí)間: 2023-10-07
最后登錄: 2024-12-10
查看tttabi的 主題 / 回貼
2樓  發(fā)表于: 2024-04-19 17:04
問題這個(gè)怎么放進(jìn)去呢
往事如風(fēng)
科技改變制造
級(jí)別: 網(wǎng)絡(luò)英雄

精華主題: 0
發(fā)帖數(shù)量: 11484 個(gè)
工控威望: 18642 點(diǎn)
下載積分: 12347 分
在線時(shí)間: 2697(小時(shí))
注冊(cè)時(shí)間: 2013-01-31
最后登錄: 2024-12-15
查看往事如風(fēng)的 主題 / 回貼
3樓  發(fā)表于: 2024-04-21 15:58
不明覺厲
三人行者必有我?guī)?,擇其善者而從之
biaogege520
清晨的風(fēng)
級(jí)別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 182 個(gè)
工控威望: 346 點(diǎn)
下載積分: 265 分
在線時(shí)間: 74(小時(shí))
注冊(cè)時(shí)間: 2015-07-01
最后登錄: 2024-11-12
查看biaogege520的 主題 / 回貼
4樓  發(fā)表于: 2024-05-09 14:07
        

主站蜘蛛池模板: 在线不卡久久| 成人wwxx| 日本xxwwwxxxx| 无码h黄肉动漫在线观看网站 | 巨爆乳中文字幕爆乳区| 91精品欧美| 一级全黄毛片| 国产乱子伦精品无码专区| 日本MV大片生活片| 色视频一区二区三区| 成人在线高清不卡免费视频| 久久国产免费一区二区三区| 亚洲自拍婷婷五月天| 五月天婷婷丁香在线一区二区 | 国产视频三区| 国产99一区视频免费| 欧美激情肉欲高潮无码鲁大师| 好大好硬再深一点口述| 青青久在线视频免费观看手机| 夜夜草yy| 国产成人精品尤物一区二区| 国产免费成人在线视频| 久久精品影院一区二区三区| 九九热在线免费观看| 搡女人真爽免费视频大全软件| 成人免费毛片在线观看| 最新中文字幕不卡高清在线观看| 国产九九自拍电影在线观看| 毛片免费全部免费观看| 久久久久久精品天堂无码中文字| www亚洲精品| 日韩美女在线观看一区二区日| 国产成人无码一二三区视频 | 欧美特黄a级高清免费看片| 91在线免费观看网站| 亚洲欧美日韩精品香蕉| 成人亚洲A片V一区二区中出片| 亚洲天堂热| 成人a毛片高清视频| 自拍日韩美国av| 国产成人h综合亚洲欧美在线|