Hello,
I am trying to program a serial device (Nova Source Synthesizer) via the 9Pin
com port. I was able to program device using MatLab via the following
commands:
Port = serial('Com2');
set(Port, 'BaudRate', 38400, 'Parity', 'none', 'Terminator', 'CR');
fprintf(Port, 'FR3810');
In this example the frequency (FR) of the synthesizer is program for 3810MHz.
Can someone provide the basic commands to open up a communication port and
then be able to transmit 'FR3810' using a .c code on a DEV C++ compiler. Many
Thanks!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note that the port was opened in binary mode and the CR ('\r'), line
terminator explicitly used in the printf(); that appears to be implied in the
MATLAB code. If you did not use binary mode and use the more usual '\n', you
get a CR+LF line termination on Windows, and just LF on Linux, and other
operating systems may have different conventions. However it is likely that
your device will accept either convention; I am just trying to emulate your
MATLAB implementation.
I made a shell call to set the port configuration, this is a bit quick and
dirty, but works. The Win32 API has more flexible ways to perform serial I/O
that will work better in a GUI application, see for an example/tutorial. You
will see that it is hard work! Microsoft added a much better and more elegant
interface for serial I/O communications in the , but Dev-C++ does not support
that; but the frankly far better (and free) VC++ 2008 Express does, although
you'd have to use C++/CLI, and .Net programming is much cleaner in C# in any
case. If you are doing a lot of serial I/O and especially if you are
implementing a GUI interface I'd recommend .Net/Windows forms, which therefore
means using either VC++, C# or one of the other ,Net languages.
Hello,
I am trying to program a serial device (Nova Source Synthesizer) via the 9Pin
com port. I was able to program device using MatLab via the following
commands:
Port = serial('Com2');
set(Port, 'BaudRate', 38400, 'Parity', 'none', 'Terminator', 'CR');
fprintf(Port, 'FR3810');
In this example the frequency (FR) of the synthesizer is program for 3810MHz.
Can someone provide the basic commands to open up a communication port and
then be able to transmit 'FR3810' using a .c code on a DEV C++ compiler. Many
Thanks!!!
You can use pretty much what you have used in MATLAB (although there are more
elegant but complex methods in Win32):
FILE* port ;
port = fopen( "com2", "w+b" ) ;
system( "mode com2 baud=38400 parity=none") ;
fprintf( port, "FR3810\r" ) ;
Note that the port was opened in binary mode and the CR ('\r'), line
terminator explicitly used in the printf(); that appears to be implied in the
MATLAB code. If you did not use binary mode and use the more usual '\n', you
get a CR+LF line termination on Windows, and just LF on Linux, and other
operating systems may have different conventions. However it is likely that
your device will accept either convention; I am just trying to emulate your
MATLAB implementation.
I made a shell call to set the port configuration, this is a bit quick and
dirty, but works. The Win32 API has more flexible ways to perform serial I/O
that will work better in a GUI application, see for an example/tutorial. You
will see that it is hard work! Microsoft added a much better and more elegant
interface for serial I/O communications in the , but Dev-C++ does not support
that; but the frankly far better (and free) VC++ 2008 Express does, although
you'd have to use C++/CLI, and .Net programming is much cleaner in C# in any
case. If you are doing a lot of serial I/O and especially if you are
implementing a GUI interface I'd recommend .Net/Windows forms, which therefore
means using either VC++, C# or one of the other ,Net languages.
: http://msdn.microsoft.com/en-
us/library/ms810467.aspx
: http://msdn.microsoft.com/en-
us/library/system.io.ports.serialport.aspx
Sourceforge's new mark-up implementation really sucks! StackOverflow wuse teh
same 'mark-down' notation and had managed to make it work!
Where in the code it says "e, replace with "
Clifford