Game Development Community

Serial Port Output

by Omri Perez · in Technical Issues · 08/12/2008 (6:55 am) · 7 replies

Hello everyone I am a PhD student
in neuroscience and I made a nice pseudo-VR experiment with tge 1.5.

I record electrical activity from subject at a sampling rate and I need the game to send out pulses
(called triggers in our jargon) whenever something important happens so that I know when I look
at the recorded data when something happend.

I impleneted this with a 30ms long .wav file that is 2d and preloaded but it turns out that
tge plays it with rather a large temproal jitter of +-100 ms atleast.

I need to find a lower level output method that is more accurate, like turning on a bit from 0 to 1 in the serial port or something like that.
is there a way to do such a thing in tge?

thanks in advance!
Omri

#1
08/12/2008 (1:49 pm)
I believe that the gamecycle depends on the computer speed, as well as the video card that is being used.
Since your time-granularity must be a function of the frame-rate, I don't believe you are going to be able to provide a constant (as in constandt across different computers) clock rate.

I guess your best bet is to send all your data on a jitttery output, and stream it on a mmore controlled way, after you fill the output buffer.
This can be implemented by attaching a PIC microcontroller to the printer port.

I could be wrong, but it makes sense TO ME that your time granularity will be 1/frame-rate.
Since you can not achieve a constant frame rate, this would mess your output.
Buffering the data on the PIC and then streaming it in a more controlled way is what I would do.

I hope this helps.

Rui
#2
08/12/2008 (2:14 pm)
Suppose you could add the windows API to the engine, then access the com port through that running in a seperate thread with a timer function to check for updates before posting the info out of the com port. Since it would be it's own thread it would run separate of torque and use it's own timers etc.

Basically your thread timer would be set for say 100ms, then you would have the code in the thread loop at the 100ms point, and you could feed the thread with cross thread variables in torque. There are a few multi thread tutorials you can look up to get the basic idea.

I wish I could find the demo code I played with for another project it was in C# but basically was what you would need to do.
#3
08/12/2008 (2:25 pm)
Is this .wav a sinussoidal wave?
Sinusoidal waves can easily be generated by a PIC microcontroller, with up to 10 bits DACresolution.
Then you could haee your PIC to wait for a trigger pulse comming through the printer port - D0, for instance.
When it senses the raising edge of tha pulse, it starts outputing a 30mS sinusoidal output.
You could even code the frequency in D1-D7.

Now, if it is not a sinusoidal wave, then this may not work that well.
#4
08/13/2008 (1:40 pm)
Thanks for all the quick answers guys,

- the pulse could be a sine wave, doesn't really matter, though I have to admit I don't know what a pic microcontroller is.

Either way I just need that trigger pulse from the parallel/ serial port.

-My laptop doesn't have a parallel port.

messing around with the build and adding threads is currently beyond my technical skills, is there no command available to just output 'something' to one of the ports?

thanks in advance.
#5
08/13/2008 (2:42 pm)
This post shows how to read from and write to the serial port, in visual C++.
Pretty straightforward - BUT, it is C++ - I don't believe there isanyy script command for serial in/out.
Rui

Edit: Here is th link:

http://www.fogma.co.uk/foggylog/archive/140.html
#6
08/14/2008 (3:18 am)
Thanks, Rui.
How would I go about integrating this into the engine so that I could call it from the script?
#7
08/15/2008 (2:35 pm)
Hello Omri.

I have never compiled the engine.
I have been workking exclusively with TorqueScript.
So, I don't know how to do that.

Right now, I am trying the compile the engine, because I need a night vision and a riffle scope, so EVENTUAL am going to learn how to build the engine.

When I learn that, I will try to help you.

Rui