can anyone guide me how can I send and receive (transfer) files between 2 computers using RS232...pls also give some link about the basics because I have no background of this concept nor any good material
Thanks,
Edesign
can anyone guide me how can I send and receive (transfer) files between 2 computers using RS232...pls also give some link about the basics because I have no background of this concept nor any good material
Thanks,
Edesign
Also, one more question..where can I learn VB? Is there any forum of this group related to VB??
Thanks,
Edesign
The principle of serial communication is pretty simple, but there is no definite portable standard, so it would depend on several things....
What hardware/OS are you using?
Do you have a particular protocol in mind?
As to VB, I'm sure there are people on the board that knows VB, but there is no board on this site for VB discussions in particular.
--
Mats
Last edited by matsp; 03-12-2008 at 03:29 AM.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
basically, i want to transfer a file between 2 pcs using an RF module(or an optical fiber)..I wrote a program using outportb which sent characters but now need to do it with entire file...i will be using windows xp and at college I have IBM machine...the hardware part is already available(for some other purpose we made it actually)...but have no idea about the software...where to start with..
So, you have a PC running XP and an IBM <what architecture> running <what OS>?
On the PC side, you could open the serial port with CreateFile().
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Hello,
I actually wrote a small program, but now the trouble is...I am using inport and outport in my program and I have included <dos.h>...still compiling it in Visual studio gives an error that these functions are not defined...
Edesign
If you're actually using RS232...
http://msdn2.microsoft.com/en-us/library/ms810467.aspx
gg
Oh my God...It seems so tough to me...Isn't there any other way...
Or..pls if someone can give me a brief idea in simpler language...Or where can I get examples and overview that sort of explanation??
Edesign
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
http://electrosofts.com/serial/ should help.
Try using a DOS based compiler like Turbo C.
Not everything that can be counted counts, and not everything that counts can be counted
- Albert Einstein.
No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
- Herbert Mayer
Here's some code that I've used in the past to communicate with a security controller which uses a Motorola 68000 processor.
Code:#include <windows.h> #include <stdio.h> #include <string.h> HANDLE hPort; BOOL WriteByte(BYTE bybyte) { DWORD iBytesWritten=0; DWORD iBytesToRead = 1; if(WriteFile(hPort,(LPCVOID) &bybyte,iBytesToRead,&iBytesWritten,NULL)==0) return FALSE; else return TRUE; } BOOL WriteString(const void *instring, int length) { int index; BYTE *inbyte = (BYTE *) instring; for(index = 0; index< length; ++index) { if (WriteByte(inbyte[index]) == FALSE) return FALSE; } return TRUE; } BOOL ReadByte(BYTE &resp) { BOOL bReturn = TRUE; BYTE rx; DWORD dwBytesTransferred=0; if (ReadFile (hPort, &rx, 1, &dwBytesTransferred, 0)> 0) { if (dwBytesTransferred == 1) { resp=rx; bReturn = TRUE; } else bReturn = FALSE; } else bReturn = FALSE; return bReturn; } BOOL ReadString(void *outstring, int *length) { BYTE data; BYTE dataout[4096]={0}; int index = 0; while(ReadByte(data)== TRUE) { dataout[index++] = data; } memcpy(outstring, dataout, index); *length = index; return TRUE; } void ClosePort() { CloseHandle(hPort); return; } HANDLE ConfigureSerialPort(LPCSTR lpszPortName) { HANDLE hComm = NULL; DWORD dwError; DCB PortDCB; COMMTIMEOUTS CommTimeouts; // Open the serial port. hComm = CreateFile (lpszPortName, // Pointer to the name of the port GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode 0, // Share mode NULL, // Pointer to the security attribute OPEN_EXISTING, // How to open the serial port 0, // Port attributes NULL); // Handle to port with attribute // to copy // Initialize the DCBlength member. PortDCB.DCBlength = sizeof (DCB); // Get the default port setting information. GetCommState (hComm, &PortDCB); // Change the DCB structure settings. PortDCB.BaudRate = 9600; // Current baud PortDCB.fBinary = TRUE; // Binary mode; no EOF check PortDCB.fParity = TRUE; // Enable parity checking PortDCB.fOutxCtsFlow = FALSE; // No CTS output flow control PortDCB.fOutxDsrFlow = FALSE; // No DSR output flow control PortDCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type PortDCB.fDsrSensitivity = FALSE; // DSR sensitivity PortDCB.fTXContinueOnXoff = TRUE; // XOFF continues Tx PortDCB.fOutX = FALSE; // No XON/XOFF out flow control PortDCB.fInX = FALSE; // No XON/XOFF in flow control PortDCB.fErrorChar = FALSE; // Disable error replacement PortDCB.fNull = FALSE; // Disable null stripping PortDCB.fRtsControl = RTS_CONTROL_ENABLE; // RTS flow control PortDCB.fAbortOnError = FALSE; // Do not abort reads/writes on // error PortDCB.ByteSize = 8; // Number of bits/byte, 4-8 PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space PortDCB.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2 // Configure the port according to the specifications of the DCB // structure. if (!SetCommState (hComm, &PortDCB)) { printf("Could not configure serial port\n"); return NULL; } // Retrieve the time-out parameters for all read and write operations // on the port. GetCommTimeouts (hComm, &CommTimeouts); // Change the COMMTIMEOUTS structure settings. CommTimeouts.ReadIntervalTimeout = MAXDWORD; CommTimeouts.ReadTotalTimeoutMultiplier = 0; CommTimeouts.ReadTotalTimeoutConstant = 0; CommTimeouts.WriteTotalTimeoutMultiplier = 0; CommTimeouts.WriteTotalTimeoutConstant = 0; if (!SetCommTimeouts (hComm, &CommTimeouts)) { printf("Could not set timeouts\n"); return NULL; } return hComm; } int main(void) { // Can also use COM2, COM3 or COM4 here hPort = ConfigureSerialPort("COM1"); if(hPort == NULL) { printf("Com port configuration failed\n"); return -1; } // Call your ReadString and WriteString functions here ClosePort(); return 0; }
i wrote a small code using inportb & outportb....just checked with a serial cable connected between 2 pcs...
I am able to transfer files but facing 2 problems...
1) even though the baud rate set is very high 38400bps, it takes too much of time..I mean
by this baud rate ideally it should have a datarate of 3.75KBps, but to transfer a 15KB file it takes more than 1.5-2 minutes..I don't know why..
2) this is the code used for reception
this does the work, but every time i need to break the execution..guessing it might have comlete reception..Is there some sort of acknowledge mechanism..so that i can know tht file transfer is complete...Code:void receivefile(FILE *out) { do { c=inportb(PORT1+5); if(c&1) { cha=inportb(PORT1); fputc(cha,out); delay(10); } }while(1); }
Would you think that waiting 0.01 seconds every character you output could have some effect on the transfer time? At 38400, this is equivalent of waiting for 384 bit times - so 38 characters, making it 39 two out of five waits.Code:delay(10);
Also calling fputc on every character will be noticably less efficient than buffering up some amount (such as 256 to 1024 bytes) and storing that using fwrite().
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
hey edesign
I have book calledit's mostly about PARALLEL PORT but it might help you. If you need it just send me a PM .Code:interfacing-with-c-programming-real-world-applications
thanks.
Guess you can use a sentinel character in the file you are sending so that you can check it in the received file.this does the work, but every time i need to break the execution..guessing it might have comlete reception..Is there some sort of acknowledge mechanism..so that i can know tht file transfer is complete...
Suppose if it is '#'
Like so...
instead ofCode:do { // code to receive }while(cha!='#');
Code:do { // code to receive }while(1);
Not everything that can be counted counts, and not everything that counts can be counted
- Albert Einstein.
No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
- Herbert Mayer