コード例 #1
0
        public static TcpModbusPacket GetPacket(byte[] buffer)
        {
            if (buffer.Length < TcpModbusPacketHead.HEAD_SIZE)
            {
                throw (new Exception("数据包长度过短,无法转换"));
            }
            UInt16 PacketLen = BytesOP.MakeShort(buffer[4], buffer[5]);

            if (buffer.Length < (TcpModbusPacketHead.HEAD_SIZE + PacketLen))
            {
                throw (new Exception("数据包长度过短,无法转换"));
            }
            UInt16 ProtocolID = BytesOP.MakeShort(buffer[2], buffer[3]);//协议号

            if (ProtocolID != TcpModbusPacketHead.ProtocolID)
            {
                throw (new Exception("数据协议标识不符!"));
            }
            TcpModbusPacket     packet     = new TcpModbusPacket();
            TcpModbusPacketHead packetHead = new TcpModbusPacketHead();

            packetHead.MBAP_Index = BytesOP.MakeShort(buffer[0], buffer[1]);
            packetHead.Len        = PacketLen;
            packet.Header         = packetHead;
            packet.SubAddr        = buffer[6];
            packet.functionCode   = (FunctionCode)buffer[7];
            packet.Data           = new Byte[packetHead.Len - 2];
            Array.Copy(buffer, TcpModbusPacketHead.HEAD_SIZE + 2, packet.Data, 0, packetHead.Len - 2);
            return(packet);
        }
コード例 #2
0
        public static pppPocket MakepppPacket(List <byte> RxList, int start)
        {
            pppPocket ppp = new pppPocket();

            ppp.Protocol = BytesOP.MakeShort(RxList[start], RxList[start + 1]);
            ppp.Code     = RxList[start + 2];
            ppp.ID       = RxList[start + 3];
            ushort l = BytesOP.MakeShort(RxList[start + 4], RxList[start + 5]);

            l = (ushort)(l - 4);
            try
            {
                for (int i = 0; i < l;)
                {
                    byte[] bs = new byte[RxList[i + start + 1 + 6] - 2];
                    for (int j = 0; j < bs.Length; j++)
                    {
                        bs[j] = RxList[i + 2 + j + 6 + start];
                    }
                    ppp.AddCommand(RxList[i + 6 + start], bs);
                    i = i + RxList[i + 1 + start + 6];
                }
            }
            catch { }
            return(ppp);
        }
コード例 #3
0
        private void waitTimer_Tick(object sender, EventArgs e)
        {
            form1.ReadDeweRev();
            this.Invoke((EventHandler)(delegate
            {
                double d = form1.deweRev;
                chart1.Series[0].Points.AddY(d);
                lRev.Text = d.ToString("f1");
            }));
            TcpModbusPacket tp = form1.ReadPLC();

            if (tp != null)
            {
                ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
                if (!BytesOP.GetBit(D100, 0))//系统外部停机
                {
                    MessageBox.Show("测试停止");
                    this.Invoke((EventHandler)(delegate
                    {
                        waitTimer.Enabled = false;
                        toolStripButton1.Enabled = true;
                    }));
                }
            }
        }
コード例 #4
0
        public static List <byte> PPPDataEncode(List <byte> RxList, bool bLCP)
        {
            ushort crc = Verify.GetVerify_CRC16_CCITT(RxList.ToArray(), RxList.Count);

            RxList.Add(BytesOP.GetLowByte(crc));
            RxList.Add(BytesOP.GetHighByte(crc));
            List <byte> temp = new List <byte>();

            temp.Add(0x7e);
            byte x;

            foreach (byte b in RxList)
            {
                x = IsNeedTrans(b, bLCP);
                if (x != 0x00)
                {
                    temp.Add(0x7d);
                    temp.Add(x);
                }
                else
                {
                    temp.Add(b);
                }
            }
            temp.Add(0x7e);
            return(temp);
        }
