Hello Qiba
This program is the equivalent to the very famous Hello World in programming, but applied to our API. This program gets the firmware version from Qiba's devices and prints it to the screen.
Python3
import serialser = serial.Serial() #Create Serial Objectser.baudrate = 115200 #Set the appropriate BaudRateser.timeout = 50 #The maximum timeout that the program waits for a reply. If 0 is used, the pot is blocked until readline returnsser.port = '/dev/ttyACM0' # Specify the device file descriptorser.open() #Open the serial connectionser.write(b'V\n') #Write the version command "V\n" encoded in Binarys = ser.readline() # Read the responseprint('Version:' + s.decode('ascii')) # Print it on the terminal, note the decoding to ascii.To execute the program, just copy the code above to a file "helloqiba.py" and run it like shown below.
sudo python3 helloqiba.pyC
It is necessary to install the System.IO.Ports package to use this example:
[https://www.nuget.org/packages/System.IO.Ports/](https://www.nuget.org/packages/System.IO.Ports/)**
**
x
using System.IO.Ports;public class Program { static SerialPort _serialPort; public static void Main() { // Create a new SerialPort object with default settings. _serialPort = new SerialPort(); StringComparer stringComparer = StringComparer.Ordinal; // Change the serial port properties: _serialPort.PortName = "COM5"; //Change port device _serialPort.BaudRate = 115200; _serialPort.Parity = Parity.None; _serialPort.DataBits = 8; _serialPort.StopBits = StopBits.One; _serialPort.Handshake = Handshake.None; // Set the read/write timeouts _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500; _serialPort.Open(); WriteSerial("V"); ReadSerial(); } //Write a string to serial port public static void WriteSerial(string command) { _serialPort.WriteLine(command); } //Read a reply from serial port. Returns empty string if nothing is read within timeout public static string ReadSerial() { string message; try { message = _serialPort.ReadLine(); Console.WriteLine(message); }catch (TimeoutException) { return ""; } return message; }}