Friday, November 20, 2009

C or C++ program to read data from serial port?

hello



i need a c or c++ program to read data from serial port connected to sick pls laser scanner.model is 200-113.



I have tried several programs in vc++,c,c++ but no one is able to read data serial port.



In one program i am getting msg



xxx.exe:MFC42D.dll:0xc000000: Access violation



When debugged i get



No matching symbol found :kernel32.dll



user32.dll



msvcrt60.dll



and so on.



And finally i get the program ends witih 0x0 code.



in another program it is saying bios.h not found



Whiel in anotehr it says could not able to find outportb()



I dont know the problem is.



But i need one program for this special case ie reading data from serial port connected to sick pls 200-114 laser scanner.



Eagerly waiting for answer



.Any help would be greatly appreciated.



C or C++ program to read data from serial port?microsoft visual studio



I have some c++ serial port code that does what you want. Email me and I will send it to you. I have used it for a few apps. and it seems to work just fine.



C or C++ program to read data from serial port?ie internet explorer



i guess both can be used.. there is some library which provides some methode to read data from serial port
will have 2 machines hooked up via the COM1 ports.



1 machine running windows having a hyperterminal session opened and the other machine running Linux having my program running.



I want to able to type a character into the hyperterminal window and have the character displayed on the Linux machine.



Im very new to C programming but heres what i have for my program so far, just not sure how to read the input and display it:



#include %26lt;stdio.h%26gt; /*Standard input/output definitions*/



#include %26lt;string.h%26gt; /*String function definitions*/



#include %26lt;unistd.h%26gt; /*Unix standard function definitions*/



#include %26lt;fcntl.h%26gt; /*File control definitions*/



#include %26lt;errno.h%26gt; /*Error number definitions*/



#include %26lt;termios.h%26gt; /*POSIX terminal control definitions*/



int open_port(void)



{



int fd; /* File descriptor for the port */



fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);



if(fd == 0)



{



perror("open_port: Unable to open /dev/ttyS0 - ");



}



else



fcntl(fd, F_SETFL, 0);



return (fd);



}



/*Configire port*/



struct termios options;



/*Get the current options for the port*/



tcgetattr(fd, %26amp;options);



/*Set the Baud rates to 19200*/



cfsetispeed(%26amp;options, B19200);



cfsetospeed(%26amp;options, B19200);



/*Enable received and set local mode*/



options.c_cflag |= (CLOCAL | CREAD);



/*Set new options for port*/



tcsetattr(fd, TCSANOW, %26amp;options);



/*Set data bits*/



options.c_cflag %26amp;= ~CSIZE; /*Mask the character size bits*/



options.c_cflag |= CS8; /*Select 8 data bits*/



/*Set RAW input*/



options.c_lflag %26amp;= ~(ICANON | ECHO | ECHOE | ISIG);



/*Set Raw output*/



options.c_oflag %26amp;= ~OPOST;



/*Set timeout to 1 sec*/



options.c_cc[VMIN] = 0;



options.c_cc{VTIME] = 10;



/*Code to read input goes here*/



close(fd);



Can anyone advise on this?



Thanks
Here is one program:



http://www.fogma.co.uk/foggylog/archive/...



also this article should help:



http://www.codeproject.com/system/serial...



You should know what is expected from your input device, though.

No comments:

Post a Comment

 
computer repair