コード例 #5
0
        public static ushort[,] TransPicDatas(byte[] ya, int row, int col, int PixelDepth)
        {
            int k;

            ushort[,] ret = new ushort[row, col];
            for (int m = 0; m < row; m++)
            {
                for (int n = 0; n < col; n++)
                {
                    k         = n * 2;
                    ret[m, n] = BytesOP.MakeShort(ya[k + 2 * col * m + 1], ya[k + 2 * col * m]);
                    switch (PixelDepth)
                    {
                    case 8:
                        ret[m, n] &= 0x00ff;
                        break;

                    case 10:
                        ret[m, n] &= 0x03ff;
                        break;

                    case 12:
                        ret[m, n] &= 0x0fff;
                        break;

                    case 14:
                        ret[m, n] &= 0x3fff;
                        break;
                    }
                }
            }
            return(ret);
        }
コード例 #6
0
 public static byte[] GetTxData(ushort BaudRate)
 {
     byte[] ret = new byte[2];
     ret[0] = BytesOP.GetLowByte(BaudRate);
     ret[1] = BytesOP.GetHighByte(BaudRate);
     return(ret);
 }
コード例 #7
0
        private void waitTimer_Tick(object sender, EventArgs e)
        {
            form1.ReadDeweData();
            this.Invoke((EventHandler)(delegate
            {
                chart1.Series[0].Points.AddY(form1.deweNiuZhen);
                chart2.Series[0].Points.AddY(form1.deweNiuJu);
                chart2.Series[1].Points.AddY(Torque);
                chart2.Series[2].Points.AddY(motorTorque);
            }));
            t           = t + waitTimer.Interval / 1000;
            motorTorque = Torque + Amplitude * Math.Sin(omega * t);
            form1.SetMotor(motorRev, motorTorque);
            TcpModbusPacket tp = form1.ReadPLC();

            if (tp != null)
            {
                ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
                if (!BytesOP.GetBit(D100, 0))//系统外部停机
                {
                    MessageBox.Show("测试停止");
                    this.Invoke((EventHandler)(delegate
                    {
                        waitTimer.Enabled = false;
                        toolStripButton1.Enabled = true;
                    }));
                }
            }
        }
コード例 #8
0
        public static CMOSInfo SerialCommand1()
        {
            CP0314Packet Rx0314 = new CP0314Packet(1);

            byte[] tx = CP0314Packet.MakeCP0314Packet(1, null);
            mySerialPort.Write(tx, 0, tx.Length);
            while (true)
            {
                try
                {
                    if (Rx0314.DataPacketed((byte)mySerialPort.ReadByte()))
                    {
                        CMOSInfo ret = new CMOSInfo();
                        //ret.RowPixels = BytesOP.MakeShort(Rx0314.Data[0], Rx0314.Data[1]);
                        //ret.ColPixels = BytesOP.MakeShort(Rx0314.Data[2], Rx0314.Data[3]);
                        //ret.PixelDepth = Rx0314.Data[4];
                        //ret.RGB = (RGBType)(BytesOP.MakeShort(Rx0314.Data[5], Rx0314.Data[6]));
                        ret.Ts = BytesOP.MakeShort(Rx0314.Data[7], Rx0314.Data[8]);
                        return(ret);
                    }
                }
                catch
                {
                    //MessageBox.Show("读取数据失败");
                    break;
                }
            }
            return(null);
        }
コード例 #9
0
        public static ushort[,] TransImageDatas(byte[] byteList)//, int row, int col, int PixelDepth)
        {
            int k;

            ushort[,]  imageData = new ushort[SystemParam.CCD_M, SystemParam.CCD_N];
            for (int m = 0; m < SystemParam.CCD_M; m++)
            {
                for (int n = 0; n < SystemParam.CCD_N; n++)
                {
                    k = n * 2;
                    imageData[m, n] = BytesOP.MakeShort(byteList[k + 2 * SystemParam.CCD_N * m + 1], byteList[k + 2 * SystemParam.CCD_N * m]);
                    switch (SystemParam.CCD_ADL)//图像传感器模数转换宽度
                    {
                    case 8:
                        imageData[m, n] &= 0x00ff;
                        break;

                    case 10:
                        imageData[m, n] &= 0x03ff;
                        break;

                    case 12:
                        imageData[m, n] &= 0x0fff;
                        break;

                    case 14:
                        imageData[m, n] &= 0x3fff;
                        break;
                    }
                }
            }
            return(imageData);
        }
