Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - got error while reading from COM 1: (11 Items)
   
got error while reading from COM 1  
HI,

i like to read from serial port COM1 and so that i ve opened and write it successfully . but i was unable to read from 
it.. and am using QNX RTOS in vmware and using QNX momentics. please help me as soon as possible.i attached my code here


//code:
/*
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<termios.h>
#include<string.h>
#include<stdlib.h>
#include<pthread.h>
#include<time.h>
#include<signal.h>
#include<sys/time.h>
//pthread_t serial_thread1;
//int serial_temp=0,serial_temp1=0;
int WriteAdrPort(char*);
//int readadrport1(char*,int);
int readadrport(char*,int);
void CloseAdrPort();
int serial_fd=0;
struct termios serial_termios;
int main(int argc,char *argv[])
{
char serial_writemsg[100];
char serial_readmsg[100];
char serial_portname[100];
int serial_portnumber;
int serial_write;
printf("\n enter the serial port number");
scanf("%d",&serial_portnumber);
printf("OpenAdrPort port = %d \n", serial_portnumber);
sprintf(serial_portname, "/dev/ttyp%d", serial_portnumber);
printf("sPortName = %s\n", serial_portname);
serial_fd = open(serial_portname, O_RDWR | O_NOCTTY | O_NDELAY);
if (serial_fd < 0)
{
printf("open error %d %s\n", errno, strerror(errno));
exit(0);
}
else
{
printf("fd is %d\n",serial_fd);
tcgetattr(serial_fd, &serial_termios);
tcflush(serial_fd, TCIFLUSH);
serial_termios.c_cflag = B9600 | CS8 |CREAD | CLOCAL | HUPCL;
cfsetospeed(&serial_termios, B9600);
tcsetattr(serial_fd, TCSANOW, &serial_termios);
}
printf("\n enter the serial port command");
scanf("%s",serial_writemsg);
serial_write=WriteAdrPort(serial_writemsg);
if(serial_write>0)
	printf("\n successfully written");
else
	printf("\n error in writing");
sleep(5);
if(readadrport(serial_readmsg,100)>0)
{
printf("\n the msg got from the port is %s",serial_readmsg);
}
else
	printf("\n there is nothing to read");
CloseAdrPort();
}
int WriteAdrPort(char *serial_writeoutmsg)
{
int serial_out;
if (serial_fd < 1)
{
printf(" port is not open\n");
exit(0);
}
serial_out = write(serial_fd,serial_writeoutmsg, strlen(serial_writeoutmsg));
if (serial_out < 0)
{
printf("write error %d %s\n", errno, strerror(errno));
}
else
{
printf("wrote %d chars: %s\n",serial_out,serial_writeoutmsg);
}
}
int readadrport(char *serial_readoutmsg,int imax)
{
int serial_in;
serial_in = read(serial_fd,serial_readoutmsg,imax-1);
if (serial_in< 0)
{
if (errno == EAGAIN)
{
printf("\n no response from read port");
//return 0;
}
else
{
printf("read error %d %s\n", errno, strerror(errno));
}
}
else
{
printf("read %d chars: %s\n", serial_in,serial_readoutmsg);
}
return serial_in;

}
void CloseAdrPort()
{
if (serial_fd > 0)
{
close(serial_fd);
}
}
*/

thanks in advance,
shakthi


Re: got error while reading from COM 1  
Hi Shakti,

...without looking much further in your code:

Try opening "/dev/ser%%d" instead of "/dev/ttyp%d". The latter is a pseudo-terminal device, whereas "ser" designates 
serial (=COM) ports.

Cheers,
Thomas
Re: got error while reading from COM 1  
hi,

thanks for your suggestion.

yes , com 1= /dev/ser1 and com2=/dev/ser2 . you are right.

i ve checked with that too.. but dint get output..... after i ve written in COM1 and i tried to read if from COM1 but 
cant read.... and if i use ttyp0 onli my output that is whatever written , will be display in QNX RTOS which was running
 in same pc ... but if i use ser1 or ser2 , nothing will be display in QNX RTOS.. and am using same pc and same COM1(for
 reading and writing) and VMware running in same pc.


thanks in advance,
shakthi
RE: got error while reading from COM 1  
Ah, right. That'll be the next problem. AFAIK, you'll not be able to exchange data 
between the host and the virtual machine in both directions. Depending on the settings 
in your VMware, you'll be using:
- either an existing (hardware) COM port of your host, then you cannot use a host 
  application to talk to the virtual machine (you'd need to loopback the serial 
  port... :-)
