Home > Back-end >  Victor controls the use of serial port
Victor controls the use of serial port

Time:09-17

I used victor controls from the drive (a machine) receives the data, and then painted waveform data, because the data returned data quickly, now victor is unacceptable to the next bit machine data, there is slowly in front of instruction, send and receive is normal, but the data behind the fast, don't get all the time, I originally received in a thread, but can't, later I change within a timer, every 5 ms read from the buffer time, but I still can't, a machine under 10 bytes per frame data is the data,

CodePudding user response:

CodePudding user response:

A place to have the wrong number above, is eight bytes per frame data

CodePudding user response:

Thank you for help

CodePudding user response:

1. Receiving data suggest that in controls 1 OnPackage events,
2. The other side of the data even send a frame at a time, eight bytes, but when received, also may appear to receive incomplete a frame, so you are in processing, for the rest of the insufficiency of a frame of data processing,

CodePudding user response:

reference 4 floor titan_ysl response:
1. Receiving data suggest that in the control of 1 OnPackage event in writing,
2. The other side of the data even send a frame at a time, eight bytes, but when received, also may appear to receive incomplete a frame, so you are in processing, for the rest of the insufficiency of a frame of data processing,
OnPackage events have time interval, the soon I send data, is can't get into OnPackage basic

CodePudding user response:

I now use TComm controls, can you tell me the eight bytes of hexadecimal data reception should be how to write?

CodePudding user response:

According to the string is read in directly, then parsing

CodePudding user response:

refer to 7th floor hongss response:
directly according to the string to read in, then parse

So, please write what's wrong?
Void __fastcall TForm3: : Timer1Timer (TObject * Sender)
{
Unsigned char buf [8]={0};
AnsiString STR.
Int count=MSComm1 - & gt; InBufferCount;//the number of bytes;
OleVariant rec=MSComm1 - & gt; The Input;//remove the receive buffer content;
Char m=rec GetElement (count - 1);//test found that this isn't a
for(int j=0; j{

For (int m=0; M<8; M++)
{
If (8 * j + m>=count)
break;
Buf [m]=rec. GetElement (j * 8 + m);//convert byte type
}
}
}
Tests that found a mistake, I add a static variable in loop, also found that cycle times less than the number of bytes of the count

CodePudding user response:

Used to be so, for your reference

 
Int buff [200].//declare a store receives the data buffer, a global variable

Int ByteNum;//receive the number of bytes
Int BuffPtr;//the receive buffer pointer, please declare for global variables,
OleVariant RxBuff;//a for receiving OleVariant variables,

If (MSComm1 - & gt; InBuffCount> 0) RxBuff=Communica1 - & gt; The Input;//if there are more than one byte of data buffer
ByteNum=RxBuff. ArrayHighBound (1);//remove the actual number of bytes read
for(int i=0; I<=ByteNum; I++)
{
Buff [BuffPtr++]=RxBuff. GetElement (I);//will receive the data read in their own buffer,
}

CodePudding user response:

This data by using the method of control automatic parsing packets do not apply, the need to according to the analytical data, communication protocol in which controls are the same
  • Related