hi,
yesterday my project worked fine.but now it's not working.actually am woking on two c# winform applications just for testing whether they are sending or receiving.
1st application need to send excel data row by row once this data received by second application that will sen back some info($machineID#).
here is the code o 1st application:
private void Upload_Click(object sender, EventArgs e)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(textBox1.Text, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
progressBar1.Visible = true;
int k = 100 / rowCount;
for (int i = 2; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
if (j == 1)
machId = xlRange.Cells[i, j].Value.ToString();
if (j == 2)
custId = xlRange.Cells[i, j].Value.ToString();
if (j == 3)
name = xlRange.Cells[i, j].Value.ToString();
if (j == 4)
totalBal= xlRange.Cells[i, j].Value.ToString();
if (j == 5)
paid = xlRange.Cells[i, j].Value.ToString();
if (j == 6)
lastPaid= xlRange.Cells[i, j].Value.ToString();
if (j == 7)
due = xlRange.Cells[i, j].Value.ToString();
final = "$ POST," + machId + "," + custId + "," + name + "," + totalBal + "," + paid + "," + lastPaid + "," + due + " # ";
}
if (serialPort1.IsOpen)
{
if(machId.Length<=5 && custId.Length<=10 && name.Length<=15 && totalBal.Length<=7 && paid.Length<=7 && lastPaid.Length<=14 && due.Length<=7 )
serialPort1.Write(final);
} serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
and second application is:
<pre lang="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace handheld_Responce
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
serialPort1.Open();
serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void send_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (serialPort1.IsOpen)
{
String RecievedData;
RecievedData = serialPort1.ReadExisting();
if (!(RecievedData == ""))
{
textBox2.Invoke((MethodInvoker)delegate { textBox2.Text += RecievedData; });
}
Thread.Sleep(100);
serialPort1.WriteLine("$M121,0#");
}
}
}
}