c# - How to check and ignore message from serial port? -


i want ignore messages came serial port except unique. add each message hashset , when new message arrive check messages not contains in hashset, if message not contains want print him, right program think each messages arrived unique , don't understand why comparing code not working, maybe can me. here code:

using system; using system.collections.generic; using system.linq; using system.text; using system.io.ports;  namespace mysniffer {     class program     {         static void main(string[] args)         {             hashset<string> messages = new hashset<string>();             serialport comport = new serialport();             comport.baudrate = 115200;             comport.portname = "com4";             comport.open();             while (true)             {                 string rx = comport.readline(); //reading com port                 messages.add(rx); // add new incoming message hashset                 if (!messages.contains(rx))                 {                      console.writeline(rx); // write incoming message                 }                 else {                      console.writeline(messages.count); // check how many messages in hashset                 }             }         }     } } 

the problem in logic of code, messages.add(rx); should moved in if block.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -