I have the following program that reads the serial port
public static void Main()
{
SerialPort mySerialPort = new SerialPort("COM1");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
mySerialPort.Open();
Console.WriteLine("Press any key to continue...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.WriteLine("Data Received:");
Console.Write(indata);
}
I have below method in a application that calls the webservice that pulls the details from database.
private void Reintialise()
{
InitializeComponent();
try
{
kioskService.KioskTimeSheet kiosk = new kioskService.KioskTimeSheet();
string empCode = "";
buttonIn.IsEnabled = true;
buttonOut.IsEnabled = true;
buttonstart.IsEnabled = true;
buttonSwitch.IsEnabled = true;
buttonend.IsEnabled = true;
DataSet ds = kiosk.LoadEmployeeDetails("CO123");
if (ds != null)
{
DataTable dt = ds.Tables[0];
emp.name = dt.Rows[0]["Name"].ToString();
emp.empID = dt.Rows[0]["EmployeeID"].ToString();
emp.status = dt.Rows[0]["Status"].ToString();
emp.ProjectNo = "18674AB";
textBoxName.DataContext = emp;
if (emp.status == string.Empty)
{
buttonIn.IsEnabled = true;
buttonOut.IsEnabled = false;
}
else
{
buttonIn.IsEnabled = false;
buttonOut.IsEnabled = true;
}
} //if ds
}
catch
{
ErrorBox.Text = "Error in Reintialise";
}
}
Serial port will continously scan for input but only one user at a time. How can I now pass the value read from DataReceivedHandler to the reinitialise method and start the application?

New Topic/Question
Reply



MultiQuote




|