i have a BarcodeScanner here which im telling to make a picture for me. Im sending a command as byte to the scanner, waiting for the response and then im trying to read it.
if i just use a serial monitor and send the bytes manually it works just fine, i get my whole jpeg and im happy.
if i try it in C# i try to read the bytes with a simple method (was the bread and butter method which i found on google. normal i used (serialport.ReadExisting() which crashes the same way).
here is the whole event :
public void serial_datareceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
usescanner = (SerialPort)sender;
if (sender is SerialPort)
{
string port = ((SerialPort)sender).PortName;
int count = ((SerialPort)sender).BytesToRead;
int returnAscii = 0;
string message = "";
while (count > 0)
{
returnAscii = ((SerialPort)sender).ReadByte();
message = message + Convert.ToChar(returnAscii);
count--;
}
ScanPort sport = new ScanPort(port, true);
scanner.ScannerPort = sport;
}
((SerialPort)sender).Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
i Always get 4096 bytes to read back. and then i can read till about 70-90 bytes so yes my messagestring is that long then so it does work ! just simply crashes in the middle of it.
the scanner is not the problem as im working with the scanner for a long time. and i can send data back and forth. also ive tested it on a demoprogram which the manufacturer handed me so it does work.
any ideas? maybe i just dont know how to read bytes.
thanks for the help