A week ago, I posted some news about DPA Terminal. I promised, that I will add control capability for all main constructions from this site. A few days ago, I added Relay Board control capability. I had to change source code of Relay Board, but I think, the result is worth to it. Let’s see inside.
Relay Board source code changes
Original source code looks like this:
if ( _PNUM == PNUM_USER + 0 ) // ? { // Check command if ( _PCMD != 0 ) DpaApiReturnPeripheralError( ERROR_PCMD ); // Check data length if ( _DpaDataLength != 1 ) DpaApiReturnPeripheralError( ERROR_DATA_LEN ); SR74HC595_SendByte(_DpaMessage.Response.PData[0]); goto DpaHandleReturnTRUE; } |
The source code allowed only relay state control, not reading. This new source allows reading relay state.
// Handle peripheral command switch (_PNUM) { case (PNUM_USER + 0): switch (_PCMD) { case 0: // Check data length if ( _DpaDataLength != 1 ) DpaApiReturnPeripheralError( ERROR_DATA_LEN ); relaystate = _DpaMessage.Response.PData[0]; SR74HC595_SendByte(relaystate); goto DpaHandleReturnTRUE; break; case 1: // Check data length if ( _DpaDataLength != 0 ) DpaApiReturnPeripheralError( ERROR_DATA_LEN ); _DpaMessage.Response.PData[0] = relaystate; _DpaDataLength = 1; goto DpaHandleReturnTRUE; break; default: DpaApiReturnPeripheralError( ERROR_PCMD ); break; } break; default: DpaApiReturnPeripheralError(ERROR_PNUM); break; } |
If you want set some relay state, just use DPA packet with PNUM=0x20, PCMD=0x00, and DATA with relay state. If you want read relay state, just use DPA packet with PNUM=0x20, PCMD=0x01, and without data. You will get a relay state in response packet.
DPA Terminal support
DPA Terminal has a new functional tab: “Relay Board”. This tab contains address field, eight checkboxes for relay state set and visualisation, and two buttons for relay state set and read operation.
I found some bugs inside DPA .NET class, when I worked on this tab, so I corrected them. Full sources for both, DPA Terminal and Relay Board are attached.
Enjoy.