コード例 #1
0
        /// <summary>
        /// 处理接收到的Ntrip数据。
        /// </summary>
        /// <param name="myBytes"></param>
        private void ProcessReceivingData(byte[] myBytes)
        {
            //写到串口
            if (COMPort.IsOpen)
            {
                COMPort.Write(myBytes, 0, myBytes.Length);
            }
            //写到本地接收器
            if (this.Option.IsWriteToLocal)
            {
                WriteRawDataToLocal(myBytes);
            }
            //实时解析处理器
            if (Rtcm3DataReceiver != null)
            {
                Rtcm3DataReceiver.Receive(myBytes);
            }

            if (ReceivedByteCount == 0)
            {
                OnInfoProduced(Name + " NTRIP Client is receiving data.");
            }
            ReceivedByteCount += myBytes.Length;
            OnInstantInfoProduced(Name + " Connected, " + Strings.Format(ReceivedByteCount, "###,###,###,##0") + " bytes received.");
        }
コード例 #2
0
        public void SendPacket()
        {
            if (!IsConnected)
            {
                return;
            }
            var data = GSCommand.Bytes;

            COMPort.Write(data, 0, data.Length);
        }
コード例 #3
0
ファイル: RocketPortModel.cs プロジェクト: ESFT/command
        public void SendPacket(bool launchArmed)
        {
            RocketCommand.LaunchArmed = launchArmed;
            if (!IsConnected)
            {
                return;
            }
            var data = RocketCommand.Bytes;

            COMPort.Write(data, 0, data.Length);
        }
コード例 #4
0
        private void btnWrite_Click(object sender, EventArgs e)
        {
            byte[] buff = new byte[41];
            buff[0] = 0xaa;
            buff[1] = 0x57; // W
            buff[2] = Convert.ToByte(chkPPMA.Checked);
            buff[3] = (byte)(cbFrameA.SelectedIndex + 4);
            buff[4] = (byte)(cbChannelsA.SelectedIndex + 1);

            buff[5]  = (byte)(cbChA1.SelectedIndex);
            buff[6]  = (byte)(cbChA2.SelectedIndex);
            buff[7]  = (byte)(cbChA3.SelectedIndex);
            buff[8]  = (byte)(cbChA4.SelectedIndex);
            buff[9]  = (byte)(cbChA5.SelectedIndex);
            buff[10] = (byte)(cbChA6.SelectedIndex);
            buff[11] = (byte)(cbChA7.SelectedIndex);
            buff[12] = (byte)(cbChA8.SelectedIndex);
            buff[13] = (byte)(cbChA9.SelectedIndex);
            buff[14] = (byte)(cbChA10.SelectedIndex);
            buff[15] = (byte)(cbChA11.SelectedIndex);
            buff[16] = (byte)(cbChA12.SelectedIndex);
            buff[17] = (byte)(cbChA13.SelectedIndex);
            buff[18] = (byte)(cbChA14.SelectedIndex);
            buff[19] = (byte)(cbChA15.SelectedIndex);
            buff[20] = (byte)(cbChA16.SelectedIndex);

            buff[21] = Convert.ToByte(chkPPMB.Checked);
            buff[22] = (byte)(cbFrameB.SelectedIndex + 4);
            buff[23] = (byte)(cbChannelsB.SelectedIndex + 1);

            buff[24] = (byte)(cbChB1.SelectedIndex);
            buff[25] = (byte)(cbChB2.SelectedIndex);
            buff[26] = (byte)(cbChB3.SelectedIndex);
            buff[27] = (byte)(cbChB4.SelectedIndex);
            buff[28] = (byte)(cbChB5.SelectedIndex);
            buff[29] = (byte)(cbChB6.SelectedIndex);
            buff[30] = (byte)(cbChB7.SelectedIndex);
            buff[31] = (byte)(cbChB8.SelectedIndex);
            buff[32] = (byte)(cbChB9.SelectedIndex);
            buff[33] = (byte)(cbChB10.SelectedIndex);
            buff[34] = (byte)(cbChB11.SelectedIndex);
            buff[35] = (byte)(cbChB12.SelectedIndex);
            buff[36] = (byte)(cbChB13.SelectedIndex);
            buff[37] = (byte)(cbChB14.SelectedIndex);
            buff[38] = (byte)(cbChB15.SelectedIndex);
            buff[39] = (byte)(cbChB16.SelectedIndex);

            buff[40] = 0x5d;

            COMPort.Open();
            COMPort.Write(buff, 0, 41);
            COMPort.Close();
        }