コード例 #10
0
        public static EnvironmentInfo SerialCommand2()
        {
            CP0314Packet Rx0314 = new CP0314Packet(2);

            byte[] tx = CP0314Packet.MakeCP0314Packet(2, null);
            mySerialPort.Write(tx, 0, tx.Length);
            while (true)
            {
                try
                {
                    if (Rx0314.DataPacketed((byte)mySerialPort.ReadByte()))
                    {
                        EnvironmentInfo ret = new EnvironmentInfo();
                        ret.Temp = BytesOP.MakeShort(Rx0314.Data[0], Rx0314.Data[1]);
                        ret.E    = BytesOP.MakeShort(Rx0314.Data[2], Rx0314.Data[3]);
                        return(ret);
                    }
                }
                catch
                {
                    //MessageBox.Show("读取数据失败");
                    break;
                }
            }
            return(null);
        }
コード例 #11
0
        void checkPLC()
        {
            TcpModbusPacket tp = ReadPLC();

            if (tp != null)
            {
                ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
                if (!BytesOP.GetBit(D100, 0))//系统外部停机
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        openTimer.Enabled = false;
                        waitTimer.Enabled = false;
                        splitContainer1.Enabled = false;
                        toolStripButton4.Enabled = true;
                        listView1.BackColor = SystemColors.Window;
                        listView2.BackColor = SystemColors.Window;
                        tbTime1.Visible = false;
                        tbTime.Visible = false;
                        timer1.Enabled = false;
                    }));
                    MessageBox.Show("测试停止");
                }
            }
        }
コード例 #12
0
 public static byte[] MakeCP1616_NoAddr_Packet(byte com, byte[] data)
 {
     byte[] txbuffer;
     if (data != null)
     {
         txbuffer    = new byte[CP1616_NoAddr_PacketHead.HEAD_SIZE + data.Length + 2];
         txbuffer[0] = 0x16;
         txbuffer[1] = 0x16;
         txbuffer[2] = com;
         txbuffer[3] = BytesOP.GetHighByte((UInt16)data.Length);
         txbuffer[4] = BytesOP.GetLowByte((UInt16)data.Length);
         for (int i = 0; i < data.Length; i++)
         {
             txbuffer[i + CP1616_NoAddr_PacketHead.HEAD_SIZE] = data[i];
         }
         txbuffer[CP1616_NoAddr_PacketHead.HEAD_SIZE + data.Length]     = Verify.GetVerify_byteSum(txbuffer, CP1616_NoAddr_PacketHead.HEAD_SIZE + data.Length);
         txbuffer[CP1616_NoAddr_PacketHead.HEAD_SIZE + data.Length + 1] = 0x0d;
     }
     else
     {
         txbuffer    = new byte[CP1616_NoAddr_PacketHead.HEAD_SIZE + 2];
         txbuffer[0] = 0x16;
         txbuffer[1] = 0x16;
         txbuffer[2] = com;
         txbuffer[3] = 0x00;
         txbuffer[4] = 0x00;
         txbuffer[CP1616_NoAddr_PacketHead.HEAD_SIZE]     = Verify.GetVerify_byteSum(txbuffer, CP1616_NoAddr_PacketHead.HEAD_SIZE);
         txbuffer[CP1616_NoAddr_PacketHead.HEAD_SIZE + 1] = 0x0d;
     }
     return(txbuffer);
 }
