Help extracting information from USB port data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Help extracting information from USB port data
I wonder if it would be possible for Livecode to capture raw data from a USB input device (such as
a keyboard: i.e. intercepting that data before the operating system had played about with it.
a keyboard: i.e. intercepting that data before the operating system had played about with it.
Re: Help extracting information from USB port data
I don't know if this link is what you need: http://livecodeitalia.blogspot.it/2014/ ... porta.html
Best regards
Max
Best regards
Max
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
Thanks MaxV: certainly worth a look
Mind you, I have no Italian, so things will take a bit of decoding.
Mind you, I have no Italian, so things will take a bit of decoding.
Re: Help extracting information from USB port data
I suggest you to use the google translator button, it's in the page.richmond62 wrote:Thanks MaxV: certainly worth a look
Mind you, I have no Italian, so things will take a bit of decoding.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
Google translate as Google translate, but does it TRANSLATE?
Here are some of Google's attempts:
Google translate traducir como Google, pero ¿traducir?
Google translate come Google Translate, ma vuol tradurre?
Google превежда като Google превежда, но не го преведе?
And . . . back again:
from "Spanish" : Google translate translated as Google, but translate?
from "Italian" : Google translate translated as Google, but translate?
from "Bulgarian" : Google translate Google translate as, but not translate it?
QUOD ERAT DEMONSTRANDUM
Here are some of Google's attempts:
Google translate traducir como Google, pero ¿traducir?
Google translate come Google Translate, ma vuol tradurre?
Google превежда като Google превежда, но не го преведе?
And . . . back again:
from "Spanish" : Google translate translated as Google, but translate?
from "Italian" : Google translate translated as Google, but translate?
from "Bulgarian" : Google translate Google translate as, but not translate it?
QUOD ERAT DEMONSTRANDUM
Re: Help extracting information from USB port data
Hi richmond62,
on the right column, just before the stats, there is a Google Translate tool, if you choose "English" this is the output (I use class=notranslate for code, so code is unchanged):
P.S.Did you study Latin? I did, in Italy it is mandatory in high school... hoc tempus porto cicatrices
on the right column, just before the stats, there is a Google Translate tool, if you choose "English" this is the output (I use class=notranslate for code, so code is unchanged):
Let me know if you encounter other problems with translation.Communicate with a port
Perhaps the title may seem dubious, but in this post I will try to expose an overview on how to read the data coming from a USB, serial, or even by an Arduino board.
Before you start it is better to understand what good is all this ?
Imagine having to deal with something that is beyond just reading and writing files, imagine having to know the value of a sensor: the need to know how much has been rotated the wheel of a car, the temperature with a thermometer, the intensity light, etc. In this context we must read an input that we can get to the computer in various ways, the easiest way was analyzed and digested and comes to us as a string of information on the USB port.
By connecting the USB port to the system that reads the data, as such as Arduino, our computer does not see almost nothing, there is a file to be read; there is a communication port that shoots continuously and data that can also accept data
will not go into programming Arduino, which is beyond the scope of this post, there are also other sensors with USB port in addition to Arduino; I will mention to indicate http://bitlash.net/ as one of the easiest to program it.
The command to communicate with a door is open driver device , depending on the operating system the string device is different. On Windows systems all ports are COM, then you can write:
while on Linux ports are tty (or something similar) into the folder / dev , then:Code: Select all
open driver "COM2:" for binary update
Mac is a bit more complicated, because the name and position changes with each version, however, for the rest it is like on Linux:Code: Select all
open driver "/ dev / tty2" for binary update
Code: Select all
# Try one of these: /dev/cu.usbmodem2, /dev.tty.usbmodem2, /dev.cu.usbserial2, open driver "/dev/cu.usbmodem2" for binary update
mode "for binary" (dialogue in binary) is the most used, but you can open it in plain text.
Now comes the tricky part, reading and writing. And 'complicated because you have to understand when they begin and end the data.
If your signal is single channel (then receive information from a single sensor), usually the end character information is a carriage return. In this case, just: (by replacing usbserial with your device )
As you see, you must specify a maximum time in which the program starts to listen, otherwise if there is a transmission error the program stops because it does not get why the end of the data (carriage return).Code: Select all
read from driver usbserial for 1 line in 100 milliseconds put it into theInput
This command can repeat it every 30 milliseconds to update the value read.
If you want to send a command to your sensor / transducer, such as "I am ready to receive data", just use write , here's the code:
If you read from several sensors, the USB port will multichannel information, like: a1 = 22 34 a2 = a3 = 18 ... The roads here are many and depends largely on the update time you need. Take all the rows together and then analyze them is the worst, you risk losing a lot of time to figure out if you have received all the data. Usually the best strategy is to read one line at a time, analyze it and read the next one. The same goes for writing. Another typical mistake is to want to immediately want to communicate at very high speeds, experiment and see if you really need it . Usually the base speed of the door (9600) is more than sufficient for almost all applications. Increase speed increases synchronization problems between reading and writing, the time decreases in provisions and you can not figure out if you have received all the data correctly.Code: Select all
write "run lsd, 500" & return to driver usbserial
P.S.Did you study Latin? I did, in Italy it is mandatory in high school... hoc tempus porto cicatrices
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Help extracting information from USB port data
Hi richmond62,
thank for your suggestion, I moved the translate widget in top right position, so it's easier to see it and use it.
thank for your suggestion, I moved the translate widget in top right position, so it's easier to see it and use it.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
Thanks MaxV: BUT, I didn't have any real problem spotting the Google Translate button . .
The only problem is, that in my experience, Google does NOT translate because a computer cannot do what a human
brain can do, nor will it ever.
I do a lot of work, along with my wife, doing very high-powered translations between Bulgarian and English and know what
does constitute translation and what doesn't. What all machine 'translation' does is most definitely NOT translation, it produces
some sort of pale simulcrum of the original version that often as not loses half of its meaning in the exercise.
The only problem is, that in my experience, Google does NOT translate because a computer cannot do what a human
brain can do, nor will it ever.
I do a lot of work, along with my wife, doing very high-powered translations between Bulgarian and English and know what
does constitute translation and what doesn't. What all machine 'translation' does is most definitely NOT translation, it produces
some sort of pale simulcrum of the original version that often as not loses half of its meaning in the exercise.
Re: Help extracting information from USB port data
This is worthy of a new thread in the 'Consciousness, AI and Machine Learning with Livecode' board.a computer cannot do what a human brain can do, nor will it ever.
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
De Bello Gallico is not great help with Italian articles about Livecode
Mind you, Plautus's plays, while being totally irrelevant to Livecode are hilarious.
Mind you, Plautus's plays, while being totally irrelevant to Livecode are hilarious.
Last edited by richmond62 on Wed Mar 25, 2015 8:02 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
"open driver "COM2:" for binary update"
OK: that supposes that the USB device is always going to be in position 2 in the COM queue.
It seems that one of the largest problems is working out which of the COM connexions is the USB device one wants to communicate with.
OK: that supposes that the USB device is always going to be in position 2 in the COM queue.
It seems that one of the largest problems is working out which of the COM connexions is the USB device one wants to communicate with.
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
I'm doing something wrong, and would be grateful for some help.
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Help extracting information from USB port data
Hi Richmond,
but I think "end" may actually be either CRLF or LF or numToChar(13)
Simon
Code: Select all
read from file "COM3:" until end
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Help extracting information from USB port data
Thanks, Simon: obviously there are some errors in the Documentation . . . LOL
Re: Help extracting information from USB port data
I haven't checked the docs (on a mobile phone here) but EOF might be relevant?