コード例 #5
0
    public static void ThreadWriteProcess()
    {
        COMPort cp = new COMPort("COM1");

        cp.Open();
        for (int i = 0; i < 100; i++)
        {
            Thread.Sleep(100);
            cp.setBuffer(System.Text.Encoding.ASCII.GetBytes("hello world"));
            cp.Write();
        }
        cp.Close();
    }
コード例 #6
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (button1.Text == "打开串口")
     {
         if (comboBoxBaudRate.SelectedIndex == 1)
         {
             COMPort.BaudRate = 115200;
         }
         else
         {
             COMPort.BaudRate = 9600;
         }
         try
         {
             COMPort.PortName = comboBoxCOM.Text;
             COMPort.Open();
         }
         catch (ArgumentException exc)
         {
             MessageBox.Show(exc.Message);
             return;
         }
         if (COMPort.IsOpen)
         {
             MessageBox.Show("打开成功");
             string s   = "SGT_Debuger Online";
             byte[] buf = Encoding.ASCII.GetBytes(s);
             COMPort.Write(buf, 0, s.Length);
             button1.Text = "关闭串口";
         }
         else
         {
             MessageBox.Show("存在问题");
         }
     }
     else
     {
         string s   = "SGT_Debuger Offline";
         byte[] buf = Encoding.ASCII.GetBytes(s);
         COMPort.Write(buf, 0, s.Length);
         COMPort.Close();
         button1.Text = "打开串口";
     }
 }
コード例 #7
0
 private void ModbusSendReceive(object param)
 {
     lock (this)
     {
         try
         {
             ModbusParam parameters;
             if (param is ModbusParam)
             {
                 parameters = (ModbusParam)param;
             }
             else
             {
                 throw new ModbusPDUException("Wrong parametrization of ModbusSendReceive method.");
             }
             byte[] responseFrame = new byte[(int)parameters.ResponseSize];
             COMPort.DiscardInBuffer();
             COMPort.Write(parameters.RequestADU, 0, parameters.RequestADU.Length);
             Thread.Sleep(ResponseWaitingDelay);
             COMPort.Read(responseFrame, 0, (int)parameters.ResponseSize);
             byte[] adu = ModbusSerialPDU.extractADU(responseFrame);
             if (responseFrame[1] > (byte)127)
             {
                 throw new ModbusPDUException(String.Format("Modbus application error : function {0:X}, exception {1:X}", responseFrame[1], responseFrame[2]));
             }
             else
             if (responseFrame[1] == 0x03)
             {
                 Int16[] values = GetValuesFromResponseADU03(adu);
                 ModbusDataReceived(values);
             }
         }
         catch (Exception ex)
         {
             commException = ex;
             ModbusError(ex);
         }
     }
 }
コード例 #8
0
 private void SendOut(char[] message)
 {
     COMPort.Write(message, 0, 5);
     Thread.Sleep(100);
 }
