please understand that I am really in need of help. I want to write over the Moving LED board which can be connected through serial connection.
. This is the image of the board. There is a software provided by the company from which this board is bought.
This is the image of the software GUI. I tried making a C# GUI for serialPort connection. But however, I could not see the output in the board. When making virtual serial ports and communicating through TeraTerm, The program works perfectly. I even have used HEX code converter. But I am unable to write in this board. Plese have a look at my code and help me.
This is the picture of GUI I created. The code is as follows. Please suggest me. Thanks in advance
namespace comPort18Nov
{
public partial class Form1 : Form
{
string dataOut;
string dataIn;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
cBoxCOMPORT.Items.AddRange(ports);
chBoxDtrEnable.Checked = false;
serialPort1.DtrEnable=false;
chBoxRTSEnable.Checked = false;
serialPort1.RtsEnable = false;
btnSendData.Enabled = false;
btnOpen.Enabled = true;
btnClose.Enabled = false;
}
private void btnOpen_Click(object sender, EventArgs e)
{
try
{
serialPort1.PortName = cBoxCOMPORT.Text;
serialPort1.BaudRate = Convert.ToInt32(cBoxBaudRate.Text);
serialPort1.DataBits = Convert.ToInt32(cBoxDataBits.Text);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cBoxStopBits.Text);
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), cBoxParityBits.Text);
serialPort1.Open();
progressBar1.Value = 100;
//Disable the btnOpen once it is open
btnOpen.Enabled = false;
btnClose.Enabled = true; //Enable the btnClose
btnSendData.Enabled = true;
//show label status as open
lblStatusCom.Text = "ON";
}
catch (Exception err)
{
MessageBox.Show(err.Message,"Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
btnOpen.Enabled = true;
btnClose.Enabled = false;
btnSendData.Enabled = false;
lblStatusCom.Text = "OFF"; //label status
}
}
private void btnClose_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
progressBar1.Value = 0;
//Enable btnOpen and disable btnClose
btnOpen.Enabled = true;
btnClose.Enabled = false;
btnSendData.Enabled = false;
//show label status
lblStatusCom.Text = "OFF";
}
}
private void btnSendData_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
dataOut = toHex(tBoxDataOut.Text);
//dataOut = tBoxDataOut.Text;
serialPort1.WriteLine(dataOut);
}
}
//For Hex Conversion
public string toHex(string inp)
{
string outp = string.Empty;
char[] value = inp.ToCharArray();
foreach(char L in value)
{
int V = Convert.ToInt32(L);
outp += string.Format("{0:X2}", V);
}
return outp;
}
private void label7_Click(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
private void chBoxDtrEnable_CheckedChanged(object sender, EventArgs e)
{
if (chBoxDtrEnable.Checked)
{
serialPort1.DtrEnable = true;
}
else { serialPort1.DtrEnable = false; }
}
private void chBoxRTSEnable_CheckedChanged(object sender, EventArgs e)
{
if (chBoxRTSEnable.Checked)
{
serialPort1.RtsEnable = true;
}
else{serialPort1.RtsEnable = false;}
}
private void btnClearDataOut_Click(object sender, EventArgs e)
{
if (tBoxDataOut.Text != "")
{
tBoxDataOut.Text = "";
}
}
private void tBoxDataOut_TextChanged(object sender, EventArgs e)
{
int dataOutLength = tBoxDataOut.TextLength;
lblDataOutLength.Text = string.Format("{0:00}", dataOutLength);
}
private void tBoxDataIn_TextChanged(object sender, EventArgs e)
{
}
}
}