I have 8 input (sensor) I will read all of value 1 or 0 and I will calculate them spesific way for example
SUM=D1X1+D2X2+D3X4+D4X8+D5X16+D6X32+D7X64+D8X128
So you are assigning a binary weight to each sensor?
Do something like:
SavedValue = SavedValue & ~(1 << SensorNumber); // clear bit
SavedValue = SavedValue | (SensorValue << SensorNumber); //sets bit for sensor# if SensorValue = 1
The first line clears the bit for sensor ‘SensorNumber’ in the integer ‘SavedValue’. It does this by shifting a 1 into that bits position and takign the complement of that value. In other words you wind up with a 1 in every bit positon except the sensors bit position. When you logically AND SavedValue with this bitmask it clears the bit for this sensor.
The second line sets the sensors bit position it the sensor reading is 1, if the sensor reading is 0 then nothign is changed.
That is a really good idea Mike. I think though that you would have to poll the parallel port state as it is deigned for bidirectional communications. One could use a timer to poll the parallel port state every 10ms or so and raise an event when it changed. I’m doing something similar right now with an I/O-40. I am polling all five input ports and checking for a change in value. In my case since I am interested in what input changed I have to compare the new port readings with the old and raise an event for each sensor (bit) that changed states.