コード例 #13
0
 void WaitingStart(object LockWatingThread)
 {
     while (true)
     {
         TcpModbusPacket tp = form1.ReadPLC();
         if (tp != null)
         {
             ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
             if (BytesOP.GetBit(D100, 0))//系统已经启动
             {
                 form1.SetMotor(motorRev, motorTorque);
                 this.Invoke((EventHandler)(delegate
                 {
                     chart1.Series[0].Points.Clear();
                     waitTimer.Enabled = true;
                 }));
                 return;
             }
         }
         Thread.Sleep(1000);
         lock (LockWatingThread)
         {
             wpStart.SetProcessBarPerformStep();
             if (wpStart.HasBeenCancelled())
             {
                 return;
             }
         }
     }
 }
コード例 #14
0
//         public static MemoryStream MakePacket(NetPacket.NetPacketType type, object o)
//         {
//             NetPacket packet = new NetPacket();
//             packet._packetHead = new NetPacketHead();
//             packet.Data = o; ;
//             packet._packetHead.PType = type;
//             MemoryStream mStream = new MemoryStream();
//             mStream.Write(BitConverter.GetBytes(NetPacketHead.Version), 0, sizeof(Int32));//版本
//             mStream.Write(BitConverter.GetBytes((Int32)packet.PacketHead.PType), 0, sizeof(Int32));//类型
//             byte[] buffer = null;
//             buffer = (byte[])packet.Data;
//             packet.PacketHead.Len = buffer.Length;
//             mStream.Write(BitConverter.GetBytes(packet.PacketHead.Len), 0, sizeof(Int32));//长度
//             if (buffer != null)
//                 mStream.Write(buffer, 0, buffer.Length);
//             return mStream;
//         }

        public static object SaveDataProcessCallbackProc(byte[] tempbuffer, ref byte[] buffer, ref int dataOffset, int length)
        {
            //判断读取的字节数+缓冲区已有字节数是否超过缓冲区总大小
            if (length + dataOffset > buffer.Length)
            {
                if (dataOffset >= TcpModbusPacketHead.HEAD_SIZE)//如果缓冲区数据满足一个包头数据大小,则可以计算出本次接收的包需要的缓冲区大小,从而实现一次调整大小
                {
                    int PacketLen = BytesOP.MakeShort(buffer[4], buffer[5]);
                    Array.Resize <Byte>(ref buffer, TcpModbusPacketHead.HEAD_SIZE + PacketLen);
                }
                else //不满足一个完整的网络封包的大小
                {
                    Array.Resize <Byte>(ref buffer, buffer.Length + BUFFER_SIZE * 2);
                }
            }
            //将新读取的数据拷贝到缓冲区
            Array.Copy(tempbuffer, 0, buffer, dataOffset, length);
            //修改"数据实际长度"
            dataOffset += length;
            if (dataOffset > TcpModbusPacketHead.HEAD_SIZE)//已经有头数据了
            {
                int PacketLen = BytesOP.MakeShort(buffer[4], buffer[5]);
                if (dataOffset < (TcpModbusPacketHead.HEAD_SIZE + PacketLen))
                {
                    return(null);
                }
            }
            //获得了完整的数据包
            TcpModbusPacket packet = GetPacket(buffer);

            Array.Copy(buffer, TcpModbusPacketHead.HEAD_SIZE + packet.Header.Len, buffer, 0, dataOffset - (TcpModbusPacketHead.HEAD_SIZE + packet.Header.Len));
            dataOffset -= (TcpModbusPacketHead.HEAD_SIZE + packet.Header.Len);//缓冲区实际数据长度减去一个完整封包长度
            return(packet);
        }
