- Home /
how can i see serial port speed
I'm trying to get input from a stationary bike into Unity. I'm reading from the serial port (at 9600 baud) and it's slowing things down to about 1fps. I've seen the other posts with similar problems but I was already doing the polling from Update (rather than OnGUI) and I've tried slowing down the sampling rate (to no avail).
Presently, I've put the polling in another thread and only using the data when it is updated but that results in a lag. What I would like to do is to see exactly how much time the serial port is taking but I'm not sure how to get the system time in milliseconds in Unity.
Is there a way to do that? Also, any suggestions about serial port reading would be appreciated (I can post up the code if that would be useful). Thanks!
How do you read the seial port? Any code samples? Do you use blocking functions? The thread-solution is propably the best, how do you synchronise the thread with Unity's main thread?
There's a command SerialPort in System.IO.Ports. It's just:
mySerial = new SerialPort(port, 9600);
to open up a port. It may block (which is why it's slow, probably, and it's what I'm trying to figure out). I'm using a separate thread so the blocking doesn't hold things in the main thread but I'd still like the input to be at a higher rate. I just use a semaphore to sync - no real race condition to worry about.
Answer by aldonaletto · May 20, 2012 at 12:32 PM
I don't know if this is what you're looking for, but you can read Time.realtimeSinceStartup - this value is based on the system timer, don't take Time.timeScale into account and is updated even during the update cycle (different from Time.time, which shows the same value during the whole update cycle).
I'm interested in sub-second resolution (1/100 second) since I'm dealing with things on a frame rate level. Time.time and Time.realtimeSinceStartup both only deal in seconds, which is too slow for me.
Uhmm all time values are in seconds, right, but they are float values. You have a fractional part. When you multiplying the value with 1000 you have milliseconds.
Your answer
Follow this Question
Related Questions
Time.timeScale and Time.fixedDeltaTime 1 Answer
SmoothDamp smoothTime ignored! 1 Answer
On time slow down only player enable to move 2 Answers
Time.timeScale question 1 Answer
how to get smooth slow motion? 4 Answers