Esempio n. 1
0
    // Client thread which does not block Update()
    void NetMQClient()
    {
        AsyncIO.ForceDotNet.Force();
        NetMQConfig.ManualTerminationTakeOver();
        NetMQConfig.ContextCreate(true);

        //string msg;
        var timeout = new System.TimeSpan(0, 0, 1); //1sec

        Debug.Log("Connect to the server.");

        pubSocket = new PublisherSocket();
        pubSocket.Options.ReceiveHighWatermark = 0;
        pubSocket.Connect("tcp://192.168.1.122:55556");

        bool is_connected = true;

        while (is_connected && stop_thread_ == false)
        {
            pubSocket.TrySendFrame(timeout, final);
        }

        pubSocket.Close();
        Debug.Log("ContextTerminate.");
        NetMQConfig.ContextTerminate();
        NetMQConfig.Cleanup();
    }
Esempio n. 2
0
    void OnApplicationQuit()
    {
        pubSocket.TrySendFrame(new System.TimeSpan(0, 0, 1), "0:0:0>");

        lock (thisLock_) stop_thread_ = true;
        client_thread_.Join();
        Debug.Log("Quit the thread.");
    }
Esempio n. 3
0
        protected override void OnReceived(byte[] buffer, long offset, long size)
        {
            var frame = new byte[size];

            Array.Copy(buffer, offset, frame, 0, size);

            publisher.TrySendFrame(frame);

            //Log.Debug(Encoding.ASCII.GetString(frame));

            //SendAsync(buffer, offset, size);
        }
