hello,
and thank you for the help
after the syntax of the program output that are sent are of type Byte.
can I send data de type Real (float)?
I used the following the syntax program:
using System.IO.Ports;
using System.Text;
using System.Threading;
namespace change_this_to_your_namespace
{
public class Program
{
public static void Main()
{
SerialPort UART = new SerialPort(“COM1”, 115200);
int counter = 0;
UART.Open();
while (true)
{
// create a string
string counter_string = “Count: " + counter.ToString() +
”\r\n";
// convert the string to bytes
byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
// send the bytes on the serial port
UART.Write(buffer, 0, buffer.Length);
// increment the counter;
counter++;
//wait…
Thread.Sleep(100);
}
}
}
}
hello,
and thank you for the help
after the syntax of the program output that are sent are of type Byte.
can I send data de type Real (float)?
I used the following the syntax program:
using System.IO.Ports;
using System.Text;
using System.Threading;
namespace change_this_to_your_namespace
{
public class Program
{
public static void Main()
{
SerialPort UART = new SerialPort(“COM1”, 115200);
int counter = 0;
UART.Open();
while (true)
{
// create a string
string counter_string = “Count: " + counter.ToString() +
”\r\n";
// convert the string to bytes
byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
// send the bytes on the serial port
UART.Write(buffer, 0, buffer.Length);
// increment the counter;
counter++;
//wait…
Thread.Sleep(100);
}
}
}
}
public void ConvertDoubleString(double doubleVal) {
string stringVal;
// A conversion from Double to string cannot overflow.
stringVal = System.Convert.ToString(doubleVal);
System.Console.WriteLine("{0} as a string is: {1}",
doubleVal, stringVal);
try {
doubleVal = System.Convert.ToDouble(stringVal);
System.Console.WriteLine("{0} as a double is: {1}",
stringVal, doubleVal);
}
catch (System.OverflowException) {
System.Console.WriteLine(
"Conversion from string-to-double overflowed.");
}
catch (System.FormatException) {
System.Console.WriteLine(
"The string was not formatted as a double.");
}
catch (System.ArgumentException) {
System.Console.WriteLine(
"The string pointed to null.");
}
}