SFML community forums

Help => General => Topic started by: Ivo on September 19, 2013, 02:07:08 am

Title: How to use a serial com port with SFML
Post by: Ivo on September 19, 2013, 02:07:08 am
Hello,

I'm new to SFML, working through the tutorials, all good so far, but what I need and cannot find is how to use a serial port with SFML.

OS is Windows 7, IDE is Visual Studio 2012 Express, SFML version 2.1.

Background: I have to develop a basic computer game which uses the input of two microcontrollers connected with serial ports.

Question: I would like to have events similar to the mouse or keybord events whenever data are received on the serial port (and of course send something sometimes). Is there anything like that in SFML available?

Thank you, Ivo


Title: Re: How to use a serial com port with SFML
Post by: eXpl0it3r on September 19, 2013, 02:14:52 am
SFML doesn't have any kind of API for working with serial ports. It's a multimedia library not a generic library that can handle anything.
What do you want to do with the serial port? :)
Title: Re: How to use a serial com port with SFML
Post by: Ivo on September 19, 2013, 02:34:49 am
The game I have to develop has a microcontroller as input device. It sends out measurement data, every 10ms 30 ASCII bytes using Bluetooth.
I have to read these data, move simple geometric objects on the screen and in addition dump the data in a logfile. I have set up a virtual com port using a Bluetooth manager provided with my laptop. My first approach was a Visual Basic solution. It does the job but it's not fast enough, it can only process 10 events per second, not 100 as requested.
In VB I have a com port and whenever the application gets a 'receive' event I just read the data and process them.

Title: Re: How to use a serial com port with SFML
Post by: eXpl0it3r on September 19, 2013, 02:45:38 am
You'll have to go and use the WinAPI directly. Google yields a lot of useful information on Serial ports and C++ (e.g. here (http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c5425/Serial-Communication-in-Windows.htm), here (http://msdn.microsoft.com/en-us/library/ff802693.aspx), here (http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2503/CSerial--A-C-Class-for-Serial-Communications.htm) or here (http://suite101.com/a/reading-a-serial-port-using-windows-a124369)). With C++ you can of course also consider using Bluetooth directly (e.g. see here (http://msdn.microsoft.com/en-us/library/windows/desktop/aa362932(v=vs.85).aspx)).
Title: Re: How to use a serial com port with SFML
Post by: fallahn on September 19, 2013, 08:17:06 am
A while back I wrote a class specifically for talking to microcontrollers over RS232 which wraps both windows and Linux APIs in a single cross platform interface, here (http://trederia.blogspot.co.uk/2013/02/c-wrapper-class-for-rs232-com.html) which might help
Title: Re: How to use a serial com port with SFML
Post by: Ivo on September 20, 2013, 01:17:35 am
Thanks for the reply and the help, guys.
Now I'm working my way through the information you provided.