I've been looking for hours for a way to write to a serial port. Every way that I have found I haven't been able to implement. The program I'm currently using for Recvfrom() functions requires me to disable precomplied headers (I'm not sure if thats an issue). So what I'm basically asking is, is there a way to transmit a variable through a serial port, and if so what is the easiest way to go about it.
Precompiled headers isn't really an issue - if you are including other code directly in your project rather than building a library you might have to add the #include stdaxf.h
to that code, or you can simply include the .h and .cpp files directly into your code file.
If you want to talk to the serial port directly in win32 it's easy enough. The big issue is handling the threading and waiting for new data to arrive - but if you just want to send and sit there waiting for a response it's easy
You could use qextserialport a library for serial communication with QT.
Here is the link to the function recvfrom() in the msdn documentation. Also contains a sample. http://msdn.microsoft.com/en-us/library/windows/desktop/ms740120%28v=vs.85%29.aspx I have compiled without any problems in VS2010.
Just make sure that the very first line in your cpp file is
#include "stdafx.h"
otherwise you would run into all sorts of compiler and link errors. Precompiled header is not an issue if you follow what I wrote previously.
Hope that helps.
recvfrom
is used with sockets. To read from the serial port (under Windows) you'd normally useReadFile
or something similar. Are you really dealing with a network connection, a serial port, or (possibly) something like SLIP or PPP that creates a socket connection over a serial port? Also, the title says writing, butrecvfrom
is for reading - Jerry Coffin 2012-04-05 18:17