Click here to Skip to main content
15,076,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone. I'm trying to write my own application which will control external hardware device.

So, the idea is to send a status command every 1 sec. (using timer). But except status commands I need to send another commands at any time. The worst case is when both commands will join eg. STATUS + MY COMMAND or MY COMMAND + STATUS. External hardware recognize only first part of this creture.
How to divide commands ?

Just use the System.Collections.Queue[^]. Or, use this as a reference for a queue that is thread-safe (not sure if you're doing this with threads).

Rather than just building a string of data to send, create a queue of commands. When the timer fires, loop through the queue and send one command at a time until all commands are sent.

Using this approach also allows you to ensure that if a command exists already in the queue - and shouldn't be sent again - you can omit adding it to the queue.

Thanks for answer, I'm using arraylist for create an object with commands and there in timer for transmmit I'm changing it to byte array and send an array through SerialPort. How to do this queue ?
Thank you very much :)


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