I have an 8 bit digital output board used to control a device. Each external device requires one bit and is controlled by another application. I wrote a class library and a class DigitalOutputPort (VB 2010), which converts the driver that controls the 8-bit port. Each device application uses this class, creating its own instance.
To set the digital output port bit, I have to write a byte to this port: this byte is a bit mask for all 8 bits together: to set HIGH bit 0 - 1 - 2, I need to write 7 to the port, set HIGH all 8 bits, I need to write 256 and so on ...
Everything works fine when only one application uses the class. But if two applications want to set their own bit on this port, I have problems because I do not know the current value of all the bits set by other applications (the driver does not have such a function), and, of course, I cannot change one bit without changing all the others (if I do not know the current bitmask)
This usually looks like a typical case of data sharing between two applications, and my first idea was to write the current port value in a file on disk, where the entire application can access and read it. But for this simple problem, it is too hard. In addition, it can also create a problem of reliability and reliability.
Then I, however, talk about using a common class (property) in a class. A common field retains its value between all instances of the class: but is this also true between instances from different applications? I can not find more information about this last point, I have to do the same test.
The third way is to create only one instance of the DigitalOutputPort class, one for all applications. The first application that needs it will create an object, all other applications will use the already created object. I like it more than others, but I donβt know whether and how to do it.
What should be the right approach in your opinion?
Thanks for answering.