- or a file / pipe on the host; in that case, the VM will only be able to write to 
  the serial port.

If you need to test bi-directional serial communication in your VM, I think there 
is only one option - use a second host and a serial cable to establish a true serial 
connection, and configure your VM to attach to the physical COM port.

Regards,
Thomas

-----Original Message-----
From: shakthi b [mailto:community-noreply@qnx.com] 
Sent: Donnerstag, 8. September 2011 13:43
To: general-bazaar
Subject: Re: got error while reading from COM 1

hi,

thanks for your suggestion.

yes , com 1= /dev/ser1 and com2=/dev/ser2 . you are right.

i ve checked with that too.. but dint get output..... after i ve written in COM1 and i tried to read if from COM1 but 
cant read.... and if i use ttyp0 onli my output that is whatever written , will be display in QNX RTOS which was running
 in same pc ... but if i use ser1 or ser2 , nothing will be display in QNX RTOS.. and am using same pc and same COM1(for
 reading and writing) and VMware running in same pc.


thanks in advance,
shakthi



_______________________________________________

General
http://community.qnx.com/sf/go/post88709
Re: RE: got error while reading from COM 1  
hi thomas,

thanks for your reply.. but what to do now?? i dint understand what u r referring? but now am connecting com1 and com2 
using female pin connector.. now i can write it in com1 using qnx and read it from com2 using qnx.. but now also am 
facing same problem..... do u ve any other suggestion?? or is it possible to use hyperterminal like write it to com2 
using hyperterminal , so that i can read it from com2. please say ur suggestion. am ameatur in serial port in qnx...

thanks in advance,
shakthi
RE: RE: got error while reading from COM 1  
Well, if you have 2 physical serial ports on your host, it's easy:

- Connect the two ports using a null-modem cable (as you probably already did)
- Configure the VM to use one of the host's physical serial ports (e.g., COM1)
  No matter which one you use, it should show up as /dev/ser1 under QNX.
- Run a terminal emulation (e.g., hyperterminal) on the host, and connect to 
  the _other_ COM port (e.g., COM2). 

With that setup, you should be able to both read and write from/to the serial 
port in QNX.

Regards,
Thomas


-----Original Message-----
From: shakthi b [mailto:community-noreply@qnx.com] 
Sent: Donnerstag, 8. September 2011 14:26
To: general-bazaar
Subject: Re: RE: got error while reading from COM 1

hi thomas,

thanks for your reply.. but what to do now?? i dint understand what u r referring? but now am connecting com1 and com2 
using female pin connector.. now i can write it in com1 using qnx and read it from com2 using qnx.. but now also am 
facing same problem..... do u ve any other suggestion?? or is it possible to use hyperterminal like write it to com2 
using hyperterminal , so that i can read it from com2. please say ur suggestion. am ameatur in serial port in qnx...

thanks in advance,
shakthi



_______________________________________________

General
http://community.qnx.com/sf/go/post88713
Re: got error while reading from COM 1  
hi thomas,

thanks for your reply... can you tell me how to configure the VMware to use one of the serial ports like COM1(do u mean 
execute my code using com1 i.e. /dev/ser1 rite) .. pls help me..

thanks in advance,
shakthi
RE: got error while reading from COM 1  
Hi,

