I'm trying to make a simple application to test the RS422 communications with another computer. Using the RS232 interfaces this program is working smoothly, but with the RS422 is not working, as there is one computer that can't send. To complex the scenario a little bit more, I can communicate through RS422 using a HyperTerminal.
Here is the code:
public partial class MainForm : Form
{
private SerialPort m_port;
public MainForm()
{
InitializeComponent();
m_list.Items.AddRange(SerialPort.GetPortNames());
m_port = new SerialPort();
m_port.BaudRate = 9600;
m_port.DataBits = 8;
m_port.Parity = Parity.None;
m_port.StopBits = StopBits.One;
m_port.Handshake = Handshake.None;
m_port.Encoding = new ASCIIEncoding();
m_port.ReceivedBytesThreshold = 1;
m_port.DataReceived += DataReceivedEvent;
}
~MainForm()
{
if (m_port != null)
m_port.Close();
}
private void openClick(object sender, EventArgs e)
{
m_port.Close();
m_port.PortName = (string)m_list.SelectedItem;
try
{
m_port.Open();
m_buttonSend.Enabled = true;
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message);
}
}
private void ButtonSendClick(object sender, EventArgs e)
{
m_port.WriteLine(m_testBox.Text);
}
private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs args)
{
Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
m_receivedText.Text += m_port.ReadLine();
}
}
Any help or experience with this technology is appreciated. Thanks!
EDIT
There is a lot of differences between the trace with Portmon of Hyperterminal and the .NET component. There is one of the lines that got my attention as it reefers to the wait mask of the port interruption IOCTL_SERIAL_SET_WAIT_MASK.
With HyperTerminal:
IOCTL_SERIAL_SET_WAIT_MASK Serial0 SUCCESS Mask: RLSD ERR
With the .NET SerialPort component
IOCTL_SERIAL_SET_WAIT_MASK Serial0 SUCCESS Mask: RXCHAR RXFLAG CTS DSR RLSD BRK ERR RING
Anybody knows how to change the mask from the component? This is getting deep...
Finally there was a problem in the initialitation and another one with the blocking ReadLine call. RTS and DTS must be enabled.
Here is the code
using System;
using System.IO.Ports;
using System.Text;
using System.Windows.Forms;
namespace ComPlay
{
public partial class MainForm : Form
{
private SerialPort m_port;
private byte [] m_buffer = new byte[10];
public MainForm()
{
InitializeComponent();
m_list.Items.AddRange(SerialPort.GetPortNames());
m_list.SelectedIndex = 0;
m_port = new SerialPort(SerialPort.GetPortNames()[0],9600,Parity.None,8,StopBits.One);
m_port.Handshake = Handshake.None;
m_port.RtsEnable = true;
m_port.DtrEnable = true;
m_port.DataReceived += DataReceivedEvent;
m_port.PinChanged += PinChangedEvent;
}
~MainForm()
{
if (m_port != null)
m_port.Close();
}
private void openClick(object sender, EventArgs e)
{
if (m_port.IsOpen)
m_port.Close();
m_port.PortName = (string)m_list.SelectedItem;
try
{
m_port.Open();
m_buttonSend.Enabled = true;
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message);
}
}
private void ButtonSendClick(object sender, EventArgs e)
{
byte [] r_bytes = Encoding.ASCII.GetBytes(m_testBox.Text);
m_port.Write(r_bytes,0,r_bytes.Length);
}
private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs args)
{
Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
m_port.Read(m_buffer, 0, m_buffer.Length);
m_receivedText.Text += Encoding.ASCII.GetString(m_buffer);
}
private void PinChangedEvent(object sender, SerialPinChangedEventArgs args)
{
}
}
}
The important thing to begin transmitting was to change this
IOCTL_SERIAL_SET_HANDFLOW Serial1 SUCCESS Shake:80000000 Replace:80000040 XonLimit:1024 XoffLimit:1024
to this
IOCTL_SERIAL_SET_HANDFLOW Serial1 SUCCESS Shake:80000001 Replace:80000040 XonLimit:1024 XoffLimit:1024
activating RTS and DTR.
Related
This question already has answers here:
Communicate between two windows forms in C#
(12 answers)
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
I am a newbie in C# and I have questions as below:
I have a Form1 name is setting Port Name, Baud Rate, Parity... of modbus protocol and I can open serial Port.
Also, I have another Form is called Form2, When Port is opened i want to close Form1 and Port alway Open => I can do it. But this problem that was I want to get data such as FC03 HolodingRegister, FC01 WriteSingleCoil... for Form2 but didnot.
I used delegate to transfer data from Form 1 to Form 2 but I could not use button Form2 to send FC01 signal.
How to use FC01, FC03,04... for Form2 when Form 1 connected.
Code Form1:
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;
using Modbus.Device;
namespace ATS
{
public partial class frCommunication : Form
{
SerialPort serialPort = new SerialPort();
ModbusMaster Master;
public delegate void truyendulieu(string text);
public truyendulieu truyendata;
public delegate void truyendulieu1(string text1);
public truyendulieu1 truyendata1;
public delegate void truyendulieu2(string text2);
public truyendulieu2 truyendata2;
public frCommunication()
{
InitializeComponent();
}
private void frCommunication_Load(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
cboxPort.Items.AddRange(ports);
cboxPort.SelectedIndex = 0;
}
private void btnConnect_Click(object sender, EventArgs e)
{
btnConnect.Enabled = false;
btnDisconnect.Enabled = true;
try
{
serialPort.PortName = cboxPort.Text;
serialPort.BaudRate = Convert.ToInt32(cboxBaudRate.Text);
serialPort.DataBits = Convert.ToInt32(cboxDataBits.Text);
serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cboxStopBits.Text);
serialPort.Parity = (Parity)Enum.Parse(typeof(Parity), cboxParity.Text);
serialPort.Open();
Master = ModbusSerialMaster.CreateRtu(serialPort);
Master.Transport.Retries = 0; // don't have to to retries
Master.Transport.ReadTimeout = 300;//miliseconds
}
catch (Exception err)
{
MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (serialPort.IsOpen)
{
lblDisplay.Text = "Connected";
lblDisplay.ForeColor = System.Drawing.Color.Red;
cboxBaudRate.Enabled = false;
}
else
{
lblDisplay.Text = "Disconnected";
MessageBox.Show("Error!");
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
btnConnect.Enabled = true;
btnDisconnect.Enabled = false;
try
{
serialPort.Close();
lblDisplay.Text = "Disconnected";
lblDisplay.ForeColor = System.Drawing.Color.Green;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (serialPort.IsOpen)
{
ushort[] holding_register = Master.ReadHoldingRegisters(1, 0, 10);
txtV_Grid.Text = Convert.ToString(holding_register[0]);
txtC_Grid.Text = Convert.ToString(holding_register[1]);
txtP_Grid.Text = Convert.ToString(holding_register[2]);
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (txtV_Grid.Text.Length > 0 || txtC_Grid.Text.Length > 0 || txtP_Grid.Text.Length > 0)
{
if (truyendata != null || truyendata1 != null)
{
truyendata(txtV_Grid.Text);
truyendata1(txtC_Grid.Text);
truyendata2(txtP_Grid.Text);
}
this.Hide();
}
}
private void txtV_Grid_TextChanged(object sender, EventArgs e)
{
if (truyendata != null)
{
truyendata(txtV_Grid.Text);
}
}
private void txtC_Grid_TextChanged(object sender, EventArgs e)
{
if (truyendata1 != null)
{
truyendata1(txtC_Grid.Text);
}
}
private void txtP_Grid_TextChanged(object sender, EventArgs e)
{
if (truyendata2 != null)
{
truyendata2(txtP_Grid.Text);
}
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void btnOn_ACB_Grid_Click(object sender, EventArgs e)
{
if (serialPort.IsOpen)
{
DialogResult dl = MessageBox.Show("Would you like to turn On ACB_GRID", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dl == DialogResult.Yes)
{
Master.WriteSingleCoil(1, 0, true);
}
else
{
Master.WriteSingleCoil(1, 0, false);
}
}
}
private void btnOff_ACB_Grid_Click(object sender, EventArgs e)
{
if (serialPort.IsOpen)
{
DialogResult dl = MessageBox.Show("Would you like to turn Off ACB_GRID", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dl == DialogResult.Yes)
{
Master.WriteSingleCoil(1, 0, false);
}
else
{
Master.WriteSingleCoil(1, 0, true);
}
}
}
}
}
Code Form2:
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 SymbolFactoryDotNet;
namespace ATS
{
public partial class frMain : Form
{
public frMain()
{
InitializeComponent();
}
private void communicationToolStripMenuItem_Click(object sender, EventArgs e)
{
frCommunication frm = new frCommunication();
frm.ShowDialog();
}
private void standardControl1_Load(object sender, EventArgs e)
{
}
private void LoadData(string data)
{
txtV.Text = "";
txtV.Text = data;
}
private void LoadData1(string data1)
{
txtC.Text = "";
txtC.Text = data1;
}
private void LoadData2(string data2)
{
txtP.Text = "";
txtP.Text = data2;
}
private void btnConnect_Click(object sender, EventArgs e)
{
frCommunication frm = new frCommunication();
frm.truyendata = new frCommunication.truyendulieu(LoadData);
frm.truyendata1 = new frCommunication.truyendulieu1(LoadData1);
frm.truyendata2 = new frCommunication.truyendulieu2(LoadData2);
frm.ShowDialog();
}
private void txtV_TextChanged(object sender, EventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
if(picOn.Visible == false)
{
picOn.Visible = true;
picOff_Grid.Visible = false;
// standardControl3.DiscreteValue2 = true;
}
else
{
picOn.Visible = false;
picOff_Grid.Visible = true;
}
}
private void frMain_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString("HH:mm:ss dd-MM-yyyy");
}
private void btnOn_Grid_Click(object sender, EventArgs e)
{
}
}
}
When I understand you right, you will in Form1 open a connection, close the Form, open a new Form2 and use this connection there?
Well, when that's the case, you could make an special Connection Singleton to hold this connection then you can use it in your Form2
using System;
namespace Sandbox
{
public sealed class Connection
{
private static readonly Lazy<Connection> _instance = new Lazy<Connection>(() => new Connection());
public static Connection Instance => _instance.Value;
private Connection()
{ }
// Implement your Connection Code here.
}
}
I am trying to set up a serial com interface that will send and receive data in the Windows Forms App with C#. I can confirm that I am sending and receiving data from the ports with the help of a virtual serial port driver app since it also shows the number of bytes sent and received. However, the text box doesn't display the received messages. There no reported errors.
-------The Code---------------
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 FormAppAuto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
buttonDisconnect.Enabled = false;
buttonSend.Enabled = false;
foreach (var serialPort in SerialPort.GetPortNames())
{
comboBoxSerialPorts.Items.Add(serialPort);
}
comboBoxSerialPorts.SelectedIndex = 0;
}
private void buttonConnect_Click(object sender, EventArgs e)
{
serialPort1.PortName = comboBoxSerialPorts.Text;
serialPort1.BaudRate = 115200;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.DataBits = 8;
try
{
serialPort1.Open();
}
catch (Exception ex)
{
MessageBox.Show($"Seri port bağlantısı yapılamadı\n Hata : {ex.Message}", "Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (serialPort1.IsOpen)
{
buttonConnect.Enabled = false;
buttonDisconnect.Enabled = true;
buttonSend.Enabled = true;
}
}
private void buttonDisconnect_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
buttonConnect.Enabled = true;
buttonDisconnect.Enabled = false;
buttonSend.Enabled = false;
}
}
private void buttonSend_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Write(textBoxMyMessage.Text);
textBoxMyMessage.Clear();
}
}
public delegate void dataShow(String s);
public void writeText(String s)
{
textBoxMessages.Text += s;
}
//private void serialPort1_DataReceived(object sender, SerialDataReceivedEventHandler e)
//{
// String dataIn = serialPort1.ReadExisting();
//textBoxMessages.Text += gelenVeri;
// textBoxMessages.Invoke(new dataShow(writeText), dataIn);
// }
private void DatareceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
String indata = sp.ReadExisting();
Console.WriteLine("Data Received");
Console.Write(indata);
textBoxMessages.Text += indata;
}
}
}
I am trying to write a simple Forms app to send data over a USB port to a listening terminal device. I have been told that I need to send the data using STX ETX LRC framing but I have no idea what that means. I am a software tester for our company and not familiar with data transmissions via usb. Is there anyone who can help me with this? This is my current forms code:
private void sendRequestButton_Click(object sender, EventArgs e)
{
try
{
_serialPort = new SerialPort
{
PortName = portsDropdown.Text,
BaudRate = 19200,//connectionTypeDropdown.Text.Equals(Usb) ? 115200 : 19200,
DataBits = 8,
Parity = Parity.None,
StopBits = StopBits.One,
};
_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
_serialPort.Open();
_serialPort.Write(requestTextbox.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, #"Caught Exception:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
_serialPort.Close();
}
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
var serialPort = (SerialPort)sender;
_response = serialPort.ReadExisting();
Debug.Print(_response);
}
Here's what I used for connecting through the serial port in C#. This is in WPF so you'll have to make some adjustments.
using System;
using System.IO.Ports;
using System.Windows;
using System.Windows.Input;
namespace SerialTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private SerialPort port = new SerialPort();
int intBaud = 0;
string strComport = "";
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string[] ports = SerialPort.GetPortNames();
cbCom.ItemsSource = ports;
}
private void StartUp()
{
int intbaud;
if (int.TryParse(cbBaud.SelectionBoxItem.ToString(), out intbaud))
{
intBaud = intbaud;
strComport = cbCom.SelectedItem.ToString();
SerialStart();
}
else
{
MessageBox.Show("Enter a valid Baudrate");
}
}
private void SerialStart()
{
try
{
port.BaudRate = int.Parse(cbBaud.SelectionBoxItem.ToString());
port.DataBits = 8;
port.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One");
port.Parity = (Parity)Enum.Parse(typeof(Parity), "None");
port.PortName = cbCom.SelectedItem.ToString();
port.DataReceived += new SerialDataReceivedEventHandler(SerialReceive);
port.Handshake = Handshake.None;
if (port.IsOpen) port.Close();
port.Open();
}
catch (Exception ex)
{
txtTerm.AppendText(ex.ToString());
}
}
public enum LogMsgType { Incoming, Outgoing, Normal, Warning, Error };
private void Log(LogMsgType msgtype, string msg)
{
try
{
txtTerm.Dispatcher.Invoke(new EventHandler(delegate
{
txtTerm.AppendText(msg);
}));
}
catch (Exception ex)
{
ex.ToString();
}
}
private void SerialReceive(object sender, SerialDataReceivedEventArgs e)
{
if (!port.IsOpen) return;
string data = port.ReadExisting();
this.Dispatcher.Invoke(() =>
{
txtTerm.AppendText(data);
txtTerm.ScrollToEnd();
});
}
private void txtInput_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return && port.IsOpen)
{
try
{
port.WriteLine(txtInput.Text + "\r\n");
}
catch (Exception ex)
{
this.Dispatcher.Invoke(() =>
{
txtTerm.AppendText(ex.ToString()); ;
});
}
this.Dispatcher.Invoke(() =>
{
txtTerm.AppendText(txtInput.Text + "\n");
txtInput.Text = "";
});
}
}
}
}
Edit
Looks like for STX and ETC you have to also convert the characters to bytes
https://www.codeproject.com/questions/1107562/sending-ascii-control-stx-and-etx-in-csharp
I have code that takes data from serial com port from a weighing machine. It works okay, but receives data in several lines. I'm trying to make it receive data in one line.
In the code below I need to take weight from weigh bridge machine automatically by timer using Visual Studio 2005. It works, but I receive weight values on several lines.
I need to receive weight in one line and automatically update and convert it to an integer.
using System;
using System.IO.Ports;
using System.Windows.Forms;
namespace CommSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void Application_Idle(object sender, EventArgs e)
{
label3.Text = serialPort1.IsOpen ? "[Open]" : "[Closed]";
}
private void button1_Click(object sender, EventArgs e)
{
if (pollingCheckbox.Checked)
{
timer1.Enabled = true;
}
else
{
timer1.Enabled = false;
TransmitCommand();
}
}
private void TransmitCommand()
{
if (textBox1.Text.Length > 0)
{
if (serialPort1.IsOpen)
{
serialPort1.Write(textBox1.Text + "\r");
}
}
}
private void ClosePort()
{
if (serialPort1.IsOpen)
{
serialPort1.DataReceived -= new SerialDataReceivedEventHandler(serialPort1_DataReceived);
serialPort1.Close();
}
}
private void closePortToolStripMenuItem_Click(object sender, EventArgs e)
{
ClosePort();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.PortName = Properties.Settings.Default.Port;
serialPort1.BaudRate = Properties.Settings.Default.Baud;
serialPort1.DataBits = Properties.Settings.Default.DataBits;
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), Properties.Settings.Default.Parity);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), Properties.Settings.Default.StopBits);
Application.Idle += new EventHandler(Application_Idle);
}
private void OpenPort()
{
serialPort1.Open();
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void openPortToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenPort();
}
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
{
ClosePort();
using (Form2 form = new Form2())
{
if (form.ShowDialog(this) == DialogResult.OK)
{
serialPort1.PortName = Properties.Settings.Default.Port;
serialPort1.BaudRate = Properties.Settings.Default.Baud;
serialPort1.DataBits = Properties.Settings.Default.DataBits;
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), Properties.Settings.Default.Parity);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), Properties.Settings.Default.StopBits);
}
}
}
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (!InvokeRequired)
{
if (e.EventType == SerialData.Chars)
{
string portData = serialPort1.ReadExisting();
textBox2.AppendText(portData);
}
}
else
{
SerialDataReceivedEventHandler invoker = new SerialDataReceivedEventHandler(serialPort1_DataReceived);
BeginInvoke(invoker, new object[] { sender, e });
}
}
private void pollingCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (timer1.Enabled && !pollingCheckbox.Checked)
{
timer1.Enabled = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pollingCheckbox.Checked)
{
TransmitCommand();
}
}
}
}
Trying to develop small application using GsmComm Library.
At the moment a have some problems with detecting if phone is connected or no.
it's detects when phone is disconnected, but doesn't want to detect phone when is connected back again ...
Any idea why ?
my code:
GsmCommMain gsm = new GsmCommMain(4, 115200, 200);
private void Form1_Load(object sender, EventArgs e)
{
gsm.PhoneConnected += new EventHandler(gsmPhoneConnected);
gsm.PhoneDisconnected += new EventHandler(gsmPhoneDisconnected);
gsm.Open();
}
private delegate void ConnctedHandler(bool connected);
private void onPhoneConnectedChange(bool connected)
{
try
{
if (connected)
{
phoneStatus.Text = "OK";
}
else
{
phoneStatus.Text = "NG";
}
}
catch (Exception exce)
{
logBox.Text += "\n\r" + exce.ToString();
}
}
public void gsmPhoneConnected(object sender, EventArgs e)
{
this.Invoke(new ConnctedHandler(onPhoneConnectedChange), new object[] { true });
}
private void gsmPhoneDisconnected(object sender, EventArgs e)
{
this.Invoke(new ConnctedHandler(onPhoneConnectedChange), new object[] { false });
}
Sorry for late answer. Just noticed your question.
There is no need to use EventHandler for connection. If you want to call some functions after phone/gsm modem is connected you should call them after you opened port and (!) checked whether connection is established using IsConnected() member function in GsmCommMain class.
var gsm = new GsmCommMain(4, 115200, 200);
private void Form1_Load(object sender, EventArgs e)
{
//gsm.PhoneConnected += new EventHandler(gsmPhoneConnected); // not needed..
gsm.PhoneDisconnected += new EventHandler(gsmPhoneDisconnected);
gsm.Open();
if(gsm.IsConnected()){
this.onPhoneConnectedChange(true);
}
}
private delegate void ConnctedHandler(bool connected);
private void onPhoneConnectedChange(bool connected)
{
try
{
if (connected)
{
phoneStatus.Text = "OK";
}
else
{
phoneStatus.Text = "NG";
}
}
catch (Exception exce)
{
logBox.Text += "\n\r" + exce.ToString();
}
}
/*public void gsmPhoneConnected(object sender, EventArgs e)
{
this.Invoke(new ConnctedHandler(onPhoneConnectedChange), new object[] { true });
}*/
private void gsmPhoneDisconnected(object sender, EventArgs e)
{
this.Invoke(new ConnctedHandler(onPhoneConnectedChange), new object[] { false });
}