c# - Using SerialPort to discard RF Device Buffer -


i'm writting small application automatically connects correct serial port sending list of commands, , waiting response serial device (rf transmitter). serial port objects sends commands in decimal format, reset, login , query command.

when query command sent, device replies response - when response received know have correct serial port connection.

all of works fine, receive error device - error 130: tx queue overflow. error can resolved restarted device (rf transmitter), frequency of error silly.

am correct in thinking tx overflow error caused when buffer on hardware becomes full? thought simple discardinbuffer after opening connection device fix - doesn't.

when should use discardinbuffer, using in correct context?

-- edit

after more comments , thoughts, i've come conclusion serialport.discardinbuffer won't current situation, rather need discard buffer on actual rf device - hence why inplugging works.

you've sent data device, , output queue has overflowed, meaning not able forward data fast you're providing it.

there's no method can call on serialport class fix this, these 2 different buffers we're talking about. calling serialport.discardoutbuffer discard output data pending your serial port, not device.

to temporarily fix issue, manual indicates can:

use command “reset txqueue” clear queue.

the better solution, however, prevent issue , not flood device data. exact way depend on hardware.

one way might introduce sort of commandqueue class has associated serialport object push commands hardware. in class, queue commands sent, , send them out configurable maximum rate. use timer, , send commands out if 1 hasn't been sent in last x msec.

another way implement sort of software flow control. appears device supports querying queue length "?state" command (page 13). respond with:

 state x1/x2 x3 x4   x1: number of datapackets in tx queue  x2: size of tx queue  x3: status byte (8 bit hexadecimal)  normal state: status byte = 0  bit 0 = 1: error in transceiver  bit 1 = 1: error in eeprom  x4: current value of dataset counter (number of last received , saved datapacket)  

you query before attempting send data packet, , sleep while queue full.


having written lot of code interface finicky hardware (serial, ethernet, etc.) in c#, can offer following advice:

  • implement abstract class tn9000devicebase has abstract methods of commands supported device.
  • derive class tn9000serialdevice : tn9000devicebase executes command using serial port.

this allow come , implement via ethernet when requirements change.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -