Click here to Skip to main content
15,885,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send the data using Rs232c to Toshiba TOSNUC CNC. While sending data less then 40 lines, data passes without any error but in case more than 40 lines, few line were missing. how to resolved it.

serial comm. setting
baudRate- 4800
Databits- 7
Parity-Even
StopBits-2

What I have tried:

if (this->serialPort->IsOpen)
		{
String^ txt = richTextBox6->Text;
serialPort->Write(header};
Thread::Sleep(1000);
serialPort->Write(txt );
Thread::Sleep(1000);
serialPort->Write(footer);
}

serialPort->Write(header+txt+footer);//got same error in this as well
Posted
Updated 18-Nov-21 14:46pm

I would guess you are overflowing the machine's serial port buffer. There are a few ways you can deal with it. First is let the hardware do the work. That means you need to have a cable with the control signal lines connected appropriately on both sides as described at Null modem - Wikipedia[^]. The control signals are used by the machine to tell the sender its buffer is full. A well-behaved serial port driver will pause transmission when the receiving side is not ready to receive data and this would solve your problem. Most serial cables have just three lines so this option may not be available to you.

Another way is to insert delays, as you have already, but delay after some number of characters. You stated there is loss after forty lines so figure out how many bytes that is and delay a few hundred milliseconds after each batch of that many bytes. Usually serial port buffers are 256 or 512 bytes but you can determine that through experimentation. The delays will allow the machine to process the data in its buffer so it can accept more. I recommend that you parameterize the number of bytes between delays and the duration of the delay. Values I would start with are 256 bytes and 200mS. Adjust them as necessary until all of the data is received correctly.
 
Share this answer
 
Additionally to what Rick York has said, check that the flow control settings on both ends of the connection agree. There are two types of handshaking, hardware (RTS/CTS) and software (XON/XOFF). The difference is that RTS/CTS raises/lowers the voltage on a specific wire to indicate that the receiver is ready for data, while XON/XOFF sends a character over the wire to tell the sender when it should start or stop sending data. Typically there's a UART on the connection that will handle the flow control for you, you don't need to do anything other than make sure both ends are expecting the same flow control. You'll have to check the specs on the CNC machine to see what its expecting and/or how to set it. You'll also have to do some research to find out how to tell your program to set the serial connection correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900