
3590ET - 3590EGT_Serial_Commands
57
6. Simple example
The following is a simple example of an application written in C# language that every second sends the READ command to the con-
nected scale and prints in the console the received weight and unit.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Text.RegularExpressions;
namespace TestCom
{
class Program
{
static void Main(string[] args)
{
SerialPort port = new SerialPort(“COM5”); //set the serial port
//configure the serial port
port.BaudRate = 9600;
port.Parity = Parity.None;
port.StopBits = StopBits.One;
port.DataBits = 8;
port.Handshake = Handshake.None;
//open the serial port
try
{
port.Open();
if (!port.IsOpen)
{
Console.WriteLine(port.Po “ port open error!”);
return;
}
}
catch (Exception ex)
{
//serial port open error: print the error message in the console and terminate
Console.WriteLine(ex.Message);
return;
}
string Command = “READ\r\n”; //command to send
string Rx; //reception string
//regular expression related to the READ command answer (ss,wtwt,wwwwwwww,uu)
Regex regexp = new Regex(“^[A-Z]{2}\\,[A-Z]{2}\\,[\\x20]*(?<weight>\\-?[0-9]+(\\.[0-9]+)?)\\,” +
“(?<um>[a-z]{2})\\r\\n$”);
Console.WriteLine(“Press Q to quit”);
//main loop
while (true)
{
Summary of Contents for 3590EGT Series
Page 1: ...www diniargeo com 3590ET 3590EGT ENGLISH Serial commands TECHNICAL MANUAL ...
Page 2: ......
Page 5: ...WUBU 54 X 55 Z 56 ZERO 56 6 Simple example 57 ...
Page 59: ...3590ET 3590EGT_Serial_Commands 59 ...
Page 60: ...3590ET 3590EGT_Serial_Commands 60 NOTES ...
Page 61: ...3590ET 3590EGT_Serial_Commands 61 NOTES ...
Page 62: ...NOTES ...
Page 63: ......