Click here to Skip to main content
15,847,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

In my window application I will be using barcode scanner through(Serial port /Com port).I have more than 20 windows forms. Customer may scan barcode in any active form. I will be using SerialDataReceivedEventHandler class to get data. I have to write same stuff code of SerialDataReceivedEventHandler in each form. So,Should i use this class in every form or how can i achieve writing all serial port code stuff in mainform and access data in every form?

If you have any suggestions please let me know.
Posted

I would be treating the Serial routines ie a wrapper class around the low level serial handling as 'singleton' code - they should appear once - possibly in the mainform - Im a bit worried about why you'd need to access it from so many forms - 20 ?

There are plenty of links/code around on how to share information between forms, but, I'd say your biggest issue was preventing two forms from trying to access the serial port at once - whats going to happen in form1 and form 2 both try to send for example ?
 
Share this answer
 
Comments
RAHUL(10217975) 20-Feb-14 2:34am    
Customer may scan barcode in any active form. How can i get that data? If I use wrapper class in main form. In my app its not mandatory to scan barcode only when main form is active they can scan in any active form.
First of all, I would suggest to use a separate thread for communication. It would make the logic way simpler than with this event.

But the main issue looks quite obvious: not only you should not do anything you mention in each form, but you should do something opposite: thoroughly isolate communication (as well as all other aspects of the code) from each and every form, from UI in general.

—SA
 
Share this answer
 

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