コード例 #15
0
        void GetGQTable(CurveData cd, DataTable dt)
        {
            DataRow dr = dt.NewRow();

            for (int i = 0; i < 101; i++)
            {
                dr = dt.NewRow();
                if (BytesOP.GetBit(cd.exWorkTepy, 2))//自动,则0.5V
                {
                    if (i % 2 == 1)
                    {
                        continue;
                    }
                    dr["GQ"] = ((float)i) / 2;
                }
                else
                {
                    dr["GQ"] = i;
                }
                //dr["BC"] = "L1=" + (10 + 5.23).ToString();
                if (cd.bGQExist[0] && i < cd.GQDataCount[0])
                {
                    dr["工作电流1mA"] = cd.GQData[0, i];
                }
                if (cd.bGQExist[1] && i < cd.GQDataCount[1])
                {
                    dr["工作电流2mA"] = cd.GQData[1, i];
                }
                if (cd.bGQExist[2] && i < cd.GQDataCount[2])
                {
                    dr["工作电流4mA"] = cd.GQData[2, i];
                }
                if (cd.bGQExist[3] && i < cd.GQDataCount[3])
                {
                    dr["工作电流5mA"] = cd.GQData[3, i];
                }


                if (cd.bGQExist[0] && ((i + 1) == cd.GQDataCount[0]))
                {
                    dr["L1"] = cd.GQData[0, i];
                }
                if (cd.bGQExist[1] && ((i + 1) == cd.GQDataCount[1]))
                {
                    dr["L2"] = cd.GQData[1, i];
                }
                if (cd.bGQExist[2] && ((i + 1) == cd.GQDataCount[2]))
                {
                    dr["L3"] = cd.GQData[2, i];
                }
                if (cd.bGQExist[3] && ((i + 1) == cd.GQDataCount[3]))
                {
                    dr["L4"] = cd.GQData[3, i];
                }
                dt.Rows.Add(dr);
            }
        }
コード例 #16
0
 public string RxProc(char rx)
 {
     RxList[RxCount++] = rx;
     if (RxCount >= RxList.Length)
     {
         RxCount = 0;
         return(string.Empty);
     }
     if (RxCount == 1)
     {
         if (rx != '$')
         {
             RxCount = 0;
         }
     }
     else if (RxCount == ID.Length)
     {
         RxList[6] = '\0';
         string str = new string(RxList, 0, ID.Length);
         if (str != ID)
         {
             RxCount = 0;
         }
     }
     else if (rx == '*')
     {
         if (!bVerify)
         {
             int len = RxCount;
             RxCount = 0;
             return(new string(RxList, 0, len));
         }
     }
     else if (rx == 0x0a)
     {
         int len = RxCount;
         RxCount = 0;
         if (RxList[len - 2] == 0x0d)
         {
             if (bVerify)//校验
             {
                 byte cs = 0;
                 for (int i = 1; i < len - 5; i++)
                 {
                     cs ^= (byte)RxList[i];
                 }
                 byte cs1 = BytesOP.ASCII2Byte((byte)RxList[len - 4], (byte)RxList[len - 3]);
                 if (cs == cs1)
                 {
                     return(new string(RxList, 0, len));
                 }
             }
         }
     }
     return(string.Empty);
 }
コード例 #17
0
 void WaitingStart(object LockWatingThread)
 {
     while (true)
     {
         TcpModbusPacket tp = ReadPLC();
         if (tp != null)
         {
             ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
             if (BytesOP.GetBit(D100, 0))     //系统已经启动
             {
                 if (BytesOP.GetBit(D100, 1)) //判断正反转
                 {
                     bForeward = true;
                     this.Invoke((EventHandler)(delegate
                     {
                         listView1.Items[6].SubItems[1].Text = "正转";
                     }));
                 }
                 else
                 {
                     bForeward = false;
                     this.Invoke((EventHandler)(delegate
                     {
                         listView1.Items[6].SubItems[1].Text = "反转";
                     }));
                 }
                 SetMotor(openRev, NiuJuPID.sp);
                 motorRev    = openRev;
                 motorTorque = NiuJuPID.sp;
                 this.Invoke((EventHandler)(delegate
                 {
                     listView1.Items[6].SubItems[1].Text = openRev.ToString("F3");
                     listView2.Items[6].SubItems[1].Text = NiuJuPID.sp.ToString();
                     listView1.Items[1].SubItems[1].Text = "";
                     listView2.Items[1].SubItems[1].Text = "";
                     chart1.Series[0].Points.Clear();
                     chart1.Series[1].Points.Clear();
                     chart2.Series[0].Points.Clear();
                     chart2.Series[1].Points.Clear();
                     openTimes = 0;
                     openTimer.Enabled = true;
                 }));
                 return;
             }
         }
         Thread.Sleep(1000);
         lock (LockWatingThread)
         {
             wpStart.SetProcessBarPerformStep();
             if (wpStart.HasBeenCancelled())
             {
                 return;
             }
         }
     }
 }
