Binary data transfer through serail port
-
Hi i have to read a binary file from disk and i have to transfer file through serial port. i am using mscomm1 in vc++ 6.0. Please help how to transfer a binary file through serial port.
What is your doubt about? Read the file in binary mode and then send the data on the serial line (set the
Output
property). BTW Why are you usingMsComm
(instead ofWin32 API
)? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
What is your doubt about? Read the file in binary mode and then send the data on the serial line (set the
Output
property). BTW Why are you usingMsComm
(instead ofWin32 API
)? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi i have to read a binary file from disk and i have to transfer file through serial port. i am using mscomm1 in vc++ 6.0. Please help how to transfer a binary file through serial port.
for binary data, you have to make sure the driver doesn't interfere with the data at all; so you must check each and every port setting, including: - pass NULL; - don't change CR/LF; - don't enable software handshaking. FWIW: I tend to avoid binary communication over serial ports; when portability is more important than performance, I'd rather do some encoding, typically stuffing 2 bytes in 3 printable characters (i.e. the range 0x20-0x7E), so port settings wouldn't interfere with it at all. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
i am working on dialog based application , i need to transfer binary file. any examples or sample code which helps me.
Still you're not giving info about your doubts. Are you able to read a binary file? Do you know how to use MsComm or Win32 API for serial communication? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
for binary data, you have to make sure the driver doesn't interfere with the data at all; so you must check each and every port setting, including: - pass NULL; - don't change CR/LF; - don't enable software handshaking. FWIW: I tend to avoid binary communication over serial ports; when portability is more important than performance, I'd rather do some encoding, typically stuffing 2 bytes in 3 printable characters (i.e. the range 0x20-0x7E), so port settings wouldn't interfere with it at all. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
i am working on dialog based application , i need to transfer binary file. any examples or sample code which helps me.
Please refer to: http://msdn.microsoft.com/en-us/library/aa363196(v=VS.85).aspx[^] Regards.
Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )
-
Still you're not giving info about your doubts. Are you able to read a binary file? Do you know how to use MsComm or Win32 API for serial communication? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]here i will give the example what i am doing. CFile file; CString str; unsigned char ch; if(file.Open("source.bin",CFile::modeRead|CFile::typeBinary)) int nLength = file.GetLength(); for(i=0;i<=nLength;i++) //Transfering file data { file.Read(&ch,1); str.Format ("%c",ch); m_mscom.SetOutput (COleVariant(str)); } is it the right way to transfer a binary file ?. i have to transfer a binary file up to 15MB.
-
hi Luc Pattyn do you have a sample code , so it will help to understood, still i am confuse
No, as I said I avoid doing such things as it is more trouble than its worth most of the time. I haven't done any binary serial comm on Windows using C/C++ in many years; and if I really had to do it today, I'd use C# anyway. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
here i will give the example what i am doing. CFile file; CString str; unsigned char ch; if(file.Open("source.bin",CFile::modeRead|CFile::typeBinary)) int nLength = file.GetLength(); for(i=0;i<=nLength;i++) //Transfering file data { file.Read(&ch,1); str.Format ("%c",ch); m_mscom.SetOutput (COleVariant(str)); } is it the right way to transfer a binary file ?. i have to transfer a binary file up to 15MB.
Well, you don't need to read the file (and write it to the serial port) a character at time (incidentally your loop-exit condition it's wrong, you should use
i<nLength
). For sending binary data, you need to fill aSafeArray
and pack it into aVariant
, see, for instance: "Mscomm and mode binary" at codeguru (usingMFC
OLE
wrapper classes really helps here). Again, you may also choose to avoidCOM
and go withWin32
'sCreateFile, WriteFile
, .., see the link Paniello provided. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Well, you don't need to read the file (and write it to the serial port) a character at time (incidentally your loop-exit condition it's wrong, you should use
i<nLength
). For sending binary data, you need to fill aSafeArray
and pack it into aVariant
, see, for instance: "Mscomm and mode binary" at codeguru (usingMFC
OLE
wrapper classes really helps here). Again, you may also choose to avoidCOM
and go withWin32
'sCreateFile, WriteFile
, .., see the link Paniello provided. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
BYTE *pBuffer = new BYTE[nLength]; COleVariant var; CByteArray barr; file.Read(pBuffer,nLength); for(UINT i = 0; i
Why don't you try (start with small amount of data)? You know, sending 15MB of data will take more than 20 minutes even at 115200 baud.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi i have to read a binary file from disk and i have to transfer file through serial port. i am using mscomm1 in vc++ 6.0. Please help how to transfer a binary file through serial port.
Just create a file pointer to the serial port com1/com2. And do operations read file and write file with small chunks of data. And about the UI(User interface ) that u can create using MFC dialog based application. Silly matter only... Thanking you Krish
-
Why don't you try (start with small amount of data)? You know, sending 15MB of data will take more than 20 minutes even at 115200 baud.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
BYTE *pBuffer = new BYTE[nLength]; COleVariant var; CByteArray barr; file.Read(pBuffer,nLength); for(UINT i = 0; i
jiya-123 wrote:
for(UINT i = 0; i < sizeof((pBuffer)/sizeof(BYTE)) ; i++)
Really? You do realize that loop equates to:
for(UINT i = 0; i < 4; i++)
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Hi i have to read a binary file from disk and i have to transfer file through serial port. i am using mscomm1 in vc++ 6.0. Please help how to transfer a binary file through serial port.
Chances are the eunuch guarding the serail port won't like binary data. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
First of all, see what David correctly pointed out http://www.codeproject.com/Messages/3628586/Re-Binary-data-transfer-through-serail-port.aspx[^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Chances are the eunuch guarding the serail port won't like binary data. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Generally, there's no problem sending binary data through a serial port if you are sure both ends are using full transparancy of the data, allow NULLs, CR/LF expansion (as mentioned by someone else above). XOFF and XON and EOF also need to be transparent. The real issue is what do you do about "transmission errors"? There's no guarantee that serial data gets to the other side without problems, dropped bits, character framing errors. So, typically you have to wrap the data with some higher level checking, CRC, etc to ensure proper transmission of the data. Of course, since corruption is detected on the receiving side, you then need to tell the transmitter to re-send the data stream. Wait, this is beginning to sound a lot like a complete protocol.....
-
Generally, there's no problem sending binary data through a serial port if you are sure both ends are using full transparancy of the data, allow NULLs, CR/LF expansion (as mentioned by someone else above). XOFF and XON and EOF also need to be transparent. The real issue is what do you do about "transmission errors"? There's no guarantee that serial data gets to the other side without problems, dropped bits, character framing errors. So, typically you have to wrap the data with some higher level checking, CRC, etc to ensure proper transmission of the data. Of course, since corruption is detected on the receiving side, you then need to tell the transmitter to re-send the data stream. Wait, this is beginning to sound a lot like a complete protocol.....
I've been there. And it might be easier/better to install SLIP and use FTP then. Unfortunately the OP never mentioned what the other side was, in fact he didn't give any context. BTW: The transparency reply was mine also, this one was a reaction on the typo in the subject line. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I've been there. And it might be easier/better to install SLIP and use FTP then. Unfortunately the OP never mentioned what the other side was, in fact he didn't give any context. BTW: The transparency reply was mine also, this one was a reaction on the typo in the subject line. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Oh, a "serail port". Isn't that where they take containers directly off the ship and put them on trains (or visa-versa). ;)