Basic serial communication


dle

Recommended Posts

Hi Guru,

I'm using Renesas synergy USB device which showing virtual COM device on the computer.

The code I wrote for the Renesas is:

if (buffer == '\r') {

break;

}

I be able to putty to send a string to the Renesas USB device and read back whatever I sent before the enter key is pressed.

I try with DF such as

device.myCOMdevice.write("myString" + Chr(13))

I don't receive any feedback from the device.

I don't think Chr(13) would act like '\r' when it write to the Renesas

Do you have any suggestion?

Thanks.

 

Link to comment
Share on other sites

No, DAQFactory doesn't add line feeds except in the File. functions when writing to a file that you've opened as a text file.  For serial comms, it only outputs what you specify, and everything is considered binary.  So your statement will only send out a carriage return (ascii 13), not a line feed (ascii 10)

Link to comment
Share on other sites

Figure out the problem.

Using Putty, every time I stroke a key, a byte is sent to Renesas MCU and therefore, I have to work around with DF by sending 1 byte at a time such as 

Device.myCOMdevice.Write(first Character)
Device.myCOMdevice.Write(Second Character)

.......
Device.myCOMdevice.Write(Chr(13))

I believe the command below also sending 1 byte at a time. It could be the timing issue? 

device.myCOMdevice.write("myString" + Chr(13))

I did not see this kind of problem when I was using 8051 MCU. 

Link to comment
Share on other sites

Serial comms is always one byte at a time.  However, that doesn't mean the remote device can handle it at full speed.  It may only have a 1 byte incoming buffer and be busy with other things (like processing the previous character).  Surprising since the baud rate of the serial port limits the speed DAQFactory can send bytes out and you would think the hardware manufacturer would reduce the maximum supported baud rate to ensure this doesn't happen.  You have two choices I see:

1) lower the baud rate

2) create a routine that outputs one byte at a time.  Its pretty easy:

function writeSlow(string out)
   for (private i = 0, i < getlength(out), i++)
      device.myComDevice.write(mid(out,i,1))
   endfor

Then instead of doing device.myComDevice.write(), you would do:

writeSlow("myString" + chr(13))

You could add a delay(1) in the the loop too if you want, but my guess is you don't need it.

You might add the chr(13) into the function so you don't have to specify it every time...

Link to comment
Share on other sites

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.