read()/write() through serial cable in photon using PtText()

Hi,

Can u Please tell me how to go about to communicate between two different photon application with PtText() widget, in two differnt machnies using write()/read() and serial cable.

Hello Swetha,
These matters are not related. In other words, serial communications are the same, whether PtText (and even Photon) is used or not. If you are seeking advice on designing and implementing serial communications, you should post your requirements.
Regards,
Yuriy

Thanku for your Reply Sir,

Below are the two different programs i am using for the transfer of message ie:

Sender::::

int
sender( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

{

char ch;
int fd;
char *users_txt_msg;
PtArg_t arg[1];

fd = open("/dev/ser1", O_RDWR | O_NOCTTY | O_NDELAY);
	if (fd < 0) {
		perror("/dev/ser1");
        exit(-1);
	}
	
 PtSetArg( &arg[0], Pt_ARG_TEXT_STRING, &users_txt_msg, 0 );

PtGetResources( ABW_base_txt, 1, arg );

	ch = &users_txt_msg;
write(fd,(unsigned char*)&ch,1);			

/* Close the serial port */
close(fd); //using this is closing the graph window??

return( Pt_CONTINUE );

}

and the reciever program :

/
int
list1( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

{

int fd;
char *Line[1];
char MyData[100];
int i = 1, len;

char users_txt_msg[50];
// = “HelloWorld” ;

fd = open( “/dev/ser1”, O_RDWR | O_NOCTTY | O_NDELAY ) ;

if( fd < 0 )
{
perror ( “/dev/ser1” );
exit (-1);
}

bzero(MyData, 100);

if(users_txt_msg[i] != 0)
{
read(fd, users_txt_msg[i], 1);

strcpy(MyData, users_txt_msg);

i++;
}

len = strlen(MyData);
Line[0] = MyData;

PtListAddItems(ABW_MyList, (const char**)Line, 1, 0);
PtRealizeWidget(ABW_MyList);

return( Pt_CONTINUE );

}

I am not able to send nor recieve a proper message, is it the proper way to go with, nor any thing other, plz reply…

ch = &users_txt_msg;
write(fd,(unsigned char*)&ch,1);

I don’t understand these lines, why don’t you use

write(fd, users_txt_msg, strlen(users_txt_msg))?

Also, I would first try to start the sender program and have a generic serial terminal at the far end, rather than your own application. Is a serial communication working using cat /dev/ser1 and echo hello > /dev/ser1? Also check for edited mode, where no transmissions occur until a newline is inserted, which is probably not what you want.

-Albrecht

The same applies to read:
read(fd, users_txt_msg[i], 1);

You are reading just one byte. Read the whole buffer (and check the return code)

Just by curiosity, you are writing and reading the other node port right? I mean fd = open ("/net/other_node/dev/ser1", …)

You told that the apps. are in differents machines… Did you test the cable? With a simple console “echo” and “cat”?

I suppose that you already did all this

Other thing, check the synchronization between the Photon App. and the reading of the message. PtFlush() maybe?

Juan Manuel