Esempio n. 4
0
        private void Publish()
        {
            publishing = true;

            publisherSocket.Connect(@"tcp://127.0.0.1:17233");

            while (publishing)
            {
                if (teleprinter.CachedDataAvailableEvent.WaitOne(TimeSpan.FromMilliseconds(200)))
                {
                    if (!publisherSocket.TrySendFrame(teleprinter.GetCachedOutput()))
                    {
                        Log.Debug("Failed to send frame.");
                    }
                }
            }
        }
        public bool Send <T, C>(Message <T> request, C content, string msgType)
        {
            var ioPubMessage = new Message <C>
            {
                Identities   = request.Identities,
                Delimiter    = request.Delimiter,
                ParentHeader = request.Header,
                Header       = new Header()
                {
                    UserName    = request.Header.UserName,
                    Session     = request.Header.Session,
                    Date        = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"),
                    MessageId   = Guid.NewGuid().ToString(),
                    MessageType = msgType,
                    Version     = request.Header.Version
                },
                Metadata = request.Metadata,
                Content  = content
            };

            var           encoder   = new UTF8Encoding();
            List <string> messages  = new List <string>();
            var           signature = Sign <C>(key, ioPubMessage, messages, iopub);

            // send
            foreach (var id in request.Identities)
            {
                iopub.TrySendFrame(encoder.GetBytes(id), true);
            }
            iopub.SendFrame(ioPubMessage.Delimiter, true);
            iopub.SendFrame(signature, true);
            for (int i = 0; i < messages.Count; i++)
            {
                iopub.SendFrame(messages[i], i < messages.Count - 1);
            }

            return(true);
        }
        private void ZMQTimer_Tick(object sender, EventArgs e)
        {
            Console.WriteLine("TX: ZMQ TICK");
            List <DataParameter> paramsToSend = new List <DataParameter>();

            // parameter grid
            if (dataGridView1 != null)
            {
                try
                {
                    Console.WriteLine("TX: ========");
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (row.IsNewRow)
                        {
                            continue;
                        }

                        object cell1Value = row.Cells[0].Value;
                        object cell2Value = row.Cells[1].Value;
                        object cell3Value = row.Cells[2].Value;

                        if (cell1Value == null || cell2Value == null || cell3Value == null)
                        {
                            Console.WriteLine("TX: Cell value is null: " + cell1Value + ", " + cell2Value + ", " + cell3Value);
                            continue;
                        }

                        string parameterIndex = cell1Value.ToString();;
                        string parameterValue = cell2Value.ToString();
                        string parameterType  = cell3Value.ToString();

                        // get index value and parse to UInt16
                        UInt16 index;
                        UInt16.TryParse(parameterIndex, out index);
                        object value = null;

                        // parse the value
                        switch (parameterType)
                        {
                        case "Int 8":
                            sbyte sbyteVal;
                            if (!sbyte.TryParse(parameterValue, out sbyteVal))
                            {
                                goto error;
                            }
                            value = sbyteVal;
                            break;

                        case "UInt 8":
                            byte byteVal;
                            if (!byte.TryParse(parameterValue, out byteVal))
                            {
                                goto error;
                            }
                            value = byteVal;
                            break;

                        case "Int 16":
                            Int16 int16Val;
                            if (!Int16.TryParse(parameterValue, out int16Val))
                            {
                                goto error;
                            }
                            value = int16Val;
                            break;

                        case "UInt 16":
                            UInt16 uint16Val;
                            if (!UInt16.TryParse(parameterValue, out uint16Val))
                            {
                                goto error;
                            }
                            value = uint16Val;
                            break;

                        case "Int 32":
                            Int32 Int32Val;
                            if (!Int32.TryParse(parameterValue, out Int32Val))
                            {
                                goto error;
                            }
                            value = Int32Val;
                            break;

                        case "UInt 32":
                            UInt32 UInt32Val;
                            if (!UInt32.TryParse(parameterValue, out UInt32Val))
                            {
                                goto error;
                            }
                            value = UInt32Val;
                            break;

                        case "Int 64":
                            Int64 Int64Val;
                            if (!Int64.TryParse(parameterValue, out Int64Val))
                            {
                                goto error;
                            }
                            value = Int64Val;
                            break;

                        case "UInt 64":
                            UInt64 UInt64Val;
                            if (!UInt64.TryParse(parameterValue, out UInt64Val))
                            {
                                goto error;
                            }
                            value = UInt64Val;
                            break;

                        case "Float":
                            float floatVal;
                            if (!float.TryParse(parameterValue, out floatVal))
                            {
                                goto error;
                            }
                            value = floatVal;
                            break;

                        case "Double":
                            double doubleVal;
                            if (!double.TryParse(parameterValue, out doubleVal))
                            {
                                goto error;
                            }
                            value = doubleVal;
                            break;

                        default:
                            Console.WriteLine("Type %s not supported.", parameterType);
                            goto error;
                        }


                        // define new parameter object
                        DataParameter p = new DataParameter();
                        p.Index = index;
                        p.Data  = value;

                        // add parameter to the list of parameters to send
                        paramsToSend.Add(p);
                        Console.WriteLine("TX: " + index + ": " + value + "(" + parameterType + ")");
                    }
                } catch (Exception ee) {
                    Console.WriteLine("ERROR: Something wrong with data table");
                    Console.WriteLine(ee.ToString());
                }
            }
            else
            {
                Console.WriteLine("gridview is null");
            }

            dataGridView1.Update();
            dataGridView1.Refresh();

            rPodI2CTX formatter = new rPodI2CTX();

            byte[] paramData = formatter.formatTransmitParameters(paramsToSend);
            byte[] header    = Encoding.ASCII.GetBytes("telemetry " + ZMQNodeTXT.Text);
            byte[] toSend    = header.Concat(paramData).ToArray();

            //Console.WriteLine(paramsToSend);
            pubSocket.TrySendFrame(TimeSpan.FromSeconds(1), toSend);

error:
            return;
        }
Esempio n. 7
0
        public void SendEntry(UNI_TOPIC topic, string sMsg)
        {
            string sMessage = $"{topic.ToString()}:{sMsg}";

            publisher.TrySendFrame(sMessage);
        }