Hellow
i have connect two computers with serial cabel
in computer A ,i use the below program to send a string to computer B
but i could not
those notes might be helpfull for you
1- i have com1 only in both computers
2- the serial cable ends in femal shapes,another word i have used
the right serial cable not any otherone
when i got your fine solution i will ask for more question regarding the serialport
program so be aware.
//below are both programs that was in computer A and B
What I have tried:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.IO.Ports;
namespace MondaySerial
{
public partial class Form1 : Form
{
static SerialPort sp = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void FormLoad(object sender, EventArgs e)
{
sp.PortName = "com1";
sp.BaudRate = 9600;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
sp.Handshake = Handshake.None;
sp.ReadTimeout = 5000;
sp.Open();
}
protected override void OnClosing(CancelEventArgs e)
{
DialogResult result;
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
result = MessageBox.Show(this, "Are You Sure Want to exit", " Answer Yes or No",
buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if (result == DialogResult.Yes)
{
sp.Close();
Application.Exit();
}
else e.Cancel = true;
}
private void SendStringClick(object sender, EventArgs e)
{
sp.WriteLine(textBox2.Text);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.IO.Ports;
namespace MondaySerial
{
public partial class Form1 : Form
{
static SerialPort sp = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void FormLoad(object sender, EventArgs e)
{
sp.PortName = "com1";
sp.BaudRate = 9600;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
sp.Handshake = Handshake.None;
sp.ReadTimeout = 5000;
sp.Open();
}
protected override void OnClosing(CancelEventArgs e)
{
DialogResult result;
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
result = MessageBox.Show(this, "Are You Sure Want to exit", " Answer Yes or No",
buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if (result == DialogResult.Yes)
{
sp.Close();
Application.Exit();
}
else e.Cancel = true;
}
private void ReadStringClick(object sender, EventArgs e)
{
textBox2.Text = sp.ReadLine();
}
}
}