In my program I must send a string of characters to the com port
( in fact the blue tooth module is being connected to the usb port of pc , and the system will define a com port for it , so I'm supposed to use the code for sending data to the COM PORT... )
In my code (as you see) I've used this command line :
" serialPort.Write(str, 0, str.Length); "
I know this command is for sending a data in "Byte type"( not characters !!) So The problem is that :
I DON'T KNOW what is the appropriate command For sending a "string of CHARACTERS " to the com port ??!!
Here is my code :
private void btncod_Click(object sender, EventArgs e)
{
char[] str = new char[5];
str[0] = 12;
str[1] = 24;
str[2] = 102;
str[3] = 215;
str[4] = 2;
string portName = "COM3";
int buadRate = 9600;
SerialPort serialPort = new SerialPort(portName, buadRate);
serialPort.DtrEnable = true;
serialPort.RtsEnable = true;
serialPort.Handshake = Handshake.None;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.Open();
serialPort.Write(str, 0, str.Length);
serialPort.Close();
}

New Topic/Question
Reply




MultiQuote





|