05-02-2012 03:20 AM
I'm not sure how to handle the serial data I'm receiving from a touchscreen panel.
All I want to do is display the two sets of coordinates, which are made up of two 4 digit numbers.
What I'm struggling with, is the carriage return/line feeds (Cr/Lf).
For example I receive,
TP CrLf TP = touchscreen pressed
0100 CrLf 0100 = first set X of coordinates where these values may be anything from 0000 to 4000 and like wise for all coordinates
0200 CrLf 0200 = first set Y of coordinates
TR CrLf TR = touchscreen released
0100 CrLf 0100 = last set of X coordinates
0200 CrLf 0200 = last set of Y coordinates
If the stylus is dragged on the touchscreen, then I may receive numerous TP CrLf plus the coordinates before I final get the touchscreen release set.
If I didn't have all the CrLf's but just one CrLf' after TP nnnn nnnn it wouldn't be problem.
I've had a go using shift registers, but I'm unsure of the best way forward.
Some guidance would be most appreciated.
Solved! Go to Solution.
05-02-2012 07:46 AM
Please down-convert your code to 8.2. More eyes can see it.
05-02-2012 09:14 AM
I would advise to have several readouts in one iteration of the main loop:
First readout - search the received string for valid command (TP or TR).
If found: run the FOR LOOP to read 2 more times - you will get a string array of your coordinates.
If not found: skip, go to next iteration.
First check this: Each readout should give you one message (TP, TR, or coordinates) and properly terminates on linefeed.
You do not need string concatenations from previous iterations, all shift registers. If not, something is wrong with ViSA settings: wrong termination char, etc.
05-02-2012 09:18 AM
Sorry saved as 8.5
05-02-2012 09:20 AM
Make that 8.0
05-02-2012 09:41 AM
Sorry I don't understand how I can do two more reads in the same iteration.
The problem I have, is that after I receive a TP, the rest of code has to run before I can read again from the serial.
So unless I shift it I lose the TP.
05-02-2012 09:51 AM
Put in multiple VISA reads within the same loop iteration!
05-02-2012 09:56 AM
Something like this?
05-03-2012 02:06 AM
Sorry Raven's Fan I didn't accept our answer as the solution, but Alexander had given me the answer before I just didn't realize you could use more that 1 VISA read. If I could have put you both down as the answer I would, but many thanks for your help.
Most appreciated.
NWM.
05-03-2012 09:21 AM - edited 05-03-2012 09:22 AM
That is no problem at all. He gave you the solution, and did a good example of it. My post was just a comment to clarify his earlier answer since it seemed you didn't catch what he meant. The kudoes are appreciated.