Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

 

In this example, the Calliope learning computer sends data to a connected PC via a serial port.

The PC receives the data and displays the data in a console program.

 

 

The code serial.writeLine("a text to send") is sent to the computer's COM interface via the built-in interface.

    serial. writeLine(Messwert + "")   //\r \n

 

 

Calliope Beispiel Code

Sending text over the serial interface

The code is in javascript

The code in the Caliope for sending data to the serial interface is described here

basic. forever(() => {

    //-----< MainLoop >------

 

    Reading temperature

    let measured value =  input. compassHeading()

 

    serial. writeLine(Messwert + "")   //\r \n

 

    wait 1 second

    basic. pause(1000)

 

    //-----</ MainLoop >------

})

 

 

 

 

Calliope is programmed here and loaded into the hardware

https://makecode.calliope.cc/

 

 

Receiving via the COM interface of the PC

 

Console Programm

 

The serial interface is first set

        < Global Variables >

        static SerialPort serial_Caliope;

 

            --< create serial >--

            Defining serial interface

            serial_Caliope = new SerialPort

            {

                PortName = "COM7",

                BaudRate = 115200,

                Parity = Parity.None,

                DataBits = 8,

                Handshake = Handshake.None,

                RtsEnable = true,

                StopBits = StopBits.One

            };

 

Then the COM interface is connected or opened for querying

 

            Start serial interface

            serial_Caliope.Open();

            --</ create serial >--

 

Values are then read via the command

string comErgebnis = serial_Caliope.ReadLine();

 

And then displayed in the console

Console.WriteLine(comErgebnis);

 

A small console program reads the data cyclically at the serial port

using System;

using System.Collections.Generic;

using System.IO.Ports;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Timers;

 

namespace _02_Console_Net

{

    class Program

    {

        < Global Variables >

        static SerialPort serial_Caliope;

 

        static void Main(string[] args)

        {

            //--------------< Main >---------------

            --< create serial >--

            Defining serial interface

            serial_Caliope = new SerialPort

            {

                PortName = "COM7",

                BaudRate = 115200,

                Parity = Parity.None,

                DataBits = 8,

                Handshake = Handshake.None,

                RtsEnable = true,

                StopBits = StopBits.One

            };

 

            Start serial interface

            serial_Caliope.Open();

            --</ create serial >--

 

 

            //-< Timer >-

            Timer timerA = new Timer(1000);

            timerA.Elapsed += Timer_Elapsed;

            timerA.Start();

            //-</ Timer >-

 

 

            Spend

            Console.ReadKey();

            //

 

 

            //--------------</ Main >---------------

        }

 

 

        #region  Events

        //----< Events >-------

        private static void Timer_Elapsed(object sender, ElapsedEventArgs e)

        {

            string comErgebnis = serial_Caliope.ReadLine();

            Console.WriteLine(comErgebnis);

        }

        //----</ Events >-------

        #endregion  /Events

 

    }

}

 

 

Mobile
»
Calliope : Sending text via serial interface to a pc

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de