x


delay sending to serial port

Hi

I've managed to get a script to send a stream of single digits from a scene to an Arduino board, so that a different LED lights up for each digit. However, there is a significant delay after the first light, and most of the sequence of lights happens after I close the scene. (Working in Play mode, with the signals being sent from a function called in Update).

Can anyone suggest why there should be such a delay please? If I send a fixed string of digits (eg 01234567) from the Start function, it works fine, it's only in the Update function that the delay happens.

The following function is called from Update() with the digit to be sent to Arduino as 'number'. sp is a public Serial Port object that has been opened and seems to work OK; the sp.Write is the command I'm concerned with. (The rest of the function sends information to GUIText just so I can see what's going on).

public void sendToArduino(string number){ sp.Write(number); message = "Direction " + number + ", Time " + Time.time; orientation.SendMessage("ShowMessage", message); }

PS: I've flagged this as code, but it's lost the layout - is that how it should appear? :0)

more ▼

asked Aug 22 '12 at 05:16 PM

Famulus gravatar image

Famulus
1 1 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

OK - I think I've cracked it, by using a timer to send to Arduino at fixed intervals. I knew I'd need to do that for other reasons, but didn't realise that it would help with this problem.

So I've set a timer to count up, and only send to Arduino when it reaches 1 second, then reset the timer to 0. All I need to do now is play around with it, to work out how small an interval is viable for what I need to do.

more ▼

answered Aug 23 '12 at 09:11 AM

Famulus gravatar image

Famulus
1 1 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x27
x24
x15

asked: Aug 22 '12 at 05:16 PM

Seen: 318 times

Last Updated: Aug 23 '12 at 09:11 AM