Serial Port Accessing / File handling in Local Network

P

pandi

Hi

I am developing a mini application which just get the input from
serial port and after this copies some file to my LAN machine(share
folder)...I am using Visual C++....


Friends can you give the way to access serial port? and then network
file accessing like open a file and write/read, close?

One more thing i want to know is regarding system command using...

I can able to use system command like
system("CMD arg1..argn") => This works fine

However what i need is arg1 is stored to a variable var1 and then
others in var2,,,var3
Now how to i use this variable in system command..

Thanks
 
M

Michael Doubez

I am developing a mini application which just get the input from
serial port and after this copies some file to my LAN machine(share
folder)...I am using Visual C++....

Friends can you give the way to access serial port? and then network
file accessing like open a file and write/read, close?

I could but it would be rude because your are OT here.
Please ask your question on
comp.os.ms-windows.programmer.win32

Another solution it to look for a solution on Google or MSDN.
One more thing i want to know is regarding system command using...

I can able to use system command like
system("CMD arg1..argn") => This works fine

However what i need is arg1 is stored to a variable var1 and then
others in var2,,,var3
Now how to i use this variable in system command..

You build you system command

string cmd = "CMD ";
string var1,var2,var3;
cmd += var1 + ' ' + var2 + ' ' + var3;

And then execute it:
::system( cmd.c_str() );
 
P

pandi

Hi

Many Thanks for Your help..

Now am able to use system command as per your suggestion.

One general doubts is FILE handling, Actually i want to open a file in
desktop and give path like "C:\Documents and Settings\Administrator
\Desktop\test.txt" but it did not open..since we have space character
in this path. How to open of this type file.

Thanks again...
 
M

Michael Doubez

Now am able to use system command as per your suggestion.

One general doubts is FILE handling, Actually i want to open a file in
desktop and give path like "C:\Documents and Settings\Administrator
\Desktop\test.txt" but it did not open..since we have space character
in this path. How to open of this type file.

You could add "" around the path parameters (that's how it is done in
scripts), or I guess there must be some possible encoding with
backslashes. This is a question best asked on comp.os.ms-
windows.programmer.win32.

[snip: don't top post]
 
P

pandi

Ok Thanks Michael...

Now am able to use system command as per your suggestion.
One general doubts is FILE handling, Actually i want to open a file in
desktop and give path like "C:\Documents and Settings\Administrator
\Desktop\test.txt" but it did not open..since we have space character
in this path. How to open of this type file.

You could add "" around the path parameters (that's how it is done in
scripts), or I guess there must be some possible encoding with
backslashes. This is a question best asked on comp.os.ms-
windows.programmer.win32.

[snip: don't top post]
 
J

James Kanze

[...]
One general doubts is FILE handling, Actually i want to open a file in
desktop and give path like "C:\Documents and Settings\Administrator
\Desktop\test.txt" but it did not open..since we have space character
in this path. How to open of this type file.

Technically, the limitations on filenames are defined by the
implementation, but practically, all of the implementations I know
will
accept anything the OS will, including white space in the case of
Windows or Unix. What might be causing you problems is the fact that
'\' is an escape character in string literals. Just replace it with
'/'
(which works fine in both Windows and Unix), and there will be no
problems.

Outside of literals, of course: when displaying filenames, you want to
display what the user expects, which is '\' under Windows; and when
parsing them, you want to behave exactly as the system does, which
means
recognizing both '\' and '/' as directory separators under Windows.
 
J

James Kanze

A correction: also cmd.exe and other utilities can accept forward
slashes in pathnames if one manages to convince them that this is a
single filename argument which has to be directly passed to a system
function. For that one can try enclosing the filename in double
quotes. Different commands/programs accept different things, though.

I was going to say that I use it rather regularly in cmd.exe, with no
problems. (Filename expansion doesn't take it into account, but
everything else does.) It's true that the Windows documentation says
to
use a '\', with a note that the file I/O functions in the Windows API
convert '/' to '\' (except when they don't). In practice, the real
problem with '/' is that it is conventionally used to signal an option
(like '-' under Unix); you should definitely avoid filenames that
start
with a '/' (but "c:/..." doesn't generally seem to cause problems).

Of course, you can always write it: "file://c:/...":). (In URL's,
'/'
is the only allowed path separator.)

In practice, I'll stand by my original statement: a well written
program
should accept both '/' and '\' in input (and will pass the '/' on to
the
system, if that's all it's doing with the filename), and use '\' in
output (because it is the "standard"). The one exception is in argv:
if
argv starts with a '/', it's an option, not a filename (and for
various historical reasons, a well written program will accept either
'/' or '-' as an option---most of Microsoft's code does).
(Internally,
you might prefer maintaining the name in an std::vector< std::string
and ignoring the issue:).)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top