Question Read and display data over USB

Ken12133

Member
Joined
Aug 1, 2021
Messages
6
Programming Experience
Beginner
I have a Banner L Gauge sensor that measures distance. Currently I have it hooked up to a USB to RS 422 converter and I can read the data over a terminal emulator. The emulator is set for hex. How can I display the information in a text box? Let me supply you with a little more information. I'm retired and a newbie to programming. I wrote a small program to communicate with an Arduino mega to turn an output on and off for future use. It also controls a servo motor using one com port. I added another com Port to try and read the L Gauge sensor. This port is configured with the sensors parameters. Using textbox1.text = serialport2.readbyte among other serialport2. commands. Still nothing is displayed in the text box. Any help would be appreciated.
Ken
 
Last edited:
Does your code even compile? If does, the chances are that you are updating the text property but not giving any CPU cycles to the UI thread for it to have a chance to paint the UI updates. And, no, the correct solution is not the WinForms equivalent of DoEvents() despite how many VB6 programmers turned VB.NET and C# programmers swarring by it.
 
Does your code even compile? If does, the chances are that you are updating the text property but not giving any CPU cycles to the UI thread for it to have a chance to paint the UI updates. And, no, the correct solution is not the WinForms equivalent of DoEvents() despite how many VB6 programmers turned VB.NET and C# programmers swarring by it.
Are you responding to k12133?
 
Considering that there is has been only one post, who else who I be responding to? Also there is no need to quote the post above yours. You are just taking up uncessary bandwidth, special for cellphone users.
 
As I indicated in my first post I'm new to program it. It does compile. I don't know what you mean by UI and DoEvents().
 
If you are new to programming, and are also new to programming in WinForms, Petzold's Programming Windows book is an excellent resource to learn from because it explains a lot of the underlying architecture/infrastructure that .NET and WinForms is built on.

The short version is that Windows GUI is an event driven system. The way events are sent through the system are via Windows messages which are put in a message queue Messages include setting text, colors, mouse positions, and when to redraw all or parts of the screen. An application gets those messages by constantly polling to see if any messages are in the queue and processing them. If your code is in a tight loop, then your app doesn't get a chance to poll for those messages.

VB6 programmers knew this. But since there was no easy way to remember their current place in their code execution to go back up to the high level polling and then come back to their code, they instead call the polling function (DoEvents) to process messages from the queue. This can (and did) lead to hard to reproduce bugs because most programmers don't expect Windows to be calling their code while their code is currently doing something else.
 
Thank you for that explanation. I don't know if this would have any bearing on my problem but the data sent out by the sensor is continuous.
 
You should only update the UI only when the serial port gives you the data available event. Read the available data, update the UI and yield control about to the event loop.
 
Back
Top Bottom