コード例 #18
0
 public static DeviceState UDPCommand_03(byte xy, byte dir, int nCount)//位移平台控制
 {
     byte[] tx = new byte[34];
     tx[0] = 0x03;
     tx[1] = xy;
     tx[2] = dir;
     tx[3] = BytesOP.GetLowByte((ushort)nCount);
     tx[4] = BytesOP.GetHighByte((ushort)nCount);
     return(udpProc(tx, 5000));
 }
コード例 #19
0
        public static void CP1616ComSend(ref SerialPort serialPort, byte com, ushort addr, uint b)
        {
            ushort b1, b2;

            b1 = BytesOP.GetHighShort(b);
            b2 = BytesOP.GetLowShort(b);
            CP1616ComSend(ref serialPort, com, addr, new byte[4] {
                BytesOP.GetHighByte(b1), BytesOP.GetLowByte(b1), BytesOP.GetHighByte(b2), BytesOP.GetLowByte(b2)
            });
        }
コード例 #20
0
        public static CP1616Packet CP1616ComProc(ref SerialPort serialPort, byte com, ushort addr, uint b)
        {
            ushort b1, b2;

            b1 = BytesOP.GetHighShort(b);
            b2 = BytesOP.GetLowShort(b);
            return(CP1616ComProc(ref serialPort, com, addr, new byte[4] {
                BytesOP.GetHighByte(b1), BytesOP.GetLowByte(b1), BytesOP.GetHighByte(b2), BytesOP.GetLowByte(b2)
            }, 5));
        }
コード例 #21
0
        public List <byte> ToArray()
        {
            byte x;

            TotalLength = SetTotalLength();
            List <byte> ret = new List <byte>();

            ret.Add(BytesOP.MakeByte(Version, HeaderLength));
            ret.Add(TypeOfService);
            ret.Add(BytesOP.GetHighByte(TotalLength));
            ret.Add(BytesOP.GetLowByte(TotalLength));
            ret.Add(BytesOP.GetHighByte(Identification));
            ret.Add(BytesOP.GetLowByte(Identification));
            x  = (byte)(Flags << 5);
            x += (byte)(FragmentOffset >> 8);
            ret.Add(x);
            ret.Add(BytesOP.GetLowByte(FragmentOffset));
            ret.Add(TimeToLive);
            ret.Add(Protocol);
            ret.Add(0x00);//校验和
            ret.Add(0x00);
            ret.Add(SourceAddress[0]);
            ret.Add(SourceAddress[1]);
            ret.Add(SourceAddress[2]);
            ret.Add(SourceAddress[3]);
            ret.Add(DastinationAddress[0]);
            ret.Add(DastinationAddress[1]);
            ret.Add(DastinationAddress[2]);
            ret.Add(DastinationAddress[3]);
            if (HeaderLength > 0x05)
            {
                for (int i = 0; i < ((HeaderLength - 0x05) * 4); i++)
                {
                    ret.Add(Options[i]);
                }
            }
            HeaderVerify = Verify.GetVerify_IP(ret.ToArray());
            ret[10]      = BytesOP.GetHighByte(HeaderVerify);
            ret[11]      = BytesOP.GetLowByte(HeaderVerify);
            switch (Protocol)
            {
            case 0x06:    //TCP
                FakeTcpHeader fh = new FakeTcpHeader(SourceAddress, DastinationAddress);
                fh.count = (ushort)(TotalLength - HeaderLength * 4);
                TCPPacket   tcp     = (TCPPacket)oProtocolContent;
                List <Byte> TCPList = tcp.ToArray(fh);
                foreach (byte b in TCPList)
                {
                    ret.Add(b);
                }
                break;
            }
            Identification++;
            return(ret);
        }