コード例 #9
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            byte[] buff = new byte[41];
            buff[0] = 0xaa;
            buff[1] = 0x52; // R

            for (int i = 2; i < 40; i++)
            {
                buff[i] = 0;
            }

            buff[40] = 0x5d;

            COMPort.Open();
            COMPort.Write(buff, 0, 41);

            int cnt = 0;

            while (cnt < 40)
            {
                if (COMPort.BytesToRead > 40)
                {
                    cnt = COMPort.Read(buff, 0, 41);
                }
            }
            COMPort.Close();

            chkPPMA.Checked = (buff[2] == 1);
            if (buff[3] - 4 < 7)
            {
                cbFrameA.SelectedIndex = buff[3] - 4;
            }
            if (buff[4] - 1 < 16)
            {
                cbChannelsA.SelectedIndex = buff[4] - 1;
            }

            if (buff[5] < 17)
            {
                cbChA1.SelectedIndex = buff[5];
            }
            if (buff[6] < 17)
            {
                cbChA2.SelectedIndex = buff[6];
            }
            if (buff[7] < 17)
            {
                cbChA3.SelectedIndex = buff[7];
            }
            if (buff[8] < 17)
            {
                cbChA4.SelectedIndex = buff[8];
            }
            if (buff[9] < 17)
            {
                cbChA5.SelectedIndex = buff[9];
            }
            if (buff[10] < 17)
            {
                cbChA6.SelectedIndex = buff[10];
            }
            if (buff[11] < 17)
            {
                cbChA7.SelectedIndex = buff[11];
            }
            if (buff[12] < 17)
            {
                cbChA8.SelectedIndex = buff[12];
            }
            if (buff[13] < 17)
            {
                cbChA9.SelectedIndex = buff[13];
            }
            if (buff[14] < 17)
            {
                cbChA10.SelectedIndex = buff[14];
            }
            if (buff[15] < 17)
            {
                cbChA11.SelectedIndex = buff[15];
            }
            if (buff[16] < 17)
            {
                cbChA12.SelectedIndex = buff[16];
            }
            if (buff[17] < 17)
            {
                cbChA13.SelectedIndex = buff[17];
            }
            if (buff[18] < 17)
            {
                cbChA14.SelectedIndex = buff[18];
            }
            if (buff[19] < 17)
            {
                cbChA15.SelectedIndex = buff[19];
            }
            if (buff[20] < 17)
            {
                cbChA16.SelectedIndex = buff[20];
            }

            chkPPMB.Checked = (buff[21] == 1);
            if (buff[22] - 4 < 7)
            {
                cbFrameB.SelectedIndex = buff[22] - 4;
            }
            if (buff[23] - 1 < 16)
            {
                cbChannelsB.SelectedIndex = buff[23] - 1;
            }

            if (buff[24] < 17)
            {
                cbChB1.SelectedIndex = buff[24];
            }
            if (buff[25] < 17)
            {
                cbChB2.SelectedIndex = buff[25];
            }
            if (buff[26] < 17)
            {
                cbChB3.SelectedIndex = buff[26];
            }
            if (buff[27] < 17)
            {
                cbChB4.SelectedIndex = buff[27];
            }
            if (buff[28] < 17)
            {
                cbChB5.SelectedIndex = buff[28];
            }
            if (buff[29] < 17)
            {
                cbChB6.SelectedIndex = buff[29];
            }
            if (buff[30] < 17)
            {
                cbChB7.SelectedIndex = buff[30];
            }
            if (buff[31] < 17)
            {
                cbChB8.SelectedIndex = buff[31];
            }
            if (buff[32] < 17)
            {
                cbChB9.SelectedIndex = buff[32];
            }
            if (buff[33] < 17)
            {
                cbChB10.SelectedIndex = buff[33];
            }
            if (buff[34] < 17)
            {
                cbChB11.SelectedIndex = buff[34];
            }
            if (buff[35] < 17)
            {
                cbChB12.SelectedIndex = buff[35];
            }
            if (buff[36] < 17)
            {
                cbChB13.SelectedIndex = buff[36];
            }
            if (buff[37] < 17)
            {
                cbChB14.SelectedIndex = buff[37];
            }
            if (buff[38] < 17)
            {
                cbChB15.SelectedIndex = buff[38];
            }
            if (buff[39] < 17)
            {
                cbChB16.SelectedIndex = buff[39];
            }
        }