コード例 #1
0
ファイル: Program.cs プロジェクト: clang2you/com_proj
        //清除屏幕内容
        public void CleanLEDContents()
        {
            if (!isTcp)
            {
                if (!comPort.IsOpen)
                {
                    comPort.Open();
                }
            }
            this.cRxNumber = (byte)0;
            pCommuTx       = new byte[64];
            pTxBuf         = new byte[32];
            pTxBuf[0]      = (byte)16;
            int commu_tx = ProtocolDevIo.CreateCommuPack(pCommuTx, pTxBuf, sCommuAtt.ScreenId, sCommuAtt.ComNo, Convert.ToByte(1));

            if (!isTcp)
            {
                this.comPort.Write(pCommuTx, 0, commu_tx);
                Thread.Sleep(100);
                if (ProtocolDevIo.CheckCommuPack(this.pRxBuf, (int)this.cRxNumber))
                {
                    if (this.pRxBuf[4] == (byte)0)
                    {
                        this.commuStatus = "清除屏幕指令发送成功";
                        this.cRxNumber   = (byte)0;
                    }
                    else
                    {
                        this.commuStatus = "清除屏幕指令应用数据异常";
                    }
                }
                else
                {
                    this.commuStatus = "清除屏幕指令终端无返回";
                }
            }
            else
            {
                switch (commTcp.TxAppPack(pCommuTx, pTxBuf, 1))
                {
                case -1:
                    Console.WriteLine("应用数据异常");
                    this.cRxNumber = (byte)8;
                    break;

                case 0:
                    Console.WriteLine("发送成功");
                    this.cRxNumber = (byte)8;
                    break;

                case 1:
                    Console.WriteLine("终端未响应");
                    this.cRxNumber = (byte)8;
                    break;
                }
            }
        }
