Click here to Skip to main content
16,006,594 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Serial port communication Pin
Scalpa14-Feb-08 5:22
Scalpa14-Feb-08 5:22 
GeneralRe: C# Serial port communication Pin
Luc Pattyn14-Feb-08 5:34
sitebuilderLuc Pattyn14-Feb-08 5:34 
GeneralRe: C# Serial port communication Pin
Scalpa14-Feb-08 5:45
Scalpa14-Feb-08 5:45 
GeneralRe: C# Serial port communication Pin
Luc Pattyn14-Feb-08 5:52
sitebuilderLuc Pattyn14-Feb-08 5:52 
GeneralRe: C# Serial port communication Pin
DaveyM6914-Feb-08 5:48
professionalDaveyM6914-Feb-08 5:48 
GeneralRe: C# Serial port communication Pin
Luc Pattyn14-Feb-08 6:03
sitebuilderLuc Pattyn14-Feb-08 6:03 
GeneralRe: C# Serial port communication Pin
Scalpa14-Feb-08 6:22
Scalpa14-Feb-08 6:22 
GeneralRe: C# Serial port communication Pin
Scalpa26-Feb-08 6:04
Scalpa26-Feb-08 6:04 
Ok, I was trying to connect a PC(XP pro) to a SARTORIUS lab balance model BP3210S and also model 1413. Via Serial rs232
I finally made it work.

The main problem was the escape sequence sent to the port.
Here is the code.
Create a Windows C# project with 1 textbox and 1 button and drop this code behind form1.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO.Ports;

namespace AnotherSerial
{
public partial class Form1 : Form
{
SerialPort sp = new SerialPort("COM1", 1200, Parity.Odd, 7, StopBits.One);
public Form1()
{
InitializeComponent();
//Subscrib deleguate to even
sp.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}

private void sendButton_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = "";
char cCHR27 = (char)27;
sp.ReadTimeout = 500;
if (sp.IsOpen) sp.Close();
sp.Open();
sp.DtrEnable = true;
sp.Write(cCHR27 + "P"); 'Escape Smile | :)
}
catch (System.Exception ex)
{

textBox1.Text = ex.Message;
}

}

private void ReadButton_Click(object sender, EventArgs e)
{
try
{
//clear the text box

textBox1.Text = "";
//read serial port and displayed the data in text box
if (sp.IsOpen) sp.Close();
sp.Open();
//textBox1.Text = sp.Read() + " Received";
}
catch (System.Exception ex)
{
textBox1.Text = ex.Message;
}
}

private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Event for receiving data
// Read the buffer to text box.
this.Invoke(new EventHandler(DoUpdate));
}

private void DoUpdate(object s, EventArgs e)
{
textBox1.Text = textBox1.Text + sp.ReadExisting();
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

It works
Thanks all.
GeneralUsing Google Maps in a C# application Pin
biscoito14-Feb-08 3:13
biscoito14-Feb-08 3:13 
GeneralRe: Using Google Maps in a C# application Pin
Mircea Puiu14-Feb-08 4:05
Mircea Puiu14-Feb-08 4:05 
GeneralRe: Using Google Maps in a C# application Pin
biscoito14-Feb-08 5:02
biscoito14-Feb-08 5:02 
GeneralRe: Using Google Maps in a C# application Pin
MrPlankton14-Feb-08 7:56
MrPlankton14-Feb-08 7:56 
GeneralRe: Using Google Maps in a C# application Pin
biscoito14-Feb-08 9:59
biscoito14-Feb-08 9:59 
QuestionProblem using DataGridViewComboBoxColumn Pin
Mc_Topaz14-Feb-08 2:29
Mc_Topaz14-Feb-08 2:29 
QuestionWriting to word document? Pin
omegazafer14-Feb-08 1:50
omegazafer14-Feb-08 1:50 
AnswerRe: Writing to word document? Pin
Giorgi Dalakishvili14-Feb-08 1:52
mentorGiorgi Dalakishvili14-Feb-08 1:52 
GeneralDataGridView problem Pin
kallileo14-Feb-08 1:12
kallileo14-Feb-08 1:12 
GeneralRe: DataGridView problem Pin
Harvey Saayman14-Feb-08 1:15
Harvey Saayman14-Feb-08 1:15 
GeneralRe: DataGridView problem Pin
Mircea Puiu14-Feb-08 4:01
Mircea Puiu14-Feb-08 4:01 
GeneralExe not running in different computer.. Pin
Ashish Chauhan14-Feb-08 0:23
Ashish Chauhan14-Feb-08 0:23 
GeneralRe: Exe not running in different computer.. Pin
DaveyM6914-Feb-08 0:28
professionalDaveyM6914-Feb-08 0:28 
GeneralRe: Exe not running in different computer.. Pin
Ashish Chauhan14-Feb-08 0:59
Ashish Chauhan14-Feb-08 0:59 
GeneralRe: Exe not running in different computer.. Pin
DaveyM6914-Feb-08 1:06
professionalDaveyM6914-Feb-08 1:06 
GeneralRe: Exe not running in different computer.. Pin
Ashish Chauhan14-Feb-08 1:14
Ashish Chauhan14-Feb-08 1:14 
GeneralRe: Exe not running in different computer.. Pin
DaveyM6914-Feb-08 1:26
professionalDaveyM6914-Feb-08 1:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.