Пример #1
0
        //public void SetA10CRS(int new_heading_degree)
        //{
        //    "A-10C_radio.txt".DecodelineOfCommand("COURSE_KNOB");
        //}
        //public void SetA10Pressure()
        //{
        //    "A-10C_pressure.txt".DecodelineOfCommand();
        //}
        //public void SetA10Laste()
        //{
        //    "A-10C_test.txt".DecodelineOfCommand("TEST2");
        //}
        public int SendDCSCommand(string stringData)
        {
            var result = 0;

            try
            {
                //byte[] bytes = _iso8859_1.GetBytes(stringData);
                var unicodeBytes = Encoding.Unicode.GetBytes(stringData + "\n");
                var asciiBytes   = new List <byte>(stringData.Length);
                asciiBytes.AddRange(Encoding.Convert(Encoding.Unicode, Encoding.ASCII, unicodeBytes));
                result = UdpSockSend.Send(asciiBytes.ToArray(), asciiBytes.ToArray().Length, ipEndPointSender);
                //result = _udpSendClient.Send(bytes, bytes.Length, _ipEndPointSender);
            }
            catch (SocketException err)
            {
                if (!Stopped)
                {
                    throw err;
                }
            }

            return(result);
        }
Пример #2
0
        private void RunSensorPoll()
        {
            try
            {
                var ipEndPointReceiver = new IPEndPoint(IPAddress.Any, UdpPortRecept);
                var ipEndPointTablette = new IPEndPoint(IPAddress.Parse("192.168.1.165"), 7776);
                UdpSockRecept = new UdpClient(UdpPortRecept);


                Stopped = false;
                OnStarted(this, new EventArgs());
                var started = DateTime.Now;

                while (!Stopped)
                {
                    byte[] bytes = UdpSockRecept.Receive(ref ipEndPointReceiver);
                    int    len   = bytes.Length;
                    if (len == 0)
                    {
                        continue;
                    }
                    _state         = DCSBiosStateEnum.WAIT_FOR_SYNC;
                    _syncByteCount = 0;
                    //if (len==1)
                    //{
                    //    var unicodeBytes = Encoding.Unicode.GetBytes(stringData + "\n");
                    //    var asciiBytes = new List<byte>(stringData.Length);
                    //    asciiBytes.AddRange(Encoding.Convert(Encoding.Unicode, Encoding.ASCII, unicodeBytes));
                    //    UdpSockSend.Send(asciiBytes.ToArray(), asciiBytes.ToArray().Length, ipEndPointSender);
                    //}
                    //if (len == 3)
                    //{
                    //string d = GetData(4544, 240);
                    //var unicodeBytes = Encoding.Unicode.GetBytes(d);
                    //var asciiBytes = new List<byte>(d.Length);
                    //asciiBytes.AddRange(Encoding.Convert(Encoding.Unicode, Encoding.Default, unicodeBytes));
                    // IPEndPoint EndPointSender = new IPEndPoint(IPAddress.Parse("192.168.1.165"), 7776);
                    //int result = UdpSockSend.Send(asciiBytes.ToArray(), asciiBytes.ToArray().Length, EndPointSender);
                    UdpSockSend.Send(bytes, len, ipEndPointTablette);
                    //continue;
                    //}

                    //UdpSockSend.Send(asciiBytes.ToArray(), asciiBytes.ToArray().Length, ipEndPointSender);

                    //using (BinaryWriter bx = new BinaryWriter(File.Open(@"E:\file.bin", FileMode.Append)))
                    //{
                    //    bx.Write(0x11111111);
                    //    bx.Write(len);
                    //    bx.Write(bytes);
                    //}
                    // Console.WriteLine("debut " + len);
                    for (int i = 0; i < len; i++)
                    {
                        ProcessByte(bytes[i]);
                    }

                    //Console.WriteLine("fin");
                }
            }
            catch (SocketException err)
            {
                // A graceful shutdown calls close socket and throws an exception while blocked in Receive()
                // Ignore this exception unless it was not generated during shutdown sequence
                if (!Stopped)
                {
                    throw err;
                }
            }
        }