Home>

visual studio 2017 C #

I want to make a BLE communication device called bitalino and a BLE communication windows app.
Eventually, I would like to make a GUI application with a windows form application, but first of all I made a console application in C # for communication confirmation.
Although it is called BLE communication, the PC side uses a virtual COM dongle, eventually serial communication, and BLE communication uses API.

The API is published on the following site, so this visual C # guy is used.
http://bitalino.com/en/development/apis

The following code was created by referring to the prepared dll called BITalino_x86.dll.
string ver = dev.version ();
By the way, it will solidify for about 3 seconds and raise an exception that the device was not found.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
    class Program
    {
        static void Main (string [] args)
        {
            try
            {
                // uncomment this block to search for Bluetooth devices
                / *
                Bitalino.DevInfo [] devs = Bitalino.find ();
                foreach (Bitalino.DevInfo d in devs)
                   Console.WriteLine ("{0}-{1}", d.macAddr, d.name);
                return;
                * /
                Console.WriteLine ("Connecting to device ...");
                // Bitalino dev = new Bitalino ("CC: 78: AB: 5E: 9D: 3D");// device MAC address 98: D3: 31: B2: 11: 6B
                Bitalino dev = new Bitalino ("COM3");// Bluetooth virtual COM port or USB-UART COM port
                Console.WriteLine ("Connected to device. Press Enter to exit.");
                string ver = dev.version ();// get device version string
                Console.WriteLine ("BITalino version: {0}", ver);
                dev.battery (10);// set battery threshold (optional)
                dev.start (1000, new int [] {0, 1, 2, 3, 4, 5});// start acquisition of all channels at 1000 Hz
                bool ledState = false;
                Bitalino.Frame [] frames = new Bitalino.Frame [100];
                for (int i = 0;i<frames.Length;i ++)
                    frames [i] = new Bitalino.Frame ();// must initialize all elements in the array
                do
                {
                    ledState =! ledState;// toggle LED state
                    dev.trigger (new bool [] {false, false, ledState, false});
                    dev.read (frames);// get 100 frames from device
                    Bitalino.Frame f = frames [0];// get a reference to the first frame of each 100 frames block
                    Console.WriteLine ("{0}: {1} {2} {3} {4};{5} {6} {7} {8} {9} {10}", // dump the first frame
                                      f.seq,
                                      f.digital [0], f.digital [1], f.digital [2], f.digital [3],
                                      f.analog [0], f.analog [1], f.analog [2], f.analog [3], f.analog [4], f.analog [5]);
                } while (! Console.KeyAvailable);// until a key is pressed
                dev.stop ();// stop acquisition
                dev.Dispose ();// disconnect from device
            }
            catch (Bitalino.Exception e)
            {
                Console.WriteLine ("BITalino exception: {0}", e.Message);
            }
        }
    }
}
  • Answer # 1

    I understand that the .NET API for windows and BLE communication are specifications that cannot communicate.

Related articles