Exemple #1
0
        private void Fun_Transfer2CRT(ref Data.CRT_STRUCT myCRT, ref ClientAPP.TCP_STRUCT Server_CRT, ref Queue <byte[]> DataQueue_save)
        {
            Delegate la = new UpdateText(UpdateTextMethod);

            while (Server_CRT.IsConnected)
            {
                if (myCRT.DataQueue_CRT.Count() > 0)
                {
                    byte[] SendByte = myCRT.DataQueue_CRT.Dequeue();
                    Server_CRT.sck.Send(SendByte);

                    Data.dtYK.Rows[3]["数量"] = (int)Data.dtYK.Rows[3]["数量"] + 1;


                    //增加存储,DataQueue_save为引用的对应SaveFile里面的Queue
                    DataQueue_save.Enqueue(SendByte);

                    myCRT.Transfer2CRTa_TempStr = "";
                    for (int m = 24; m < SendByte.Length - 8; m++)
                    {
                        myCRT.Transfer2CRTa_TempStr += SendByte[m].ToString("x2");
                    }
                    Trace.WriteLine("Fun_Transfer2CRT:" + myCRT.Transfer2CRTa_TempStr);
                }
            }
        }
Exemple #2
0
        private void Fun_RecvFromCRT(ref Data.CRT_STRUCT myCRT, ref ClientAPP.TCP_STRUCT Server_CRT)
        {
            Trace.WriteLine("Entering" + myCRT.CRTName + "Fun_RecvFromCRT!!");

            while (Server_CRT.IsConnected)
            {
                try
                {
                    byte[] RecvBufCRTa = new byte[1024];
                    int    RecvNum     = Server_CRT.sck.Receive(RecvBufCRTa);
                    if (RecvNum > 0)
                    {
                        int[] RecvBufInt = Program.BytesToInt(RecvBufCRTa);

                        myCRT.TCMsgStatus = RecvBufInt[7];
                    }
                    else
                    {
                        Trace.WriteLine("收到数据少于等于0!");
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Trace.WriteLine("Exception leave!!");
                    break;
                }
            }
        }
Exemple #3
0
        private void Fun_RecvFromCRT_Return(ref Data.CRT_STRUCT myCRT, ref ClientAPP.TCP_STRUCT Server_CRT)
        {
            Trace.WriteLine("++++++++++Entering" + myCRT.CRTName + "Fun_RecvFromCRT_Return!!");

            //int[] SendReq;
            //byte[] SendReqBytes;
            ////send request
            //SendReq = new int[16];
            //SendReq[0] = 1234567890;        //Start of msg
            //SendReq[1] = 64;                //Size of msg in bytes
            //SendReq[2] = 0;                 //Size of msg
            //SendReq[3] = 0;                 //0:channelA 1:channelB
            //SendReq[4] = 0;                 //Real time telemetry
            //SendReq[5] = 0;                 //Permanent flow 一次请求
            //SendReq[15] = -1234567890;
            //SendReqBytes = Program.IntToBytes(SendReq);

            //int len = Server_CRT.sck.Send(SendReqBytes);

            while (Server_CRT.IsConnected)
            {
                try
                {
                    byte[] RecvBufCRTa = new byte[200];
                    int    RecvNum     = Server_CRT.sck.Receive(RecvBufCRTa);

                    if (RecvNum > 0)
                    {
                        //TempRecvBuf 本次收到的数据
                        byte[] TempRecvBuf = new byte[RecvNum];
                        Array.Copy(RecvBufCRTa, TempRecvBuf, RecvNum);

                        SaveFile.Lock_Dat3.EnterWriteLock();
                        SaveFile.DataQueue_out3.Enqueue(TempRecvBuf);
                        SaveFile.Lock_Dat3.ExitWriteLock();

                        String tempstr = "";
                        for (int i = 0; i < TempRecvBuf.Length; i++)
                        {
                            tempstr += TempRecvBuf[i].ToString("x2");
                        }
                        Trace.WriteLine(tempstr);

                        Data.dtYC.Rows[0]["数量"] = (int)Data.dtYC.Rows[0]["数量"] + 1; //收到总数

                        //YCBuf 本次收到的实际遥测数据
                        byte[] YCBuf = new byte[RecvNum - 68];
                        Array.Copy(RecvBufCRTa, 64, YCBuf, 0, RecvNum - 68);

                        SaveFile.Lock_Dat4.EnterWriteLock();
                        SaveFile.DataQueue_out4.Enqueue(YCBuf);
                        SaveFile.Lock_Dat4.ExitWriteLock();

                        String tempstr2 = "";
                        for (int i = 0; i < YCBuf.Length; i++)
                        {
                            tempstr2 += YCBuf[i].ToString("x2");
                        }
                        Trace.WriteLine(tempstr2);

                        //ushort CRC = 0xffff;
                        //ushort genpoly = 0x1021;
                        //for (int i = 0; i < YCBuf.Length-2; i = i + 1)
                        //{
                        //    CRC = Function.CRChware(YCBuf[i], genpoly, CRC);
                        //}
                        ////      MyLog.Info("Calc 通道1 CRC = " + CRC.ToString("x4"));
                        //Trace.WriteLine("Calc 通道1 CRC = " + CRC.ToString("x4"));
                    }
                    else
                    {
                        Trace.WriteLine("收到数据少于等于0!");
                        break;
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.Message);
                    break;
                }
            }
            Trace.WriteLine("----------Leaving" + myCRT.CRTName + "Fun_RecvFromCRT_Return!!");
        }