I want to receive input from command line when my device scans barocode and give barcode related information to the conmmand line on telnet window which we start from login in telnet server through cmd.exe by "telnet 192.168.x.x 23" and after typing this command in cmd then login succsessfull telnet window opens and and my machin connected to device , now I have to read barcode string from this window and display output related to that string. please give me any idea how to do this?
here is my code which simply manually enter input string and after pressing enter gives output.
namespace ConsoleApplication2
{
class Program
{
private static System.Timers.Timer aTimer;
string path = @"C:\Users\Priya\Desktop\Project\barcode.txt";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SaiNathHospital"].ToString());
public void getConsoleInput()
{
try
{
FileInfo fi = new FileInfo(path);
for (int i = 0; i <= 0; i++)
{
Console.WriteLine("");
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine(Console.ReadLine());
sw.Close();
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public void getConsoleInputAtRuntime()
{
}
public void ReadWriteIntoFile()
{
try
{
string filename = @"C:\Users\Priya\Desktop\Project\Data.txt";
StringBuilder sb = new StringBuilder();
StreamReader sr = new StreamReader(path);
string s = sr.ReadLine();
sr.Close();
DataExport("Select * from PATIENT_TABLE where [BARCODE] = '" + s + "'", filename);
}
catch { }
}
public void DataExport(string SelectQuery, string filename)
{
try
{
using (var dt = new DataTable())
{
using (var da = new SqlDataAdapter(SelectQuery, con))
{
da.Fill(dt);
var rows =
from dr in dt.Rows.Cast<DataRow>()
select String.Join(
",",
from dc in dt.Columns.Cast<DataColumn>()
let t1 = Convert.IsDBNull(dr[dc]) ? "" : dr[dc].ToString()
let t2 = t1.Contains(",") ? String.Format("\"{0}\"", t1) : t1
select t2);
using (var sw = new StreamWriter(filename))
{
// sw.WriteLine(header);
foreach (var row in rows)
{
sw.WriteLine(row);
}
sw.Close();
}
}
}
}
catch (Exception e) { Console.WriteLine(e.Message); }
}
public void WriteFileOutput()
{
string path = @"C:\Users\Priya\Desktop\Project\Data.txt";
if (File.Exists(path))
{
string[] lines = File.ReadAllLines(path);
foreach (string line in lines)
{
Console.WriteLine(line);
}
}
Console.ReadLine();
}
public void timer()
{
aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 10000;
aTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.\n");
Console.ReadLine();
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
//System.Windows.Forms.SendKeys.Send("{ENTER}");
Console.WriteLine("5 seconds Elapsed at {0} ", e.SignalTime); // for your reference to check every five seconds
}
public static void Main(string[] args)
{
Program p = new Program();
p.getConsoleInput();
p.ReadWriteIntoFile();
p.WriteFileOutput();
}
}
}