コード例 #22
0
ファイル: Form1.cs プロジェクト: dongdong-2009/LiChunYu
        static void ShiftFshKey()
        {
            FlashAddr = 0X2074;
            R0X41     = ReadFshData(R0XC1);

            if (R0X41 != 0)
            {
                for (; ;)
                {
                    //			asm("BANKSEL _A.R0XAB");
                    //			asm("RRCF _A.R0XAB, F, B");
                    //			asm("RRCF _A.R0XAC, F, B");
                    //			asm("RRCF _A.R0XAD, F, B");
                    //			asm("RRCF _A.R0XAE, F, B ");
                    ulR0XAB >>= 1;

                    BytesOP.ClrBit(ref ulR0XAB, 7);
                    if (BytesOP.GetBit(ulR0XAB, 27))
                    {
                        BytesOP.SetBit(ref ulR0XAB, 7);
                    }
                    ;

                    //           asm("BANKSEL _A.R0XAF");
                    //		   asm("RRCF _A.R0XAF, F, B");
                    //		   asm("RRCF _A.R0XB0, F, B");
                    //		   asm("RRCF _A.R0XB1, F, B");
                    //		   asm("RRCF _A.R0XB2, F, B");
                    ulR0XAF >>= 1;

                    BytesOP.ClrBit(ref ulR0XAF, 7);
                    if (BytesOP.GetBit(ulR0XAF, 27))
                    {
                        BytesOP.SetBit(ref ulR0XAF, 7);
                    }
                    ;

                    R0X41--;
                    if (R0X41 == 0)
                    {
                        break;
                    }
                }
            }

            R0XBB = 0XAB;
            R0XBC = 0XB3;
            R0X52 = 0X7F;
            R0X53 = 0X3F;

            BytesOP.SetBit(ref R0XCB, 6);
            GetFshKey();
        }
コード例 #23
0
 public byte RNum;//总线电阻序号
 public byte[] GetTxData()
 {
     byte[] ret = new byte[7];
     ret[0] = BytesOP.GetLowByte(Prescaler);
     ret[1] = BytesOP.GetHighByte(Prescaler);
     ret[2] = BS1;
     ret[3] = BS2;
     ret[4] = SJW;
     ret[5] = Param;
     ret[6] = RNum;
     return(ret);
 }
コード例 #24
0
 public static DeviceState UDPCommand_02(int Tex, int nCount)//图像采集控制帧
 {
     byte[] tx = new byte[34];
     tx[0] = 0x02;
     tx[1] = BytesOP.GetLowByte(BytesOP.GetLowShort((uint)Tex));
     tx[2] = BytesOP.GetHighByte(BytesOP.GetLowShort((uint)Tex));
     tx[3] = BytesOP.GetLowByte(BytesOP.GetHighShort((uint)Tex));
     tx[4] = BytesOP.GetHighByte(BytesOP.GetHighShort((uint)Tex));
     tx[5] = BytesOP.GetLowByte((ushort)nCount);
     tx[6] = BytesOP.GetHighByte((ushort)nCount);
     return(udpProc(tx, 1000));
 }
コード例 #25
0
 public byte[] Data;//[UART_WithPC_BUFMAX-6];
 public byte[] GetTxData()
 {
     byte[] ret = new byte[Data.Length + ParamLen];
     ret[0] = BytesOP.GetLowByte(Retry);
     ret[1] = BytesOP.GetHighByte(Retry);
     ret[2] = BytesOP.GetLowByte(RxTimeOut);
     ret[3] = BytesOP.GetHighByte(RxTimeOut);
     for (int i = 0; i < Data.Length; i++)
     {
         ret[ParamLen + i] = Data[i];
     }
     return(ret);
 }
