Kartik Mohta |
Tech »
Serial PortThis is a simple tutorial on how to send and receive data through the serial port (including the USB-Serial converters). WindowsUse this serialport.c file which includes basic functions to initialize the serial port and send/receive data. The simplest way to start is to just put your main function in the same file. A sample main function is shown below: int main() { HANDLE serialPort; if(!serialportInit(&serialPort, "\\\\.\\COM10", 38400)) { printf("Error in serialportInit"); return -1; } // Send whatever you want SerialPutC(serialPort, 'U'); CloseHandle(serialPort); return 0; } (Yes, that weird pattern made up of backslashes and dot in front of the port name is required) Just replace COM10 with the port you are using and 38400 with the baud rate you want. Some errors you might get
LinuxFor Linux, there is already a very good library available: http://libserial.sourceforge.net/ |
Page last modified on Tue May 3 11:57:25 2011 - Powered by PmWiki |