Binary data transfer through serail port
-
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). ;)