| | |
Problem with Smart Device/Pocket PC connect with Serial Port
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
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 app application array bitmap box c# check checkbox client color combo combobox concurrency control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset datatable date/time datetime degrees dll draganddrop drawing enabled encryption enum excel file filename files finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization gtk image input install installer java list localization math microsoftc#visualexpress mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remoting richtextbox save server sleep socket sql sql-server statistics string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser webcam wia winforms wpf xml





