I'm trying to read data by serial port from GTCO Calcomp Drawingboard VI, a graphic tablet (https://www.gtcocalcomp.com/drawingboard-vi-small-format-tech-specs/).
I tried to use a simple c# console application and it was possible to read some coordinates. Follows the code:
C# CONSOLE CODE
using System;
using System.IO.Ports;
class PortDataReceived
{
public static void Main()
{
SerialPort mySerialPort = new SerialPort("COM3");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
mySerialPort.Open();
Console.WriteLine("Press any key to continue...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.WriteLine("Data Received:");
Console.Write(indata);
}
}
The data is showed like this:
DATA SHOWED AT CONSOLE
Data Received:
#Data Received:
,Data Received:
4Data Received:
7Data Received:
8Data Received:
5Data Received:
8Data Received:
,Data Received:
0Data Received:
0Data Received:
0Data Received:
4Data Received:
5Data Received:
,Data Received:
0Data Received:
1Data Received:
It seems like coordinates from my graphic tablet and it is exactly what I need, but I want to implement a c# Windows Form application. I started to crate a simple layout just to connect my serial port and read data. The application looks like this: GUI Serial Application
The code of that is:
C# WINDOWS FORM APPLICATION
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace SerialDataAplication
{
public partial class Form1 : Form
{
string data = "";
public Form1()
{
InitializeComponent();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (serialPort1.IsOpen == true)
serialPort1.Close();
}
private void comboBox1_DropDown(object sender, EventArgs e)
{
string[] portasativas = SerialPort.GetPortNames();
comboBox1.DataSource = portasativas;
}
private void buttonConnect_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen == false)
{
try
{
serialPort1.PortName = comboBox1.Items[comboBox1.SelectedIndex].ToString();
serialPort1.BaudRate = 9600;
serialPort1.DtrEnable = true;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.Handshake = Handshake.None;
serialPort1.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
serialPort1.Open();
}
catch
{
return;
}
if (serialPort1.IsOpen)
{
button_Connect.Text = "Disconnect";
button_Connect.BackColor = Color.LightGreen;
comboBox1.Enabled = false;
}
}
else
{
try
{
serialPort1.Close();
comboBox1.Enabled = true;
button_Connect.Text = "Connect";
button_Connect.BackColor = Color.Salmon;
}
catch
{
return;
}
}
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
data = sp.ReadExisting();
this.Invoke(new EventHandler(writedata));
}
private void writedata(object sender, EventArgs e)
{
richTextBox1.Text += data.ToString() + "\n";
}
}
}
I tried to read data (just strings) from arduino and both, console and windows form app, worked well.
Unfortunately I am not getting success showing the data from my graphic tablet on "richtextbox".