コード例 #2
0
ファイル: TcpDevIo.cs プロジェクト: clang2you/com_proj
 public void ReceiveMessage(IAsyncResult ar)
 {
     try
     {
         Socket asyncState = ar.AsyncState as Socket;
         int    Length     = asyncState.EndReceive(ar);
         RxRes = !ProtocolDevIo.CheckCommuPack(EthentRxBuf, Length) ? 1 : (EthentRxBuf[4] != (byte)0 ? -1 : 0);
         asyncState.BeginReceive(EthentRxBuf, 0, EthentRxBuf.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), (object)asyncState);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: clang2you/com_proj
        // 初始化屏幕病设置显示模式为二次开发模式
        public void SetScreenDisplayMode()
        {
            pTxBuf   = new byte[64];
            pCommuTx = new byte[70];
            if (!isTcp)
            {
                if (!comPort.IsOpen)
                {
                    comPort.Open();
                }
            }
            byte[] pBuf20 = new byte[32];
            pBuf20[0] = 2;
            pBuf20[1] = Convert.ToByte(0);
            pTxBuf[0] = (byte)5;
            pBuf20.CopyTo(pTxBuf, 1);
            txLength           = 3;
            sCommuAtt.ScreenId = 255;
            int commu_tx = ProtocolDevIo.CreateCommuPack(pCommuTx, pTxBuf, sCommuAtt.ScreenId, sCommuAtt.ComNo, Convert.ToByte(txLength));

            if (!isTcp)
            {
                comPort.Write(pCommuTx, 0, commu_tx);
                Thread.Sleep(200);
                CheckCommuStatus();
            }
            else
            {
                commTcp.sleepIntervel = 400;
                switch (commTcp.TxAppPack(pCommuTx, pTxBuf, txLength))
                {
                case -1:
                    Console.WriteLine("应用数据异常");
                    this.cRxNumber = (byte)8;
                    break;

                case 0:
                    Console.WriteLine("发送成功");
                    this.cRxNumber = (byte)8;
                    break;

                case 1:
                    Console.WriteLine("终端未响应");
                    this.cRxNumber = (byte)8;
                    break;
                }
            }
            this.CleanLEDContents();//设置之后先清除屏幕内容
        }
コード例 #4
0
ファイル: TcpDevIo.cs プロジェクト: clang2you/com_proj
        public int TxAppPack(byte[] numArray, byte[] txBuf, int Length)
        {
            int num = 200;

            //byte[] numArray = new byte[272];
            RxRes = 1;
            if (!TcpSocket.Connected || Length > num)
            {
                return(RxRes);
            }
            int commuPack = ProtocolDevIo.CreateCommuPack(numArray, txBuf, Convert.ToByte(sCommuAtt.ScreenId), Convert.ToByte(sCommuAtt.ComNo), Convert.ToByte(Length));

            TcpSocket.BeginSend(numArray, 0, commuPack, SocketFlags.None, (AsyncCallback)null, (object)null);
            Thread.Sleep(sleepIntervel);
            return(RxRes);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: clang2you/com_proj
 public void CheckCommuStatus()
 {
     if (ProtocolDevIo.CheckCommuPack(this.pRxBuf, (int)this.cRxNumber))
     {
         if (this.pRxBuf[4] == (byte)0)
         {
             this.commuStatus = "发送成功";
             this.cRxNumber   = (byte)0;
         }
         else
         {
             this.commuStatus = "应用数据异常";
         }
     }
     else
     {
         this.commuStatus = "终端无返回";
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: clang2you/com_proj
        //发送文本数据包到 LED 屏幕
        public void SendDataPack(string text, int xPos, int yPos, int space, int fontSize, bool isFirst = false)
        {
            if (!isTcp)
            {
                if (!comPort.IsOpen)
                {
                    comPort.Open();
                }
            }
            //byte[] numArray2 = new byte[70];
            byte[] pBuf20 = new byte[70];
            pBuf20          = Encoding.Default.GetBytes(text);
            sDispText.XPos  = Convert.ToUInt16(xPos);
            sDispText.YPos  = Convert.ToUInt16(yPos);
            sDispText.Space = Convert.ToByte(0);
            sDispText.Leng  = Convert.ToByte(pBuf20.Length);
            sDispText.Font  = Convert.ToByte(1);
            sDispText.Size  = Convert.ToByte(fontSize);
            sDispText.Color = Convert.ToByte(1);
            pCommuTx        = new byte[70];
            pTxBuf          = new byte[64];
            pTxBuf[0]       = (byte)23;
            StructToBytes((object)sDispText, Marshal.SizeOf((object)sDispText)).CopyTo((Array)pTxBuf, 1);
            //pBuf20.CopyTo(pTxBuf, 1);
            txLength = 1 + Marshal.SizeOf((object)sDispText);;
            pBuf20   = Encoding.Default.GetBytes(text);
            pBuf20.CopyTo(pTxBuf, 1 + Marshal.SizeOf(sDispText));
            txLength += pBuf20.Length;
            int com_tx = ProtocolDevIo.CreateCommuPack(pCommuTx, pTxBuf, sCommuAtt.ScreenId, sCommuAtt.ComNo, Convert.ToByte(txLength));

            if (!isTcp)
            {
                comPort.Write(pCommuTx, 0, com_tx);
                Thread.Sleep(200);
                if (this.cRxNumber > (byte)7)
                {
                    if (ProtocolDevIo.CheckCommuPack(this.pRxBuf, (int)this.cRxNumber))
                    {
                        if (this.pRxBuf[4] == (byte)0)
                        {
                            Console.WriteLine("文字内容:(" + text + ")发送成功");
                            this.cRxNumber = (byte)0;
                        }
                        else
                        {
                            Console.WriteLine("文字发送应用数据异常");
                        }
                    }
                    else
                    {
                        Console.WriteLine("文字发送终端无返回");
                    }
                }
                else
                {
                    Console.WriteLine("文字发送终端无返回");
                }
            }
            else
            {
                if (isFirst)
                {
                    commTcp.sleepIntervel = 400;
                }
                else
                {
                    commTcp.sleepIntervel = 150;
                }
                Console.WriteLine("数据长度:" + txLength);
                switch (commTcp.TxAppPack(pCommuTx, pTxBuf, txLength))
                {
                case -1:
                    Console.WriteLine("应用数据异常");
                    this.cRxNumber = (byte)8;
                    break;

                case 0:
                    Console.WriteLine("发送成功");
                    this.cRxNumber = (byte)8;
                    break;

                case 1:
                    Console.WriteLine("终端未响应");
                    this.cRxNumber = (byte)8;
                    break;
                }
            }
        }