I want to read a string from my Arduino via Usb(Serial).I made this script but it has a problem:
Active4 years, 4 months ago
Microsoft windows 7 free download. The problem is that the 'count' isn't right.For example, when i send 'Backspace' this is the output:
But on the arduino serial monitor it works fine.Does anyone know why the the 'count' isn't right and how to fix it?
Arduino Serial Monitor Software
Serial Communication between Java and Arduino made simple. Serial Communication between Arduino and Java has never been simpler. A better alternative to the RXTX library, the JavaArduinoLibrary is an easy to use library with simple methods that allow you, the JAVA programmer, to read and write from the serial port.
RRUZ
125k1313 gold badges315315 silver badges446446 bronze badges
jwz104jwz104
Ethernet
14222 gold badges22 silver badges2020 bronze badges
2 Answers
As Remy said, when receiving data in serial communication you may have many events triggerin for the same string. In fact each byte is an event, but drivers usually buffer the data.
To know the end of your message you should add some char sequence at the end of this message. If you send the string from Arduino using
Serial.println() instead of Serial.print() , then it will add a new line mark after the text. This way you just need to add the characters to the ListBox1.Items.Text property instead of using Add function. You need to allow the chars #10 and #13 to make this work.
Also, if you do it this way, you don't need to send the bell character (#7).
mclopezmclopez
You are assuming a 1-to-1 relationship between the complete data and the event. There is no such guarantee. It may take multiple events to receive the complete data. The event is simply reporting that there is some data available at that moment. In your example, you likely received an event for 3 characters, and then received a second event for the remaining 6 characters. You called
Add() twice, once for each portion of data, rather than once for the complete data.
As such, you have to analyze the data you are receiving, caching it as needed between events, and then call Remy LebeauRemy Lebeau
Add() only when you have complete data to display. For example:
Serial Monitor Arduino Tutorial
362k2222 gold badges288288 silver badges490490 bronze badges
Arduino Serial Monitor InputNot the answer you're looking for? Browse other questions tagged delphiarduinousbdelphi-xe7 or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |