I am exploring the RS232 communication possibilities. I am faced with problems when i try to send file across the rs232 port. Please help...

I am really sorry if i was not expressive enough. I will explain the situation.

I have implemented the RS232 communication, At System A, i am having the program developed using Visual Basic and on System B I have another program written using C++. The two programs already communicates using the RS232 port and it is currently works like a chat utility. To enhance the work i want to add an additional module to send files. Here i am faced with problems.

To be specific, i tried to send a text file across the port. The data is being received at the other end and saved to the file also. But when i open the file at the received end i observed that additional enter has been saved. After an analysis i found out that it was not exactly an enter (chr(13)) but chr(10) that appearing on the output file.

If somebody could clarify, it would be highly helpful....

>> zandiago Glad to have you with us! Please place question in correct section of Forum!

So since i am using both Visual Basic and C++, i was not sure where to make the post. Sorry About that..

You need to be careful about transferring files from MS-Windows platform to *nix or other platforms. MS-Windows uses two bytes to indicate end-of-line while *nix, MAC and others use only one character. So if you read text files in binary mode and send that to other operating systems the receiving program has to translate the CR/LF pair to whatever the target os expects.

File transfer programs, the receiving program does the translations because the sending program may or may not know what platform it is communicating with. So, the receiving program on *nix platforms need to translate 0x0a 0x0d pair to just 0x0a and on MAC they would be translated to 0x0d (unless I have that backwards).

You need to be careful about transferring files from MS-Windows platform to *nix or other platforms. .......

Under Stood. You reply has been very clear. But what if i want to transfer a executable file.
if any translation (as mentioned in the case of Text File) takes place, the exe will become unusable. Pls advise.

you don't do anything with files that are saved as binary files on the disk, such as executable files. Only do the translation of text files. BTW: it will do no good to transfer an executable file from MS-Windows to *nix anyway because it won't run on *nix :)

you don't do anything with files that are saved as binary files on the disk, such as executable files. Only do the translation of text files. BTW: it will do no good to transfer an executable file from MS-Windows to *nix anyway because it won't run on *nix :)

I think the scenario is still not clear. I will try to make it clear.
Today there are so many medium for file transfer like 1. Internet, 2. Pen Drive, 3. CD ...and so on.....and so there may not be much scope for file transfer through RS232. I want to do this to supplement my learning curve.

So i want to transfer an executable ( or for that matter an image file ) file byte by byte from System A to System B using RS232. Of course if System B is a *nix it won't run and that does not matter at all.

NB: Actually what i plan to implement is a cross platform file transfer utility using RS232.

Please Advise...

To be specific, i tried to send a text file across the port. The data is being received at the other end and saved to the file also. But when i open the file at the received end i observed that additional enter has been saved. After an analysis i found out that it was not exactly an enter (chr(13)) but chr(10) that appearing on the output file.

I think the scenario is still not clear. I will try to make it clear.
Today there are so many medium for file transfer like 1. Internet, 2. Pen Drive, 3. CD ...and so on.....and so there may not be much scope for file transfer through RS232. I want to do this to supplement my learning curve.

So i want to transfer an executable ( or for that matter an image file ) file byte by byte from System A to System B using RS232. Of course if System B is a *nix it won't run and that does not matter at all.

NB: Actually what i plan to implement is a cross platform file transfer utility using RS232.

Please Advise...

So does that mean your original post is wrong ? You don't want to transfer a text file but a binary file such as image or executable? Or both types ?

Again, if transfering a binary file neither the client nor the server should do anything at all with the data types -- no translation should take place. Open the files in binary mode, not text mode, like this in c++. VB has similar capability to open a file in binary mode.

// open the file for input
ifstream in("filename", ios::binary);

unsigned char* buf = 0;
// get file size
in.seekg(0, ios::end);
size_t filesize = in.tellg();
// back to beginning of the file
in.seekg(0,ios::beg);
// allocate memory for the file
buf = new unsigned char[filesize];
// read the file
in.read(buf, filesize);
// close the file
in.close();
// now send buf to the other computer over rs232 port.

So does that mean your original post is wrong ? ....

Thank you for the reply, i will attempt the file file transfer and get back to you.
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.