1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
public bool ison = false;
public string str;
private void button_charger_Click(object sender, EventArgs e)
{
textBox1.Text= string.Empty;
openFilDialog1.Title="chargement";
openFilDialog1.FilterIndex =1;
if(openFilDialog1.ShowDialog(this)==DialogResult.OK)
{
StreamReader sr =new StreamReader(openFilDialog1.OpenFile(), Encoding.Default);
char [] tab =new char [100];
str = string.Empty;
str = sr.ReadToEnd();
textBox1.AppendText(str+"\r\n");
}
private void button_envoyerClick(object sender, EventArgs e)
{char [] A = {(char)10};// char (10)
serialPort1.Write(A,0,1);
while(!ison) {} // attente de la rection de la réponse de la commande d'axe
if (str.Length>0)
{
string don;
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] bytes = asii.GetBytes(str);
char[] encodedChars = ascii.GetChars(bytes);
int len = encodedChars.Lenght;
len = (len % 100 == 0) ? len : len + 100 - len % 100;
char[] buff = new char[len];
encodedChars.CopyTo(buff, 0);
for (i = 0; i < len; i += 100)
{
serialPort1.Write(don, i, i + 100);
}
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// pour la boucle while dans le bouton envoyer
if (!ison)
{
ison = true;
}
}
} |