コード例 #26
0
ファイル: Form1.cs プロジェクト: dongdong-2009/LiChunYu
        static void ShiftMixKey()
        {
            byte t;
            int  p0;

            R0XBD = 0XE0;

            for (; ;)
            {
                FlashAddr = 0X1F74;
                p0        = R0XBB;
                t         = RAMBUF[p0 - 0x83];

                t = (byte)((t >> 1) | R0XBD);

                R0X52 = ReadFshData(t);

                t = RAMBUF[p0 - 0x83];

                if ((t & 1) == 0)
                {
                    R0X52 = (byte)(R0X52 >> 4);
                }

                R0X52 &= 0XF;
                p0     = R0XBC;

                if (!BytesOP.GetBit(R0XBD, 5))
                {
                    R0XBC++;

                    t   = RAMBUF[p0 - 0x83];
                    t <<= 4;

                    R0X52 |= t;
                }

                RAMBUF[p0 - 0x83] = R0X52;

                R0XBB++;

                t     = R0XBD;
                R0XBD = (byte)(R0XBD - 0X20);

                //if (CARRY==0) break;
                if (t < 0x20)
                {
                    break;
                }
            }
        }
コード例 #27
0
 public static DeviceState UDPCommand_01()//图像采集板配置帧
 {
     byte[] tx = new byte[34];
     tx[0] = 0x01;
     tx[1] = BytesOP.GetLowByte((ushort)SystemParam.CCD_M);
     tx[2] = BytesOP.GetHighByte((ushort)SystemParam.CCD_M);
     tx[3] = BytesOP.GetLowByte((ushort)SystemParam.CCD_N);
     tx[4] = BytesOP.GetHighByte((ushort)SystemParam.CCD_N);
     tx[5] = (byte)SystemParam.CCD_phi;
     tx[6] = 0x67;
     tx[7] = 0x00;
     tx[8] = (byte)(SystemParam.CCD_PGA + 0x0b);
     return(udpProc(tx, 1000));
 }
コード例 #28
0
ファイル: ASCII_Master.cs プロジェクト: wangf0228GitHub/WFLib
        public static byte[] TxCommand(byte[] txBuffer)
        {
            byte[] ret = new byte[txBuffer.Length * 2 + 5];
            ret[0] = (byte)':';
            for (int i = 0; i < txBuffer.Length; i++)
            {
                BytesOP.Byte2ASCII(txBuffer[i], out ret[1 + (i << 1)], out ret[1 + (i << 1) + 1]);
            }
            byte sum = Verify.GetVerify_byteSum(txBuffer);

            BytesOP.Byte2ASCII(sum, out ret[txBuffer.Length * 2 + 1], out ret[txBuffer.Length * 2 + 2]);
            ret[txBuffer.Length * 2 + 3] = 0x0d;
            ret[txBuffer.Length * 2 + 4] = 0x0a;
            return(ret);
        }
コード例 #29
0
 public DeviceState(byte[] _all)
 {
     all = new byte[_all.Length];
     Array.Copy(_all, all, _all.Length);
     CW          = all[0];
     rxCW        = all[1];
     Illuminance = BytesOP.MakeShort(all[3], all[2]);
     deviceState = all[4];
     CMOSState   = all[5];
     fMain.Invoke((EventHandler)(delegate
     {
         fMain.lbDeviceState.Text = deviceState == 0x01 ? "正常" : "异常";
         fMain.lbCMOSState.Text = CMOSState == 0x01 ? "正常" : "异常";
         fMain.lbIlluminance.Text = Illuminance.ToString();
     }));
 }
コード例 #30
0
        public static byte[] ReTransPicDatas(ushort[,] ya, int row, int col)
        {
            int k;

            byte[] ret = new byte[row * col * 2];
            for (int m = 0; m < row; m++)
            {
                for (int n = 0; n < col; n++)
                {
                    k = n * 2;
                    ret[k + 2 * col * m + 1] = BytesOP.GetHighByte(ya[m, n]);
                    ret[k + 2 * col * m]     = BytesOP.GetLowByte(ya[m, n]);
                }
            }
            return(ret);
        }