Archived

This topic is now archived and is closed to further replies.

Reading from serial port using OpenGL/C

This topic is 5044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if there is a simple way to read from the serial port using OpenGL. My program modifies a graphic depending on info coming from the serial port. I''ve checked the internet but there are hundreds of different methods. I''ve found one which uses handles but I think you have to compule using a win32 console, which I don''t think will work with OpenGL. Any hints or links would be helpful. Thanks.

Share this post


Link to post
Share on other sites
This is a joke, isn''t it? You don''t really think you can acces a serial port using a graphics API.
But anything that works with the Win32 API should do it.

Share this post


Link to post
Share on other sites
quote:
Original post by SauronTheDark
I don't think J-the-Bear ment to use OpenGL to access the com port I think he means he wants to access the com port from a program that is also using opengl.


quote:
Original post by J-the-Bear
...read from the serial port using OpenGL...


On a helpful note:
1. OpenGL is a graphics API, in simplistic terms an API is a set a commands that a piece of software calls to do some task without having to worry about how that task is actually accomplished. This means (in the case of OpenGL) that you don't have to know what video card you're using or how it stores data (linear, in planes, etc) just that you use the OpenGL commands to do stuff with it. The Win32 API is another API, it gives apps access to OS controlled resources (That's actually a really lame definition of Win32 but I don't really care).

2. Handles are not limited to console applications, they are used throughout all win32 apps (console and window) to identify system objects such as windows, resources (files, ports) and other stuff.

2. The easyist way (correct me if you know another way that does not use low level hardware commands) to use serial communications in Win32 is using handles so check your Win32 API reference for "CreateFile" as a starting point (I don't know the address of any tutorials on this, anyone that does please post)



Edited by - Michalson on February 19, 2002 10:36:57 AM

Share this post


Link to post
Share on other sites
Hmm.. yea.

Check up on the win32 api functions:

CreateFile
ReadFile
WriteFile
CloseHandle

To open a com port specify "COM1" or "COM2" and so on for lpFileName parameter in CreateFile.

Share this post


Link to post
Share on other sites
Thanks for the help I wasn''t sure about the handles working in an application instead of a console. I''ll try using the win32 api. Sauron was right I was hoping to use c or c++ for the port along with my OpenGL. I mentioned this in the title(OpenGL/C).

Share this post


Link to post
Share on other sites
i''m sorry 4 my bad english... and it seems that this is a very late reply... but i hope i can help anyone...

now i''m working on my project that uses opengl to generate 3d graphic, and serial port reader which is used to read data from my gps.

i''m using multithread to accomplish that....
one thread to read serial port, and other to opengl.

from thread that handle serial port, data is loaded into global memory, and the other thread (opengl) reads the global memory...

it wasn''t works so good... one problem i got was i can''t call glutPostRedisplay() from serial port reader thread, so i put glutPostRedisplay() in a function aaa() which is called by glutIdleFunc(aaa).

that''s not a good solution because it used resources that''s unnecesary to do... but until now, i get no answer to solve this problem.

i run this project without any problem on my laptop... my laptop can run for 1.5 hours without power cord plugged (only with the battery).... when i tested this program on the car (run only by the battery''s power), only about 30-40 minutes my battery run from full to empty... then at home, i see that my program used about 99% of proccessor..... it''s a very shocking fact, because at idle, it takes only 10 to 15%.

Share this post


Link to post
Share on other sites