to configure a VMware player, follow the steps below. For other VMware products, the procedure should be similar:
- Shutdown QNX within in the virtual machine
- "Power off" the virtual machine ("Virtual Machine" / "Power" / "Power off"). Do NOT exit the VMware player.
- Click "Edit virtual machine settings"
- In the list on the hardware tab, select the serial port (or add a new one with default settings if there isn't any)
- Check "Connect at power on"
- Select "Use physical serial port"
- From the combo box, select the serial port you want the VM to use
- Click "Ok" and start the virtual machine. /dev/ser1 should now be connected to the configured COM port.

Regards,
Thomas

-----Original Message-----
From: shakthi b [mailto:community-noreply@qnx.com] 
Sent: Freitag, 9. September 2011 08:22
To: general-bazaar
Subject: Re: got error while reading from COM 1

hi thomas,

thanks for your reply... can you tell me how to configure the VMware to use one of the serial ports like COM1(do u mean 
execute my code using com1 i.e. /dev/ser1 rite) .. pls help me..

thanks in advance,
shakthi



_______________________________________________

General
http://community.qnx.com/sf/go/post88739
Re: RE: got error while reading from COM 1  
hi thomas,

thanks for your reply..my issue not resolved yet..
i dint get output and i cant able to read through hyperterminal which is running in windows..... is there any specified 
baudrate we should maintain while writing the code..??


thanks in advance,
shakthi
RE: RE: got error while reading from COM 1  
Hi,

regarding the baud rate: Yes, of course -- the one you specified in the termios structure and cfsetospeed(), i.e., 9600 
baud. It might be a good idea to also set the input baud rate explicitly, using cfsetispeed().

From what I see in the code you provided, your COM port setting should be 9600,N,8,1 (9600 baud, no parity, 8 data bits,
 1 stop bit).

You could try running a second instance of 'hyperterminal' instead of VMware, to see whether the serial communication 
between the two serial comm. ports on your host works at all. If it does, you can advance to using VMware with QNX on 
one end.

Regards,
Thomas


-----Original Message-----
From: shakthi b [mailto:community-noreply@qnx.com] 
Sent: Mittwoch, 14. September 2011 13:09
To: general-bazaar
Subject: Re: RE: got error while reading from COM 1

hi thomas,

thanks for your reply..my issue not resolved yet..
i dint get output and i cant able to read through hyperterminal which is running in windows..... is there any specified 
baudrate we should maintain while writing the code..??


thanks in advance,
shakthi



_______________________________________________

General
http://community.qnx.com/sf/go/post88818
Re: RE: RE: got error while reading from COM 1  
hi thomas,

thank you so much for your help.. successfully got output in hyperterminal when i write something in com1 using qnx code
.. but now problem is it can able to read only two characters. dont why this happened?? can you clarify my doubt.. 

my code is :
// qnx code
/*#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<termios.h>
#include<string.h>
#include<stdlib.h>
#include<pthread.h>
#include<time.h>
#include<signal.h>
#include<sys/time.h>
//pthread_t serial_thread1;
//int serial_temp=0,serial_temp1=0;
int WriteAdrPort(char*);
//int readadrport1(char*,int);
int readadrport(char*,int);
void CloseAdrPort();
int serial_fd=0;
struct termios serial_termios;
int main(int argc,char *argv[])
{
char serial_writemsg[100];
char serial_readmsg[100];
char serial_portname[100];
int serial_portnumber;
int serial_write;
memset((void*)&serial_writemsg,'\0',sizeof(serial_writemsg));

printf("\n enter the serial port number");
scanf("%d",&serial_portnumber);
printf("OpenAdrPort port = %d \n", serial_portnumber);
sprintf(serial_portname, "/dev/ser%d", serial_portnumber);
printf("sPortName = %s\n", serial_portname);
serial_fd = open(serial_portname, O_RDWR | O_NOCTTY | O_NDELAY);
if (serial_fd < 0)
{
printf("open error %d %s\n", errno, strerror(errno));
exit(0);
}
else
{
printf("fd is %d\n",serial_fd);
tcgetattr(serial_fd, &serial_termios);
tcflush(serial_fd, TCIFLUSH);
//serial_termios.c_cflag = B9600 | CS8 |CREAD | CLOCAL | HUPCL;
cfsetispeed(&serial_termios,B9600);
cfsetospeed(&serial_termios, B9600);
tcsetattr(serial_fd, TCSANOW, &serial_termios);
}
printf("\n enter the serial port command");
scanf("%s",serial_writemsg);
serial_write=WriteAdrPort(serial_writemsg);
if(serial_write>0)
	printf("\n successfully written");
else
	printf("\n error in writing");

CloseAdrPort();
}
int WriteAdrPort(char *serial_writeoutmsg)
{
int serial_out;
if (serial_fd < 1)
{
printf(" port is not open\n");
exit(0);
}
serial_out = write(serial_fd,serial_writeoutmsg, strlen(serial_writeoutmsg));
if (serial_out < 0)
{
printf("write error %d %s\n", errno, strerror(errno));
}
else
{
printf("wrote %d chars: %s\n",serial_out,serial_writeoutmsg);
}
}
void CloseAdrPort()
{
if (serial_fd > 0)
{
close(serial_fd);
}
}
*/


thanks in advance,
shakthi