| | |
Problem with Smart Device/Pocket PC connect with Serial Port
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi all,
Currently i'm doing a pocket pc in Visual Studio 2005 in C#, the program is actlly to communicate with a reader using Serial Port.And i run the program using the emulator. For the code,i'm using class Serial Port to establish the connection. After doing all the settings, it seem that the connection is already establish. It's because there is no exception fired after i open the port inside the Load method.
I realize that my problem is when i try to write byte to the serial port, after press button event fired. my emulator suddenly stuck freezing there.below is my code:
privateSerialPort sp;
private void Form1_Load(object sender, EventArgs e)
{
#region Serial Port Init
sp= new SerialPort();
sp = new SerialPort();
sp.PortName = "COM1";
sp.BaudRate = 115200;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
try
{
sp.Open();
MessageBox.Show("Port Open!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
#endregion
}
private void startBtn_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (sp.IsOpen == true)
{
sp.Write(new byte[] { 0xC0, 0x02, 0x01, 0xFF }, 0, 4); //(1)
string STRBFR = sp.ReadExisting();
toHexClass c1 = new toHexClass();
string inHex = c1.display(STRBFR);
string[] strReg = Regex.Split(inHex, "01 18");
for (int i = 1; i < strReg.Length; i++)
{
compAdd.Text = strReg[i].Substring(0, 15);
}
}
else
{
MessageBox.Show("PORT CLOSED!");
}
}
(1)-line that the problem start to happen.
For your information, i already tried the same code in window form, it's successfully running.
Please do advice me on this.. i really need help here....thanks..
Currently i'm doing a pocket pc in Visual Studio 2005 in C#, the program is actlly to communicate with a reader using Serial Port.And i run the program using the emulator. For the code,i'm using class Serial Port to establish the connection. After doing all the settings, it seem that the connection is already establish. It's because there is no exception fired after i open the port inside the Load method.
I realize that my problem is when i try to write byte to the serial port, after press button event fired. my emulator suddenly stuck freezing there.below is my code:
privateSerialPort sp;
private void Form1_Load(object sender, EventArgs e)
{
#region Serial Port Init
sp= new SerialPort();
sp = new SerialPort();
sp.PortName = "COM1";
sp.BaudRate = 115200;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
try
{
sp.Open();
MessageBox.Show("Port Open!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
#endregion
}
private void startBtn_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (sp.IsOpen == true)
{
sp.Write(new byte[] { 0xC0, 0x02, 0x01, 0xFF }, 0, 4); //(1)
string STRBFR = sp.ReadExisting();
toHexClass c1 = new toHexClass();
string inHex = c1.display(STRBFR);
string[] strReg = Regex.Split(inHex, "01 18");
for (int i = 1; i < strReg.Length; i++)
{
compAdd.Text = strReg[i].Substring(0, 15);
}
}
else
{
MessageBox.Show("PORT CLOSED!");
}
}
(1)-line that the problem start to happen.
For your information, i already tried the same code in window form, it's successfully running.
Please do advice me on this.. i really need help here....thanks..
![]() |
Similar Threads
- reading data using serial port (Visual Basic 4 / 5 / 6)
- Send data on a serial port (C++)
- how to mount to serial port??wat is the command? (Shell Scripting)
- Problem with real-time app reading from serial port (ASP.NET)
- serial port shens (USB Devices and other Peripherals)
Other Threads in the C# Forum
- Previous Thread: plz help me
- Next Thread: For Disappear
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client clock combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees developer development draganddrop drawing dynamiccreation encryption enum excel file form format forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math microsystems mouseclick mysql operator password path photoshop picturebox pixelinversion post priviallages. programming property radians regex remoting richtextbox running... serialization server sleep soap socket sql sqlserver stack statistics stream string table temperature text textbox thread time timer update usercontrol validation visualstudio webbrowser windows windowsformsapplication winforms wpf write xml





