Hello all. I hope someone may be able to help me with two problems I have that I do not understand.
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// If the com port has been closed, do nothing
if (!comport.IsOpen) return;
// This method will be called when there is data waiting in the port's buffer
// Determain which mode (string or binary) the user is in
// Read all the data waiting in the buffer
string data = comport.ReadExisting();
textBox1.AppendText(data);
textBox1.ScrollToCaret();
//scnbutton.PerformClick();
// Display the text to the user in the terminal
}
I am Dealing with barcodes. When my scanner scans the barcode it returns S08A07934068721. It returns this value every time the UPC is 07934068721 which is the value I wish to append to the textbox.
string data1= data.Substring(4);
textBox1.AppendText(data1);
This is an example of what have tried to use to substring it.
Every time I try to substring the string data it ends up breaking into pieces and I'm not sure how to stop it. After I get this fixed then I will have a problem with the code below
textBox1.Text = textBox1.Text.PadLeft(13, '0');
This works great and always pads 13 digits. But when the UPC or something types has a 0 in the front it drops down to 12 digits why is this?