ارتباط با پورت سریال

Apr 7, 2008 at 09:53 o\clock

serial communication a

by: CSharp

i, if you use the input as string then you will send two chars which are "1" followed by a "2".

if you want to send the value 12 then you will have to do the following:

 

private void send_data()

{

byte[] buffer_2_send = new byte[1];

byte data_2_send = 0;

 

data_2_send = Byte.Parse(textBox1.Text);//this way you will get the value 12 in your variable

 

//we will use a buffer because the serial_port.Write takes either a string or a buffer of data

buffer_2_send [0] = data_2_send ;

 

serial_port.Open();

serial_prort.Write(buffer_2_send, 0, buffer_2_send.Length);//write data on the serial port

serial_port.Close();

}

 

 


Log in to comment:

Attention: many blogigo features are only available to registered users. Register now without any obligations and get your free weblog!