예제 #1
0
        /// <summary>
        /// udp dataを取り込む。
        /// </summary>
        public void set_udp_kv_data(byte[] bytes, ref KV_DATA kd)
        {
            GCHandle gch = GCHandle.Alloc(bytes, GCHandleType.Pinned);

            kd = (KV_DATA)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(KV_DATA));
            gch.Free();
        }
예제 #2
0
        /// <summary>
        /// MT3 dataの計算
        /// </summary>
        /// <remarks>
        /// KV_DATA -> az,alt etcに変換
        /// </remarks>
        public void cal_mt3(KV_DATA kd)
        {
            //MT3
            x2pos         = (kd.xx2 << 16) + (kd.xx1 << 8) + kd.xx0; // <<16 ->256*256  <<8 ->256
            y2pos         = (kd.yy2 << 16) + (kd.yy1 << 8) + kd.yy0; // <<16 ->256*256  <<8 ->256
            x2v           = ((kd.v21 << 8) + kd.v20) << 6;
            y2v           = ((kd.v23 << 8) + kd.v22) << 6;
            udp_time_code = EndianChange(kd.UdpTimeCode);
            //MT2
            xpos = ((kd.x1 << 8) + kd.x0) << 4; // <<16 ->256*256  <<8 ->256
            ypos = ((kd.y1 << 8) + kd.y0) << 4; // <<16 ->256*256  <<8 ->256
            x1v  = ((kd.v11 << 8) + kd.v10) << 6;
            y1v  = ((kd.v13 << 8) + kd.v12) << 6;

            /*
             * kv_status = (UInt16)((kd.y3 << 8) + kd.y2);      //KV1000 DM503
             * data_request = (UInt16)((kd.x3 << 8) + kd.x2);   //KV1000 DM499
             * binStr_status = Convert.ToString(kv_status, 2);
             * binStr_request = Convert.ToString(data_request, 2);
             * Pos2AzAlt2();
             *
             * mt3mode = (short)((data_request & (1 << 4)) >> 4); //Set MT3Region(0=mmWest,1=mmEast)
             * if ((int)(kv_status & (1 << 10)) != 0) vaz2_kv = +x2v / 1000.0; // MR106 on:+
             * else vaz2_kv = -x2v / 1000.0;
             * if ((int)(kv_status & (1 << 11)) != 0)
             * { //mr107:Y2モータ回転方向
             *  if (mt3mode == mmEast) valt2_kv = -y2v / 1000.0;
             *  else valt2_kv = y2v / 1000.0;
             * }
             * else
             * {
             *  if (mt3mode == mmEast) valt2_kv = y2v / 1000.0;
             *  else valt2_kv = -y2v / 1000.0;
             * }
             *
             * mt3state_move_pre = mt3state_move;
             * mt3state_truck_pre = mt3state_truck;
             * mt3state_center_pre = mt3state_center;
             * mt3state_night_pre = mt3state_night;
             *
             * mt3state_move = (kv_status & (1 << 12)); //導入中フラグ
             * mt3state_truck = (kv_status & (1 << 13)); //追尾中フラグ
             * mt3state_night = (kv_status & (1 << 14)); //夜間フラグ
             * mt3state_center = (data_request & (1 << 2)); //センタリング中フラグ
             *
             * // truck開始時
             * if (mt3state_truck_pre == 0 && mt3state_truck != 0) kalman_init_flag = 1;
             *
             * // センタリング中 完了時
             * if (mt3state_center_pre != 0 && mt3state_center == 0) kalman_init_flag = 1;
             */
        }
예제 #3
0
        // 別スレッド処理(UDP) //IP 192.168.1.209
        private void worker_udp_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = (BackgroundWorker)sender;

            //バインドするローカルポート番号
            int localPort = mmFsiUdpPortKV1000SpCam2; //  24410;// broadcast mmFsiUdpPortMT3IDS2;

            System.Net.Sockets.UdpClient udpc4 = null;;
            try
            {
                udpc4 = new System.Net.Sockets.UdpClient(localPort);
            }
            catch (Exception ex)
            {
                //匿名デリゲートで表示する
                //this.Invoke(new dlgSetString(ShowRText), new object[] { richTextBox1, ex.ToString() });
                ShowRTextFW(ex.ToString());
            }

            //文字コードを指定する
            System.Text.Encoding enc = System.Text.Encoding.UTF8;
            //データを送信するリモートホストとポート番号
            //string remoteHost = "localhost";
            string remoteHost = "192.168.1.10"; // KV1000;
            int    remotePort = 8501;


            string           str;
            MOTOR_DATA_KV_SP kmd3 = new MOTOR_DATA_KV_SP();
            int     size          = Marshal.SizeOf(kmd3);
            KV_DATA kd            = new KV_DATA();
            int     sizekd        = Marshal.SizeOf(kd);


            // loop
            System.Net.IPEndPoint remoteEP = new System.Net.IPEndPoint(System.Net.IPAddress.Any, localPort);
            while (bw.CancellationPending == false)
            {
                //データを受信する
                byte[] rcvBytes = udpc4.Receive(ref remoteEP);

                if (remoteEP.Address.ToString() == remoteHost && remoteEP.Port == remotePort)
                {
                    //kd = ToStruct1(rcvBytes);
                    //bw.ReportProgress(0, kd);

                    string rcvMsg = enc.GetString(rcvBytes);
                    str = DateTime.Now.ToString("yyyyMMdd_HHmmss_fff") + "受信したデータ:[" + rcvMsg + "]\n";
                    ShowRTextFW(str);
                    //this.Invoke(new dlgSetString(ShowRText), new object[] { richTextBox1, str });
                }
                else
                {
                    string rcvMsg = enc.GetString(rcvBytes);
                    str = DateTime.Now.ToString("yyyyMMdd_HHmmss_fff") + "送信元アドレス:{0}/ポート番号:{1}/Size:{2}\n" + remoteEP.Address + "/" + remoteEP.Port + "/" + rcvBytes.Length + "[" + rcvMsg + "]\n";
                    ShowRTextFW(str);
                    //this.Invoke(new dlgSetString(ShowRText), new object[] { richTextBox1, str });
                }

                //データを送信する
                if (cmd_str_f != 0)
                {
                    //送信するデータを読み込む
                    string sendMsg   = cmd_str + "\r";// "test送信するデータ";
                    byte[] sendBytes = enc.GetBytes(sendMsg);

                    //リモートホストを指定してデータを送信する
                    udpc4.Send(sendBytes, sendBytes.Length, remoteHost, remotePort);
                    cmd_str_f = 0;
                }
            }

            //UDP接続を終了
            udpc4.Close();
        }