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 serial
ser = serial.Serial() #Create Serial Object
ser.baudrate = 115200 #Set the appropriate BaudRate
ser.timeout = 50 #The maximum timeout that the program waits for a reply. If 0 is used, the pot is blocked until readline returns
ser.port = '/dev/ttyACM0' # Specify the device file descriptor
ser.open() #Open the serial connection
ser.write(b'V\n') #Write the version command "V\n" encoded in Binary
s = ser.readline() # Read the response
print('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.py
C
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;
}
}