3
votes

I have a sensor which uses RS422 to spit out messages over serial. (I think thats the right terminology.) Anyways, I made my wiring harness, and hooked it up to my rs422 to usb convertor and tada, I got data in hyperterminal. Good stuff.

Now the sensor has an odd baud rate, 1500kbps. I am doing this in Windows, so it actually wasn't that hard to set that baud rate. Initially, at power on, the sensor sends out a 69 byte message every 10hz. I see this message, the correct bytes are read, and the message is very accurate (it includes a timestamp, which wait for it, increases by 0.1 s every message!) MOST IMPORTANTLY, I get the message on its boundary, in other words, every read was a new message.

Anyways things are going good so far, so I took the next step, I sent a write command over the serial port, to activate a sensor data message. This message is 76 bytes large, and is sent out at 100hz. Success again, more data begins appearing in reads. However, I am not getting it at 100hz, I get blocks of 3968 bytes. If I lower my buffer, I get three very very very quick reads of 1024, then immediately a read of 896. (3968 bytes again). (Note that I am now receiving two messages, one at 10 hz with size 69, and one at 100hz with size 76, note that no combination of the two messages evenly divides 3968.)

My question is, somewhere something is buffering my 100hz messages, and I am not getting them as they're being received. I would like to change that but I do not know what I'm looking for. I don't need that 100hz message on its boundary, I just don't want it at 2 Hz. I would be happy with 30hz or even 20hz.


Below I include my Serial Port Set up code:

Port Open

 serial_port_ = CreateFile(L"COM6", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

CommState and Timeouts

 COMMTIMEOUTS comm_timeouts;
 ZeroMemory(&comm_timeouts, sizeof(COMMTIMEOUTS));
 //comm_timeouts.ReadIntervalTimeout = MAXDWORD; //Instant Read, still get 3968 chunks
 comm_timeouts.ReadIntervalTimeout = 1; //1ms timeout
 comm_timeouts.ReadTotalTimeoutConstant = 1000; //Derp?
 comm_timeouts.WriteTotalTimeoutConstant = 5000; //Derp.
 SetCommTimeouts(serial_port_, &comm_timeouts);

 DCB dcb_configuration;
 ZeroMemory(&dcb_configuration, sizeof(DCB));
 dcb_configuration.DCBlength = sizeof(dcb_configuration);
 dcb_configuration.BaudRate = 1500000;
 dcb_configuration.ByteSize = 8;
 dcb_configuration.StopBits = ONESTOPBIT;
 dcb_configuration.Parity = ODDPARITY;
 if(!SetCommState(serial_port_, &dcb_configuration))

My Read

 if(!ReadFile(serial_port_, read_buffer_, 1024, &bytes_read, NULL))
1

1 Answers

3
votes

I would suspect your serial->usb convertor to do the buffering. Since the usb is packet based, it needs to do some buffering. In rate 10Hz, there are probably big enough delays, to flush buffer after every message. But at 100Hz the messages are coming so far, that it is flushing buffer by some other logic.

Does that make sense?